Last active
June 26, 2024 15:12
-
-
Save thenbrent/eec1d7a21e30066f6779 to your computer and use it in GitHub Desktop.
Do not send renewal order emails when the email relates to a $0 renewal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WooCommerce Subscriptions No $0 Emails | |
Plugin URI: | |
Description: Do not send processing or completed renewal order emails to customers when the order or renewal is for $0.00. | |
Author: | |
Author URI: | |
Version: 0.1 | |
*/ | |
function eg_maybe_remove_email( $order_id ){ | |
$order = new WC_Order( $order_id ); | |
if ( 0 == $order->get_total() ) { | |
switch( current_filter() ) { | |
case 'woocommerce_order_status_completed_renewal_notification': | |
$email_class = 'WCS_Email_Completed_Renewal_Order'; | |
break; | |
case 'woocommerce_order_status_pending_to_processing_renewal_notification': | |
$email_class = 'WCS_Email_Processing_Renewal_Order'; | |
break; | |
case 'woocommerce_order_status_failed_renewal_notification': | |
$email_class = 'WCS_Email_Customer_Renewal_Invoice'; | |
break; | |
default: | |
$email_class = ''; | |
break; | |
} | |
if ( ! empty( $email_class ) ) { | |
remove_action( current_filter(), array( WC()->mailer()->emails[ $email_class ], 'trigger' ) ); | |
} | |
} | |
} | |
add_action( 'woocommerce_order_status_completed_renewal_notification', 'eg_maybe_remove_email', 0, 1 ); | |
add_action( 'woocommerce_order_status_pending_to_processing_renewal_notification', 'eg_maybe_remove_email', 0, 1 ); | |
add_action( 'woocommerce_order_status_failed_renewal_notification', 'eg_maybe_remove_email', 0, 1 ); | |
// Enable these to not send initial order for $0 | |
//add_action( 'woocommerce_order_status_completed_notification', 'eg_maybe_remove_email', 0, 1 ); | |
//add_action( 'woocommerce_order_status_pending_to_processing_notification', 'eg_maybe_remove_email', 0, 1 ); | |
//add_action( 'woocommerce_order_status_failed_notification', 'eg_maybe_remove_email', 0, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script works for customer but not for admin emails
Can anyone help adding some lines to prevent sending emails to admin too