Applying coupon on subscription renewal fails due to validate_coupon_allowed_ema
-
We are applying custom coupon codes on subscription renewals and due to the is_coupon_emails_allowed function introduced a couple of weeks ago we’ve started to get errors with subscription renewals.
2024-05-01T11:01:13+00:00 Notice scheduled action XYZ (subscription payment) failed to finish processing due to the following exception: Call to a member function is_coupon_emails_allowed() on null Additional context { "_legacy": true } 2024-05-01T11:01:13+00:00 Notice action args: subscription_id: XYZ
It looks like WC()->cart is null in this scenario
[29-Apr-2024 09:51:25 UTC] PHP Fatal error: Uncaught Error: Call to a member function is_coupon_emails_allowed() on null in /wp-content/plugins/woocommerce/includes/class-wc-discounts.php:979 Stack trace: #0 /wp-content/plugins/woocommerce/includes/class-wc-discounts.php(1046): WC_Discounts->validate_coupon_allowed_emails(Object(WC_Coupon)) #1 /wp-content/plugins/woocommerce/includes/class-wc-discounts.php(252): WC_Discounts->is_coupon_valid(Object(WC_Coupon)) #2 /wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-order.php(1252): WC_Discounts->apply_coupon(Object(WC_Coupon)) #3 /wp-content/themes/my_theme/custom/discount-on-renewal.php(132): WC_Abstract_Order->apply_coupon('renewal_couponXYZ')
My custom function is called using this filter
add_filter( 'wcs_renewal_order_created', 'apply_discount_on_renewal_order_created', 10, 2 );
I’ve already fixed the issue in my theme and wrapped the code in try/catch block but I’m wondering if this shouldn’t be fixed in WooCommerce code as well.
If latter please let me know, and I can create an issue on GitHub.
Thanks
Michal
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Applying coupon on subscription renewal fails due to validate_coupon_allowed_ema’ is closed to new replies.