Add a custom text to specific email notification for local pickup Woocommerce orders

后端 未结 1 1693
抹茶落季
抹茶落季 2021-01-03 15:54

I tried the following code that is displaying a message to all those customers who should receive a customer_processing_order and customer_completed_order

相关标签:
1条回答
  • 2021-01-03 16:13

    This can be done iterating through order shipping items, this way:

    add_action( 'woocommerce_email_order_details', 'my_completed_order_email_instructions', 10, 4 );
    function my_completed_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
        // Only for processing and completed email notifications to customer
        if( ! ( 'customer_processing_order' == $email->id || 'customer_completed_order' == $email->id ) ) return;
    
        foreach( $order->get_items('shipping') as $shipping_item ){
            $shipping_rate_id = $shipping_item->get_method_id();
            $method_array = explode(':', $shipping_rate_id );
            $shipping_method_id = reset($method_array);
            // Display a custom text for local pickup shipping method only
            if( 'local_pickup' == $shipping_method_id ){
                echo '<p><strong>Ritiro in sede</strong></p>';
                break;
            }
        }
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and works.

    0 讨论(0)
提交回复
热议问题