Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Do not send renewal order emails when the email relates to a $0 renewal.
<?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
You can’t perform that action at this time.