Last active
November 1, 2021 21:57
-
-
Save alexmustin/530d7c384e1fec4e12c748aa4a27cbbe to your computer and use it in GitHub Desktop.
WooCommerce - disable 'Order Complete' emails for specific Product ID
This file contains 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
<?php | |
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'themename_disable_customer_order_email_for_product', 10, 2 ); | |
function themename_disable_customer_order_email_for_product( $recipient, $order ) { | |
// Get the current page. | |
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : ''; | |
// If we're on a WooCommerce settings page, return the regular recipient. | |
if ( 'wc-settings' === $page ) { | |
return $recipient; | |
} | |
// Get items in this order. | |
$items = (array) $order->get_items(); | |
// Loop through all items in this order. | |
foreach ( $items as $item ) { | |
// Get this product ID. | |
$this_product_id = $item['product_id']; | |
// If the product ID matches the Physical Product ID, then remove the recipient (do not send the email to the customer). | |
if ( $this_product_id == 127 ) { | |
$recipient = ''; | |
} | |
} | |
return $recipient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment