Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
88 stars 33 forks source link

CRITICAL Allowed memory size exhausted when customer cancels their subscription #564

Open rlmajcom opened 7 months ago

rlmajcom commented 7 months ago

Describe the bug

When custom cancels their subscription, fatal error occurs and this appears in the error.log like this example: CRITICAL Allowed memory size of 268435456 bytes exhausted (tried to allocate 528384 bytes) in /www/websitename/public/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php on line 447

To Reproduce

Error seems to always point to line 447 or sometimes 449 of class-wc-email.php

  1. Customer cancels subscription
  2. They do not receive the cancellation confirmation email due to the fatal error

Expected behavior

Actual behavior

These are the lines of code triggering it. I have 256MB of memory allocated, so this should not be happening: /**

Product impact

WooCommerce Subscriptions

Additional context

FINDINGS:

NO LONGER WORKS FOR APPENDING CUSTOMER TO CANCELLATION EMAIL...CAUSES MEMORY ERROR AND 500 BY RESULTING IN AN INFINITE LOOP APPENDING THE CUSTOMER EMAIL TO THE RECIPIENTS INFINITE TIMES:

add_filter( 'woocommerce_subscription_status_pending-cancel', function ( $subscription ) { $customer_email = $subscription->get_billing_email(); $wc_emails = WC()->mailer()->get_emails(); $wc_emails['WCS_Email_Cancelled_Subscription']->recipient .= ',' . $customer_email; $wc_emails['WCS_Email_Cancelled_Subscription']->trigger( $subscription ); return $subscription; }, 100);

THIS APPEARS TO WORK AS OF JAN 2024:

add_filter('woocommerce_email_recipient_cancelled_subscription', 'set_customer_as_cancelled_subscription_recipient', 10, 2); function set_customer_as_cancelled_subscription_recipient($recipient, $subscription) { //this line makes the customer the only recipient // return $subscription ? $subscription->get_billing_email() : $recipient; //this appends the customer as a recipient in addition to the recipient specified in WooCommerce Email settings if ($subscription && false === strpos($recipient, $subscription->get_billing_email())) { // Append the customer's billing email to the existing recipient list, separated by a comma $recipient .= ',' . $subscription->get_billing_email(); } return $recipient; }

``` ```

-->

bignevola commented 6 months ago

Any update on this?