久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

WooCommerce 中新訂單電子郵件通知的自定義主題

Custom subject for New Order Email notification in WooCommerce(WooCommerce 中新訂單電子郵件通知的自定義主題)
本文介紹了WooCommerce 中新訂單電子郵件通知的自定義主題的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

在 WooCommerce 中,我想將購(gòu)買的產(chǎn)品設(shè)置為新訂單";電子郵件主題行,類似于:New Order - [{product_name}] ({order_number}) - {order_date}

我知道 product_name 可能由于多個(gè)產(chǎn)品而無(wú)法使用,我仍然可以通過(guò)過(guò)濾訂購(gòu)的產(chǎn)品或僅允許多個(gè)產(chǎn)品來(lái)實(shí)現(xiàn)此目的,因?yàn)橥ㄟ^(guò)的多個(gè)訂單并不多.

我對(duì)修改主題代碼很陌生.

解決方案

新訂單"的電子郵件設(shè)置主題必須是(如您的問(wèn)題):

新訂單 - [{product_name}] ({order_number}) - {order_date}

在下面的代碼中,我將 {product_name} 替換為商品名稱??(以破折號(hào)分隔),因?yàn)橛唵慰梢杂泻芏嗌唐?.....

這個(gè)掛在 woocommerce_email_subject_new_order 中的自定義函數(shù)可以解決問(wèn)題:

add_filter( 'woocommerce_email_subject_new_order', 'customizing_new_order_subject', 10, 2 );函數(shù)customizing_new_order_subject( $formated_subject, $order ){//獲取 WC_Email_New_Order 對(duì)象的實(shí)例$email = WC()->mailer->get_emails()['WC_Email_New_Order'];//從設(shè)置中獲取未格式化的主題$subject = $email->get_option('subject', $email->get_default_subject());//遍歷訂單行項(xiàng)目$product_names = array();foreach( $order->get_items() as $item )$product_names[] = ?$item->get_name();//在數(shù)組中設(shè)置產(chǎn)品名稱//在帶有分隔符的字符串中設(shè)置產(chǎn)品名稱(當(dāng)多個(gè)項(xiàng)目時(shí))$product_names = implode(' - ', $product_names );//替換{product_name}";按產(chǎn)品名稱$subject = str_replace( '{product_name}', ?$product_names, $subject );//格式化并返回自定義的格式化主題返回 $email->format_string( $subject);}

代碼位于活動(dòng)子主題(或活動(dòng)主題)的 function.php 文件中.

經(jīng)過(guò)測(cè)試并有效.


你會(huì)得到這樣的東西:

In WooCommerce I would like to set the product purchased in the "new order" email subject line, something like this: New Order - [{product_name}] ({order_number}) - {order_date}

I understand that product_name cant be used probably due to multiple products is there a way I can still do this by filtering product ordered or just allowing multiple products as not many multi orders go through.

I am very new to modifying theme code.

解決方案

The Email settings for "New Order" the subject need to be (as in your question):

New Order - [{product_name}] ({order_number}) - {order_date}

In the code below I replace {product_name} by the items product names (separated by a dash) as an order can have many items…

This custom function hooked in woocommerce_email_subject_new_order will do the trick:

add_filter( 'woocommerce_email_subject_new_order', 'customizing_new_order_subject', 10, 2 );
function customizing_new_order_subject( $formated_subject, $order ){
    // Get an instance of the WC_Email_New_Order object
    $email = WC()->mailer->get_emails()['WC_Email_New_Order'];
    // Get unformatted subject from settings
    $subject = $email->get_option( 'subject', $email->get_default_subject() );
    
    // Loop through order line items
    $product_names = array();
    foreach( $order->get_items() as $item )
        $product_names[] = ?$item->get_name(); // Set product names in an array
    
    // Set product names in a string with separators (when more than one item)
    $product_names = implode( ' - ', $product_names );
    
    // Replace "{product_name}" by the product name
    $subject = str_replace( '{product_name}', ?$product_names, $subject );

    // format and return the custom formatted subject
    return $email->format_string( $subject );
}

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

Tested and works.


You will get something like this:

這篇關(guān)于WooCommerce 中新訂單電子郵件通知的自定義主題的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問(wèn)題中添加自定義注冊(cè)字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡(jiǎn)單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 在线不卡 | 亚洲精品一区二区在线观看 | 91视频免费在观看 | 91伊人| 中文字幕在线观看一区 | 色性av| 亚州中文字幕 | 视频一区二区在线观看 | 成人免费小视频 | av国产在线观看 | 日本午夜视频 | 337p日韩| 中国黄色在线视频 | 久久免费视频1 | 在线免费黄色小视频 | 免费精品视频在线观看 | 天天射天天操天天干 | 91国内精精品久久久久久婷婷 | 一区二区三区亚洲 | 国产视频精品在线 | 日韩欧美久久 | 人人做人人澡人人爽欧美 | 成人乱人乱一区二区三区软件 | 欧美国产一区二区 | 夜夜爽99久久国产综合精品女不卡 | 精品久久国产视频 | 超碰免费在线观看 | 日韩精品中文字幕在线 | 国产精品久久久久久亚洲调教 | 日韩精品久久一区 | 欧美日韩精品久久久免费观看 | 91在线一区二区 | 天天色综 | 久久久久久91 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 完全免费在线视频 | 日韩成人高清 | 男女午夜免费视频 | 国产精品久久久久久久久久不蜜臀 | av天天干 | 成人一区二区三区在线观看 |