Skip to content

Instantly share code, notes, and snippets.

@alexmustin
Last active November 1, 2021 21:57
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 alexmustin/530d7c384e1fec4e12c748aa4a27cbbe to your computer and use it in GitHub Desktop.
Save alexmustin/530d7c384e1fec4e12c748aa4a27cbbe to your computer and use it in GitHub Desktop.
WooCommerce - disable 'Order Complete' emails for specific Product ID
<?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