Add a custom condition to the “Additional Custom Emails & Recipients for WooCommerce” plugin

/**
 * Adds a custom condition to the "Additional Custom Emails & Recipients for WooCommerce" plugin.
 *
 * @see https://wpcodebook.com/add-condition-custom-emails-for-woocommerce-plugin/
 * @see https://plugins.trac.wordpress.org/browser/custom-emails-for-woocommerce/tags/3.4.0/includes/classes/class-alg-wc-custom-email.php#L481
 * @see https://wordpress.org/plugins/custom-emails-for-woocommerce/
 * @see https://wpfactory.com/item/custom-emails-for-woocommerce/
 */
add_filter( 'alg_wc_custom_emails_do_send_order_email', function ( $do_send, $email, $order ) {
	foreach ( $order->get_items() as $item ) {
		if (
			123 == $item['product_id'] ||
			567 == $item['variation_id']
		) {
			return true;
		}
	}
	return false;
}, 10, 3 );

Leave a Comment