0

I am trying to disable the completed order email ONLY if the customer selects the shipping method "Retirada no local" (means local pickup)

I came across the following code that disables the email for every method BUT one - which is not what I need but may be helpful:

function filter_woocommerce_email_recipient_new_order( $recipient, $order = false ) {   
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) return $recipient;
    
    // Get shipping method
    $shipping_method = $order->get_shipping_method();

    // NOT equal (Note: this should be adjusted to the shipping method in your site language)
    // Such as: 'Afhalen' for dutch, etc...
    if ( $shipping_method != 'Local Pickup' ) {
        $recipient = '';
    }

    return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'filter_woocommerce_email_recipient_new_order', 10, 2 );```
  • 1
    seems like that is exactly what you need, just filter `woocommerce_email_recipient_customer_completed_order` instead new_order – Kazz Jun 23 '23 at 02:41
  • @Kazz not really - I do need to change the filter but the code above will disable the email for EVERY order but the ones with the Local Pickup shipping method. What I need is to disable it ONLY for Local Pickup – gmedeirosn Jun 23 '23 at 14:18

1 Answers1

0

A version of the code you provided adapted to disable the Order Completed customer email when the shipping method is Retirada no local

function disable_completed_order_customer_email_for_retirada( $recipient, $order = false ) {   
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) return $recipient;
    
    // Get shipping method
    $shipping_method = $order->get_shipping_method();

    // Only disable if the shipping method is Retirada no local
    if ( $shipping_method === 'Retirada no local' ) {
        $recipient = '';
    }

    return $recipient;
}
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'disable_completed_order_customer_email_for_retirada', 10, 2 );

Note that your shipping method should match exactly the words, and capital letters of the phrase Retirada no local for this to work.

Tami
  • 686
  • 4
  • 8