亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Add product name in subject of WooCommerce new order email notification
P粉990008428
P粉990008428 2023-08-18 08:55:45
0
1
929
<p>I want to change the subject line of the email I send to the store owner to put the product name in it. I saw this code to put the customer's name in front How can I adjust this code to include the product name</p> <pre class="brush:php;toolbar:false;">/* * Place it in the theme’s functions.php or custom plug-in * * Topic filter: *woocommerce_email_subject_new_order *woocommerce_email_subject_customer_processing_order *woocommerce_email_subject_customer_completed_order *woocommerce_email_subject_customer_invoice *woocommerce_email_subject_customer_note *woocommerce_email_subject_low_stock *woocommerce_email_subject_no_stock *woocommerce_email_subject_backorder *woocommerce_email_subject_customer_new_account *woocommerce_email_subject_customer_invoice_paid **/ add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2); function change_admin_email_subject( $subject, $order ) { global $woocommerce; $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $subject = sprintf( '[%s] New customer order (# %s) from name %s %s', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name ) ; return $subject; }</pre> <p>Maybe we just need to make changes here</p> <pre class="brush:php;toolbar:false;">$subject = sprintf( '[%s] New customer order (# %s) from name %s %s', $blogname, $item-> ;get_name, $order->billing_first_name, $order->billing_last_name ); return $subject; }</pre> <p><br /></p>
P粉990008428
P粉990008428

reply all(1)
P粉207483087

Your actual code is outdated... To add the purchased product name (and quantity) to the subject of the new order email notification sent to the admin, use the following code:

add_filter('woocommerce_email_subject_new_order', 'change_email_subject_new_order', 10, 2);
function change_email_subject_new_order( $formatted_subject, $order ) {
    $products = array(); // 初始化

    // 循環(huán)遍歷訂單項(xiàng)目
    foreach( $order->get_items() as $item ){
        // 將格式化的產(chǎn)品名稱和數(shù)量添加到數(shù)組中
        $products[] = sprintf( '%s &times; %d', $item->get_name(), $item->get_quantity() );
    }

    $count    = count($products); // 產(chǎn)品數(shù)量
    $products = implode(', ', $products); // 將數(shù)組轉(zhuǎn)換為字符串

    return sprintf( 
        __('[%s] 新客戶訂單(#%s),%s,來自%s%s', 'woocommerce'), 
        wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), $order->get_order_number(), 
        sprintf( _n('產(chǎn)品(%s)', '產(chǎn)品(%s)', $count, 'woocommerce'), $products, $products ),
        $order->get_billing_first_name(), $order->get_billing_last_name() 
    );
}

Place the code in your child theme’s functions.php file (or in a plugin). It has been tested and works fine.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template