0

I am trying to either disable or change the subject line on the woocommerce confirmation email that goes to admins.

I want to do this for only one specific product category.

Any help is appreciated.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Sean Smith
  • 11
  • 1
  • 6

1 Answers1

1

Update (related to your comment).

Using a custom function hooked in woocommerce_email_subject_new_order filter hook will allow you to change the subject for "New Order" admin email notification, for a specific product category.

You will have to define in the code below the targeted product category and the custom subject:

add_filter( 'woocommerce_email_subject_new_order', 'custom_subject_for_new_order', 10, 2 );
function custom_subject_for_new_order( $subject, $order ) {
    $found = $others = false;

    // HERE define your product categories in the array (can be IDs Slugs or Names)
    $categories = array('clothing'); // coma separated for multiples categories

    // HERE define your custom subject for those defined product categories
    $custom_subject  = __("My custom subject goes here", "woocommerce");

    // Loop through order items
    foreach( $order->get_items() as $item ){
        if( has_term( $categories, 'product_cat', $item->get_product_id() ) && $found )
            $found = true; // Category is found
        else
            $others = true; // Other Categories are found
    }
    // Return the custom subject when targeted product category is found but not others.
    return $found && ! $others ? $custom_subject : $subject;
}

Code goes in function.php file of the active child theme (or active theme).

Tested and works.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thank you! This is working great. One further question. Is there a way to make this change apply if ONLY an item from this category is in the order. Meaning, if a person has an item from the category "free-downloads" the subject will change, but if they have one from "free-downloads" and one from "novels" or any other category the subject will not change. – Sean Smith Jan 24 '18 at 17:18
  • Works perfectly! Thank you for your help! – Sean Smith Jan 24 '18 at 18:30
  • @SeanSmith I remove the code from your question as it has nothing to do There. This is an issue related to an update or something else… and you should ask a new question instead, where you can use this code. This way it will appear on recent question, and will allow other to answer. Thanks – LoicTheAztec Jan 31 '18 at 16:27
  • @SeanSmith No problem just telling you the better way… If you can remove the comments after Works perfectly! it could be nice as your actual issue can be due too so many things. Thanks – LoicTheAztec Jan 31 '18 at 21:54