search

Home  >  Q&A  >  body text

WooCommerce order completion email notification: restrict specific shipping methods

I'm trying to disable the completed order email only if the customer selects the "Retirada no local" shipping method.

I found the following code, which disables email for all shipping methods except one - it's not what I need, but it might help:

function filter_woocommerce_email_recipient_new_order( $recipient, $order = false ) {   
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) return $recipient;
    
    // 获取配送方式
    $shipping_method = $order->get_shipping_method();

    // 不等于(注意:这应该根据您网站语言中的配送方式进行调整)
    // 例如:荷兰语中的“Afhalen”等...
    if ( $shipping_method != 'Local Pickup' ) {
        $recipient = '';
    }

    return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'filter_woocommerce_email_recipient_new_order', 10, 2 );```

P粉327903045P粉327903045525 days ago623

reply all(1)I'll reply

  • P粉541565322

    P粉5415653222023-09-10 10:16:25

    Change the version of the code you provided to one that disables the "Order Completed" customer email when 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;
        
        // 获取配送方式
        $shipping_method = $order->get_shipping_method();
    
        // 仅在配送方式为“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 );

    Please note that your shipping method must exactly match the words and capital letters of the phrase "Retirada no local" for this code to be valid.

    reply
    0
  • Cancelreply