2

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

3

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

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Excellent! Thanks @LoicTheAztec. Just the answer I needed – Jeffrey Fong Feb 20 '18 at 06:20
  • Sorry to re-awaken the beast, but I have noticed that this code affects my Woocommerce->settings->emails page. I have only activated this code for "Completed" emails, but everything below the "Completed" emails options on the settings page disappears. [https://imgur.com/a/5vMPt] - with the filter added; [https://imgur.com/a/81ZgN] - without the filter. Did this happen to you in your test? – Jeffrey Fong Mar 14 '18 at 22:05