Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Now zero dollar subscriptions won't trigger renawal emails anymore #796

Merged
merged 6 commits into from
Mar 28, 2025

Conversation

leonardola
Copy link
Contributor

Fixes https://github.com/woocommerce/woocommerce-subscriptions/issues/4778

Description

This PR adds a check to prevent sending renewal reminders for 0 dollar orders

How to test this PR

  • Checkout to this PR's branch
  • Place a subscription order
  • Go to /wp-admin > WooCommerce > Subscriptions > Edit
  • Make sure the Send upcoming renewal notification option does not show up in the order actions select box
  • Change the next renewal to happen in just a few minutes from now
  • Wait until the renewal happens
  • Make sure you don't receive a Manual renewal notice email but you do receive a Thank you for your order email

Product impact

  • Added changelog entry (or does not apply)
  • Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
  • Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
  • Added deprecated functions, hooks or classes to the spreadsheet

@leonardola leonardola force-pushed the fix/4778-prevent-renewal-email-zero-dollar branch from 4264748 to 977b87c Compare March 26, 2025 17:20
@leonardola leonardola requested review from a team and james-allan and removed request for a team March 26, 2025 17:20
Copy link
Contributor

@james-allan james-allan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

  • I confirmed that the action is removed for free subscriptions.
trunk This branch
Screenshot 2025-03-27 at 1 29 15 pm Screenshot 2025-03-27 at 1 30 07 pm
  • I confirmed that subscriptions with a recurring total still include the action and it still works (ie sends the email).
  • Confirmed that subscriptions with a recurring total still sends the email via AS. *
  • Confirmed that free subscriptions don't send the email via AS. *

* To test the emails are and aren't sent in a normal scenario I used this code snippet to simulate a renewal that is due in 3 days + 10 seconds. ie the email should send in 10 seconds.

wcs_get_subscription( 466 )->update_dates( [
	'next_payment' => gmdate( 'Y-m-d H:i:s', time() + ( 3 * DAY_IN_SECONDS ) + 10 ),
] );

I left a small comment about the changelog entry.

@leonardola leonardola merged commit 324a586 into trunk Mar 28, 2025
9 checks passed
@leonardola leonardola deleted the fix/4778-prevent-renewal-email-zero-dollar branch March 28, 2025 19:11
@@ -156,6 +156,9 @@ public static function send_notification( $subscription_id ) {
switch ( current_action() ) {
case 'woocommerce_scheduled_subscription_customer_notification_renewal':
$subscription = wcs_get_subscription( $subscription_id );
if ( $subscription->get_total() <= 0 ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why <= 0? Is there ever a case where we have a negative subscription? And if so, is that a refund? And if so, should we break?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why <= 0? Is there ever a case where we have a negative subscription?

The only way for the subscription totals to be negative in that flow is if the merchant sets a bigger discount than the product price in the admin area and then select Send upcoming renewal notification and click update order.

Screenshot 2025-05-01 at 15 49 54

And if so, is that a refund?

Subscriptions can't really be refunded what gets refunded are orders and orders don't have the Send upcoming renewal notification option so that flow would never run when refunding.

I've also tested coupons and they only discount up to 100% of the cart/order total.
Even products with negative price end up creating a subscriptions with a $0 total though the order has a negative total

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants