1
votes

I'm trying to add custom content after the order table on the Woocommerce "Processing Order" and "Order Completed" customer emails, using the following code.

It should only be added if the customer chose "Local Pickup" as the shipping method.

function local_pickup_extra_content_email($order, $is_admin_email) {
    if ( $is_admin_email ) {
        return;
    }

    if ( ICL_LANGUAGE_CODE == "he" && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
        echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
    }
}

add_action( 'woocommerce_email_after_order_table', 'local_pickup_extra_content_email', 10, 2  );

The content isn't being added to the emails specified. It's only being added to the "Order Details/Invoice" email that's sent manually through the Woocommerce order admin page.

How can I add the above content to the emails mentioned? What am I doing wrong?
(The email templates aren't overridden in the theme folder)

2

2 Answers

2
votes

This can be done easily targeting those email notifications through the missing hook argument $email, this way:

add_action( 'woocommerce_email_after_order_table', 'local_pickup_extra_content_email', 10, 4  );
function local_pickup_extra_content_email( $order, $sent_to_admin, $plain_text, $email ) {
    // Only for "Processing Order" and "Order Completed" customer emails
    if( ! ( 'customer_processing_order' == $email->id || 'customer_completed_order' == $email->id ) ) return;

    $lang = get_post_meta( $order->id, 'wpml_language', true );
    if ( $lang == 'he' && && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
        echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
    }
}

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

Tested and works


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

1
votes

This didn't work because of my WPML condition in the if statement:

ICL_LANGUAGE_CODE == "he" 

I don't think ICL_LANGUAGE_CODE exists when Woocommerce sends an email. To fix this, I replaced the if statement in the question above with with the following, and it worked like a charm:

$lang = get_post_meta( $order->id, 'wpml_language', true );
if ( $lang == 'he' && && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
    echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
}