Created
June 8, 2023 11:42
-
-
Save alexdeborba/72e0de0db7312d848432eeb396504539 to your computer and use it in GitHub Desktop.
Function to Disable Free Orders Completed Email
This file contains hidden or 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
/** | |
* 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