0

我试图在客户从特定类别购买产品时发送的确认电子邮件中包含自定义电子邮件主题。感谢@LoicTheAztec,我能够在functions.php中插入一些代码,并且在第一次测试时它似乎工作正常。但由于某种原因,代码不再产生任何结果。在此类别中购买的商品具有标准的 woocommerce 确认主题。

这是我正在使用的代码:

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

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

    // HERE define your custom subject for those defined product categories
    $custom_subject  = __("FREE DOWNLOAD ORDER CONFIRMATION", "woocommerce");

    // Loop through order items
    foreach( $order->get_items() as $item ){
        if( has_term( $categories, 'product_cat', $item->get_product_id() ) ){
            $found = true; // Category is found
            break; // We stop the loop
        }
    }
    // Return the custom subject when product category is found in order items
    return $found ? $custom_subject : $subject;
}

感谢您提供任何帮助。

4

0 回答 0