久久久久久久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)
主站蜘蛛池模板: 黄视频网站免费观看 | 久久久久国产一级毛片 | 二区国产 | 国产精品一区久久久 | 男女啪啪高潮无遮挡免费动态 | 久久国际精品 | 亚洲第一av | 婷婷中文字幕 | 91色视频在线观看 | 日韩精品在线观看一区二区三区 | 久久久女女女女999久久 | 久久精品国产一区 | 国产精品www | 久久久久久久一区 | 91精品国产91久久久久久 | 成人深夜福利 | 一区中文字幕 | 三级在线观看 | 手机在线一区二区三区 | 欧美激情国产日韩精品一区18 | 亚洲人人 | 日韩一区二区三区视频在线播放 | 国产精品久久久久久久粉嫩 | 在线观看黄色电影 | aaaa一级毛片 | 国产精品三级久久久久久电影 | 黄色一级在线播放 | 又黑又粗又长的欧美一区 | 久久精品久久精品久久精品 | 成人免费福利视频 | 99精品免费久久久久久久久日本 | 亚洲精品4 | 国产一级电影网 | 国产精品久久久久久久免费大片 | 一区日韩| 精品国产一区二区三区久久影院 | 欧美日韩在线观看视频网站 | 日韩免费视频一区二区 | 成人欧美一区二区三区在线播放 | 亚洲精品在线免费看 | 亚洲一区精品在线 |