1

I'm trying to disable a number of WC Subscriptions emails (so they don't get sent). I know that I can do this in the admin settings area manually however I'm trying to do this via PHP (in a plugin). The reason for this is so that when it's moved from the test site to the live site the relevant files can be simply copied across and it's good to go without any manual settings changes.

As an example - removing the new renewal order that gets sent to the site admin.

add_action( 'woocommerce_email', 'SA_unhook_unneeded_emails' );
function SA_unhook_unneeded_emails( $email_class ) {
    //remove new_renewal_order email (sent to admin)
    remove_action( 'woocommerce_order_status_pending_to_processing_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_completed_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_pending_to_on-hold_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_processing_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_completed_renewal_notification', array( $this, 'trigger' ) );
    remove_action( 'woocommerce_order_status_failed_to_on-hold_renewal_notification', array( $this, 'trigger' ) );
    //remove_action( 'woocommerce_order_status_completed_renewal_notification', array( $this, 'trigger' ) );

}

Uncommenting the last remove_action makes no difference. The emails are still sent. I've tried changing woocommerce_email to wp_head to see if made any difference but none whatsoever.

There seems to be little documentation (at least that I can find) on the WC subscriptions hooks so I'm struggling to work out what exactly I need to do to get this working.

Any help would be appreciated.

Josh
  • 79
  • 6

1 Answers1

4

Never mind found it - all I needed was a good nights sleep! For those who stumble across this later on the details are below.

You need to use the 'woocommerce_email_enabled_'.this->id filters. The id (this->id) can be found in the relevant class files for that email type. e.g.

  • New order (sent to admin) is in class-wc-email-new-order.php (woocommerce/includes folder) contains $this->id = 'new_order';
  • New renewal order (sent to admin) is new_renewal_order
  • Renewal order (send to customer) is either customer_processing_renewal_order or customer_completed_renewal_order
//stop emails without using the admin dashboard to manually set enabled/disabled status
add_filter( 'woocommerce_email_enabled_new_order', 'SA_stopemails', 10, 2); //new order sent to admin
add_filter( 'woocommerce_email_enabled_customer_on_hold_order', 'SA_stopemails', 10, 2); //order on hold sent to customer
add_filter( 'woocommerce_email_enabled_customer_processing_order', 'SA_stopemails', 10, 2); //order in processing sent to customer
add_filter( 'woocommerce_email_enabled_new_renewal_order', 'SA_stopemails', 10, 2); //new renewal order sent to admin
add_filter( 'woocommerce_email_enabled_customer_processing_renewal_order', 'SA_stopemails', 10, 2); //renewal order processing sent to customer
add_filter( 'woocommerce_email_enabled_customer_completed_renewal_order', 'SA_stopemails', 10, 2); //renewal order completed sent to customer

function SA_stopemails( $active, $order ) {
    return false;
}
Josh
  • 79
  • 6