0

I found this code (which does work) in a previous thread which enables custom messages for e-mail to customers who've selected local pickup as shipping method.

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;
    }
}

Now to my question: How do I adjust the code to remove the processing order e-mail so it only covers completed order e-mails?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

1

You just need to replace in the function code this:

// Only for processing and completed email notifications to customer
if( ! ( 'customer_processing_order' == $email->id || 
'customer_completed_order' == $email->id ) ) return;

by this:

// Only for completed email notifications to customer
if( 'customer_completed_order' != $email->id ) return;

And it will work only for "completed" order notification to the customer… So the complete code:

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 completed email notifications to customer
    if( '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;
        }
    }
}

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

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399