Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save xlplugins/de7149969cfabafd0686faa3ff130174 to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/de7149969cfabafd0686faa3ff130174 to your computer and use it in GitHub Desktop.
Disable woocommerce native email when sublium process running
class Sublium_Disable_Renewal_Emails {
public static function init() {
$email_ids = array(
'new_order',
'customer_processing_order',
'customer_completed_order',
'customer_on_hold_order',
'failed_order',
'cancelled_order',
// Renewal emails (if WooCommerce Subscriptions is present).
'new_renewal_order',
'customer_processing_renewal_order',
'customer_completed_renewal_order',
'customer_on_hold_renewal_order',
);
foreach ( $email_ids as $email_id ) {
add_filter(
"woocommerce_email_enabled_{$email_id}",
array( __CLASS__, 'disable_email' ),
999,
2
);
}
}
/**
* Disable emails for Sublium renewal orders.
*
* @param bool $enabled Whether email is enabled.
* @param WC_Order|null $order Order object.
*
* @return bool
*/
public static function disable_email( $enabled, $order = null ) {
if ( ! $order instanceof WC_Order ) {
return $enabled;
}
if ( 'yes' === $order->get_meta( '_sublium_wcs_subscription_renewal', true ) ) {
return false;
}
return $enabled;
}
}
Sublium_Disable_Renewal_Emails::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment