Remove woocommerce complete or processing email ba

2019-06-07 21:23发布

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条回答
唯我独甜
2楼-- · 2019-06-07 21:36

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

查看更多
登录 后发表回答