Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdeborba/72e0de0db7312d848432eeb396504539 to your computer and use it in GitHub Desktop.
Save alexdeborba/72e0de0db7312d848432eeb396504539 to your computer and use it in GitHub Desktop.
Function to Disable Free Orders Completed Email
/**
* This function checks if an order has a total of zero (free), and if so, stops the "Completed order" email from being sent.
*
* @param bool $is_enabled - Original state of the email (enabled/disabled)
* @param WC_Order $order - The order object for which the email is being sent
* @return bool - Modified state of the email (enabled/disabled)
*/
function disable_free_order_completed_email( $is_enabled, $order ) {
// Check if the order total is zero
if ( 0 == $order->get_total() ) {
// If the order total is zero, disable the email
$is_enabled = false;
}
// Return the possibly-modified email state
return $is_enabled;
}
// The 'woocommerce_email_enabled_customer_completed_order' filter allows enabling/disabling the "Completed order" email
// We hook into it with our function above, passing the original email state and the order object
add_filter( 'woocommerce_email_enabled_customer_completed_order', 'disable_free_order_completed_email', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment