WooCommerce Subscriptions and Yith My Account Issues - wordpress

Fatal error: Uncaught Error: Call to a member function get_status() on null
I have WooCommerce and WooCommerce Subscriptions installed as well as YITH WooCommerce Customize My Account Page. And when I click on View Subscription, I get an error about the website having issues. When I show console in Chrome, and/or enable Debug, I get the following error message. Any help is greatly appreciated!
Fatal error: Uncaught Error: Call to a member function get_status() on null in /www/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/subscription-details.php:18 Stack trace: #0 /www/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include() #1 /www/wp-content/plugins/woocommerce-subscriptions/includes/class-wcs-template-loader.php(41): wc_get_template('myaccount/subsc...', Array, '', '/www/wp-content...') #2 /wordpress/wp-includes/class-wp-hook.php(286): WCS_Template_Loader::get_subscription_details_template(NULL) #3 /wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #4 /wordpress/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #5 /www/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/view-subscription.php(23): do_action('woocommerce_sub...', NULL) #6 /www/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include('/www/wp-content...') #7 /www/wp-content/plugins/yith-woocommerce-customize-myaccount-page/includes/functio in /www/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/subscription-details.php on line 18

Add this in your view-subscription.php file:
$subscription = wcs_get_subscription(basename($_SERVER['REQUEST_URI']));
You can find it in inside the folder woocommerce/myaccount of your theme. If you don't have it then you will have to create it by copying it from your woocommerce installation (check this link if you are not sure how it works).
That line should go just after the security check:
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

Related

WooCommerce: Wrong Order Status Updated [duplicate]

When I try to programmatically update an order during a WP_Ajax hook. IE.
$order = wc_create_order($order_data);
$order->add_product( get_product( $membership_product_ids[0] ), 1 );
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order_id = $order->id;
$order->update_status('completed');
I get the following errors:
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 302
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 302
If I remove that update_status function it does not errors.
The errors you are seeing are coming from the notification system. Your code appears able to update the status just fine. The Emogrify Class is used to generate inline CSS in an HTML template. You are likely seeing these errors because either A) you have overridden the "Completed order" email template and have created a parsing error or B) there is a WooCommerce add-on that is conflicting in some way with what you are doing.
To correct the issue, the first step will be to verify that it is the notification system by going into the admin under WooCommerce->Settings->Email->Completed order and un-checking the "Enable this email notification" box. Then save that and retest.
If your error goes away, then check your theme directory for an override of that template. It would be in <themename>/woocommerce/emails/customer-completed-order.php. If you have one, them rename it so it will not override anymore and reactivate the "Completed order" notification and see if using the default template corrects the issue.
If the issue persists with the default email notification template, then disable all of the WooCommerce add-ons you might have installed and retest. At this point, if it is working, you can re-enable them one-by-one until the issue returns. Once you have found the offending add-on, you will need to either adjust your code to allow for the add-on to not cause an issue or contact the add-on developer to address you issue.
I am not sure but you could try this trick using new WC_Order( $order_id );, to avoid the error:
// global $woocommerce; // in case of need…
$order = wc_create_order($order_data);
$order_id = $order->id; // moving this here
$_order = new WC_Order( $order_id ); // here
$_order->add_product( get_product( $membership_product_ids[0] ), 1 );
$_order->set_address( $address, 'billing' );
$_order->set_address( $address, 'shipping' );
$_order->update_status('completed');
I agree this is a strange issue.
As it is rare issue, you'd better manually open:
/wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php
and before line 299, insert these lines, and see what you will get:
var_dump($value);
var_dump($this->translateCssToXpath($value['selector']));
var_dump($xpath->query($this->translateCssToXpath($value['selector'])));
I figured this out by trying a range of different hooks, the issue was that the hook I was using to create the order happened before woocommerce initialized that what caused this issue.

Using Wordpress Force Login plugin to have security feature for only a certain page. An error keeps popping up and i cant seem to find it

I can't see anything wrong with the code, this is the error below and this is the link to where i got it https://www.greengeeks.com/tutorials/force-login-before-visitors-access-wordpress/
Error:
Your PHP code changes were rolled back due to an error on line 15 of file wp-content/themes/flatsome/functions.php. Please fix and try saving again.
syntax error, unexpected 'mstyle' (T_STRING), expecting ']'
Code:
[ht_message mstyle=”info” title=”” show_icon=”” id=”” class=”” style=”” ]
function my_forcelogin_redirect( $url ) {
return home_url( ‘/mypage/’ );
}
add_filter( ‘v_forcelogin_redirect’, ‘my_forcelogin_redirect’ );[/ht_message]

Wordpress BO post.php - button Publish/Update not working (error : GET 400 bad request, rest_invalid_param, orderby=menu_order)

I'm facing a weird issue on Wordpress…
I have to do some minor content updates on a Wordpress online since 2020, running perfectly.
But for only one of the CPT, when I want to add/modify a post, the publish/update (and save as draft) buttons not working. I can click on them but nothing happens…
In my console, I spot the following errors :
400 Bad Request GET https://mywebsite/wp-json/wp/v2/challenges?per_page=100&exclude=1921&parent_exclude=1921&orderby=menu_order&order=asc&_fields=id%2Ctitle%2Cparent&context=edit&_locale=user
Uncaught (in promise)
Object { code: "rest_invalid_param", message: "Paramètre(s) non valide(s) : orderby", data: {…} } in data.min.js:2:32702
I can update content without any problem with the quick edit…
Has anyone ever encountered this error?
I found a fix here :
Tim Ross webdevelopment
I had to add to functions.php the following code :
// This enables the orderby=menu_order for Posts
add_filter( 'rest_post_collection_params', 'filter_add_rest_orderby_params', 10, 1 );
// And this for a custom post type called 'portfolio'
add_filter( 'rest_challenges_collection_params', 'filter_add_rest_orderby_params', 10, 1 );
//Add menu_order to the list of permitted orderby values function filter_add_rest_orderby_params( $params ) {
$params['orderby']['enum'][] = 'menu_order';
return $params;
}
The filter hook is called rest_{post_type}_collection_params.
In my case, the post_type is "challenges".

Error 500 Call to undefined function thrive_get_theme_options() when trying to get to customize in WP

My site uninstalled all plugins so I reactivated and since then I have been greeted by Error 500 everytime I try to get to Customise (WP).
I checked out error_log and it's pointing to the funtions.php line 659 (starts 3rd line down):
function thrive_exclude_category($query)
{
$hide_cat_option = thrive_get_theme_options('hide_cats_from_blog');
if (!is_string($hide_cat_option)) {
$hide_cat_option = "";
}
$hide_categories = is_array(json_decode($hide_cat_option)) ? json_decode($hide_cat_option) : array();
$temp_query_string_part = "";
foreach ($hide_categories as $temp_cat_id) {
$temp_query_string_part .= "-" . $temp_cat_id . " ";
}
This is probably simple stuff, however, I suck. I have been lumbered with maintaining the sites and really have no say in the matter. Thanks in advance
In one of the projects I found this problem too. After study logs and debug project I find this function don't know about another function which used in theme PHP message: PHP Fatal error: Uncaught Error: Call to undefined function thrive_get_theme_options(). The main problem here in filter which running before all files will be included in theme. So function thrive_exclude_category don't find where declared thrive_get_theme_options because pre_get_posts running before we included files:
add_filter('pre_get_posts', 'thrive_exclude_category')
We need run this filter after use after_setup_theme
function run_func(){
add_filter('pre_get_posts', 'thrive_exclude_category', 999);
}
add_action('after_setup_theme', 'run_func`);
After this you not get any error and you can use your filter.
Try reactivate all plugins required by Thrive theme because of Fatal: Call to undefined function thrive_get_theme_options()

WooCommerce Subscriptions 2.0 - wcs_renewal_order_created action/filter throws error

I am trying to execute a function when WooCommerce subscriptions creates a new subscription renewal order.
The reason being I wish to trap this event and pass details to a different database so we can trigger business workflows with our payment gateway, within our backend systems.
I've tried add_action and add_filter using wcs_renewal_order_created and then tested this by manually creating a renewal payment from the parent subscription order.
The hook calls the function, executes the code, puts some data into some test tables and then Wordpress shows an error as shown below.
Is there a simpler way to trigger a function when a renewal subscription order is created and if not, can anyone help as to why it seems to be failing calling a class that seems to set the payment method.
function log_renewal_order_interface($order, $subscription) {
write_log('woocommerce_subscriptions_renewal_order_created function called');
global $conn;
global $wpdb, $table_prefix;
write_log('woocommerce_subscriptions_renewal_order_created setting up test variables');
write_log($order);
$test1 = 'logged renewal order';
$test2 = 'order_id'.$order_id;
$test3 = 'not set';
$test4 = 'not set';
$test5 = 'not set';
// test table entry
$conn->insert('test_tabel',
array('test1' => $test1, 'test2' => $test2, 'test3' => $test3, 'test4' => $test4, 'test5' => $test5),
array('%s', '%s', '%s', '%s', '%s'));
}
add_filter ('wcs_renewal_order_created', 'log_renewal_order_interface', 10,2);
I then get the following error:
Fatal error: Uncaught Error: Call to a member function
set_payment_method() on null in
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php:176
Stack trace: #0
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286):
WCS_Admin_Meta_Boxes::create_pending_renewal_action_request(Object(WC_Subscription)) #1 /home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(310):
WP_Hook->apply_filters('', Array) #2
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/plugin.php(453):
WP_Hook->do_action(Array) #3
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php(131):
do_action('woocommerce_ord...', Object(WC_Subscription)) #4
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-includes/class-wp-hook.php(286):
WC_Meta_Box_Order_Actions::save(812, Object(WP_Post)) #5
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp- in
/home/ourislan/lifestyle5d.ourislandsvoice.com/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wcs-admin-meta-boxes.php
on line 176
Figured it out. I needed to explicitly return $object at the end of the function.

Resources