0

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'.

Thyrok
  • 23
  • 4
  • 1
    In the [emails/customer-processing-order.php](https://github.com/woocommerce/woocommerce/blob/02cf0dfaed5923513de0c88add597d1560c2cfd2/templates/emails/customer-processing-order.php) template file you have access to the `$order` object, then you can use [Get orders shipping items details in WooCommerce 3](https://stackoverflow.com/questions/46102428/get-orders-shipping-items-details-in-woocommerce-3). Note: this template can be overridden by copying it to `yourtheme/woocommerce/emails/customer-processing-order.php` – 7uc1f3r Sep 02 '20 at 14:49

1 Answers1

3

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";
    }
}
Diego
  • 1,610
  • 1
  • 14
  • 26