php - Different email heading based on shipping methods in Woocommerce

774

So I want to send the same email with a slightly different heading in WooCommerce. It uses the argument$email_heading variable to hold the value of that current email heading so I figure a simple replacement would work. It doesn't. I could be completely missing the mark here any help is much appreciated.

I want it to say Your Order is ready for pickup when they choose local pickup and then the default value (stored the email settings of woocommerce) when any other shipping is chosen.

add_filter( "woocommerce_email_heading_customer_completed_order", 'HDM_woocommerce_email_header', 10, 2 );
function HDM_woocommerce_email_header( $email_heading, $email ) {
  if ('customer_completed_order' == $email->id && $order->has_shipping_method('local_pickup') ){
      $order_id = $order->get_id();
      $email_heading = '<h1>Your Order Is Ready For Pickup</h1>';
    }
      return $email_heading;
    };
65

Answer

Solution:

There are some mistakes in your code like$email that is in fact$order. Also you are already targetingcustomer_completed_order in this composite hook, so you don't need it in yourIF statement…

So try instead:

add_filter( "woocommerce_email_heading_customer_completed_order", 'custom_email_heading', 10, 2 );
function custom_email_heading( $email_heading, $order ) {
    if ( $order->has_shipping_method('local_pickup') ){
        $email_heading = '<h1>Your Order Is Ready For Pickup</h1>';
    }
    return $email_heading;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

356

Answer

Solution:

i'm wondering if this is valid for email subject:

add_filter( "woocommerce_email_subject_customer_completed_order", 'custom_email_subject', 10, 2 );
function custom_email_subject( $subject, $order ) {
    if ( $order->has_shipping_method('local_pickup') ){
        $subject = 'Your Order Is Ready For Pickup';
}
return $subject;
}

People are also looking for solutions to the problem: php - Laravel 5.5 Eloquent groupBy on ManyToMany Relationship

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.