Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task
rlmajcom opened this issue Feb 4, 2024 · 1 comment
Open
1 task
Labels
type: bug The issue is a confirmed bug.

Comments

@rlmajcom
Copy link

rlmajcom commented Feb 4, 2024

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:
/**
* Get valid recipients.
*
* @return string
*/
public function get_recipient() {
$recipient = apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object, $this );
THIS LINE---> $recipients = array_map( 'trim', explode( ',', $recipient ) );
$recipients = array_filter( $recipients, 'is_email' );
return implode( ', ', $recipients );
}

Product impact

WooCommerce Subscriptions

  • [YES] Does this issue affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
  • Does this issue affect WooCommerce Payments? yes/no/tbc, add issue ref

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;
}

``` ```
-->
@rlmajcom rlmajcom added the type: bug The issue is a confirmed bug. label Feb 4, 2024
@bignevola
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants