问题
I am trying to remove the processing (or complete) email based on some order meta.
I'm using a POS system and getting customers to pay via the customer invoice email - the initial order status is pending payment. I want to a) test if the order was made using the pos, b) remove either the "processing" or "complete" email.
I can't seem to get the if statement logic to work. I'm pretty sure the meta key is '_pos' and the value is '1' or '0'.
Here's my myphp screem shot of wp_postmeta
add_action( 'woocommerce_email', 'removing_POS_emails' );
function removing_POS_emails( $email_class, $order_id ) {
//Remove the Processing email for POS emails
$pos_test = get_post_meta( $order_id, '_pos', true );
if ( $pos_test == "1" ) {
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
}
}
Am I missing something? Can post meta be used in the woocommerce_email hook?
If I get the if statement correct I'm confident I can remove the processing/complete email or even change the email class and create a custom processing email.
回答1:
Update (There was a bug on the other hook related to $order argument):
Here is the correct way to do it:
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'conditional_email_notification', 10, 2 );
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'conditional_email_notification', 10, 2 );
function conditional_email_notification( $recipient, $order ) {
if( is_admin() ) return $recipient;
if ( get_post_meta( $order->get_id(), '_pos', true ) ){
return '';
}
return $recipient;
}
This code goes on function.php file of your active child theme (or theme). tested and works.
Similar answer: Avoid customer email notification for a specific product category in Woocommerce
来源:https://stackoverflow.com/questions/48827068/remove-woocommerce-complete-or-processing-email-based-on-order-meta