Search code examples
phpwordpresswoocommerceemail-templatesshipping-method

Display notice on WooCommerce emails depending on chosen shipping option


I need to display a specific notice on the customer-processing-order.php email template in WooCommerce depending on the chosen shipping option. Is there a way to check the chosen shipping option in the e-mail template and return a note on the email depending on that?

Example: a customer chooses shipping methods 'Pick up in local store', the email confirmation then contains a note stating 'We will contact you as soon as your order is ready for pickup'.


Solution

  • Inside customer-processing-order.php template you have access to the $order variable which contains info about the order.

    Using that variabile you have access to the chosen shipping method using one of the following:

    1- $order->get_shipping_method(); // Gets formatted shipping method title. Returns a string 2- $order->get_shipping_methods();// Return an array of shipping costs within this order WC_Order_Item_Shipping[]

    you could check with the 2nd method the chosen shipping method and access the method_id or method_title to determinate if you need to add a custom message inside your email template. Something like this:

    foreach ( $order->get_shipping_methods() as $shippingMethod ) {
        if ($shippingMethod->get_method_title() == "Local pickup"){
            echo "We will contact you as soon as your order is ready for pickup";
        }
    }