Open rouxsean opened 2 years ago
@rouxsean could you give us some more details about your setup to help us debug this? A WooCommerce status report is helpful.
WooCommerce > Status
.Get system report
button.Copy for support
(or select => copy the text manually).In particular, please confirm you can reproduce this bug with minimum extensions active, e.g. WooCommerce
, WooCommerce Subscriptions
and a default theme (e.g. Storefront or Twenty Twenty Two). Thank you!
OK. I spun up a shiny new wordpress instance for you. Installed only woo & woo subscriptions along with Hello theme. (litespeed cache deactivated.
Here's the system report: [edited for brevity, system report is in description now]
Thank you for the system report @rouxsean !
I have one more question – how do you trigger the fatal error? If you can reproduce this reliably by using the WooCommerce UI please add steps to the description. Include config details that might be relevant (e.g. tax settings, subscription product config, subscription / order details).
From the call stack, it looks like it's something to do with viewing order items metabox. What are you doing in the admin UI when the bug occurs?
Thanks again 😄
@Jinksi can you try reproducing this? If it's a fatal error that's easily reproducible we should prioritise a fix.
Here's the code I'm using.
On this new spin-up test site, it's in the functions.php file
function delete_items_on_subscription_hold($subscription, $new_status, $old_status) { $items = $subscription->get_items(); if ( count( $items ) > 0 && $new_status == 'on-hold') { foreach ( $items as $item_id => $item ) { $subscription->remove_item($item_id); $subscription->add_order_note('Old item removed'); $subscription->calculate_totals(); $subscription->add_order_note('Totals calculated after removal');
}}} add_action('woocommerce_subscription_status_updated', 'delete_items_on_subscription_hold', 5, 3);
Thanks for the info @rouxsean , good to confirm this is a customisation issue (and not affecting sites without custom code).
Sorry. I should have included the entire code.
It's this line that's causing the issue:
$subscription->remove_item($item_id);
The order notes are added, so my code runs all the way through, but a PHP Fatal error is thrown when woo subscriptions tries to see if _subtracted_base_location_tax exists through the meta_exists() function. (line 587 of class-wcs-admin-meta-boxes.php)
Since I'm on the admin screen when I change the status from Active to on-hold, I get the wordpress white screen of death.
Also, this error happens when I change the subscription from active to on-hold from the admin screen. This is how I've been testing this.
An alternative way to test this is to process a pending renewal order. This will put the subscription on-hold until the renewal order is marked as paid. When I test this way, there is no PHP Error.
As a result, this is probably a much lower priority that I thought (generated as a result of testing method).
Not sure if there's a way to reduce priority, but I'm going to continue to develop using the pending renewal as the way to change subscription status.
Thanks!
Thanks @rouxsean – I've tagged low priority 👍
Great you've found a workaround!
Describe the bug
Customisation calling
$subscription->remove_item($item_id);
may trigger a fatal error.PHP Fatal error: Uncaught Error: Call to a member function meta_exists() on bool in /wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/admin/class-wcs-admin-meta-boxes.php:587
How to reproduce
Sample customisation from
functions.php
, hookingwoocommerce_subscription_status_updated
:With the customisation above, change a subscription from
Active
toOn hold
in admin. This triggers the fatal error.More details
Stack trace:
class-wcs-admin-meta-boxes.php on line 587:
To Reproduce
programatically delete an item from a subscription object
syntax: $subscription->remove_item($item_id);
Product impact
WooCommerce Subscriptions
WooCommerce status report: