Applying coupon on subscription renewal throws 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 #47330
Labels
focus: coupon
Issues related to coupons.
priority: high
The issue/PR is high priority—it affects lots of customers substantially, but not critically.
team: Rubik
Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues
type: community contribution
type: refactor
The issue/PR is related to refactoring.
Prerequisites
Describe the bug
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.
It looks like
WC()->cart
is null in this scenario in https://github.com/woocommerce/woocommerce/blob/release/8.8.0.20/plugins/woocommerce/includes/class-wc-discounts.php#L979My custom function is called using this filter
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 as cart is not available it this specific scenarion.
Thanks
Michal
Expected behavior
Email restricted coupons should be applied on subscription renewals
Actual behavior
Fatal error is thrown
Steps to reproduce
Apply an email restricted coupon code on subscription renewals
WordPress Environment
`
WordPress Environment
WordPress address (URL): http://prodog.local
Site address (URL): http://prodog.local
WC Version: 8.8.3
REST API Version: ✔ 8.8.3
Action Scheduler Version: ✔ 3.7.4
Log Directory Writable: ✔
WP Version: ❌ 6.4.1 - There is a newer version of WordPress available (6.5.3)
WP Multisite: –
WP Memory Limit: 1 GB
WP Debug Mode: –
WP Cron: –
Language: en_GB
External object cache: –
Server Environment
Server Info: Apache/2.4.43 (Unix)
PHP Version: 8.2.10
PHP Post Max Size: 1,000 MB
PHP Time Limit: 1200
PHP Max Input Vars: 4000
cURL Version: 8.4.0
(SecureTransport) LibreSSL/3.3.6
SUHOSIN Installed: –
MySQL Version: 5.7.28
Max Upload Size: 300 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ❌ wp_remote_post() failed. Contact your hosting provider.
Remote Get: ❌ wp_remote_get() failed. Contact your hosting provider.
Database
WC Database Version: 7.8.2
WC Database Prefix: wp_
Total Database Size: 10896.83MB
Database Data Size: 5296.99MB
Database Index Size: 5599.84MB
Status report information
Generated at: 2024-05-09 16:01:47 +01:00
`
Isolating the problem
The text was updated successfully, but these errors were encountered: