亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將產品 SKU 添加到 WooCommerce 新訂單電子郵件主題

如何將產品 SKU 添加到 WooCommerce 新訂單電子郵件主題

PHP
慕沐林林 2023-11-03 17:39:21
基于Woocommerce - 將用戶名添加到新訂單電子郵件主題行。我正在嘗試更改 WooCommerce 電子郵件主題行。訂購時我作為網站管理員在我的郵件中收到的電子郵件。我正在嘗試創建以下結構[在線商店]訂單(#....)名稱,第二名,總計-...,SKU1, SKU2, SKU3...我使用此代碼,但我不知道如何獲取訂單中每個產品的 SKU?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] Order (# %s) от %s %s Total-%u EU. %s ', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name, $order->order_total, $order->...);return $subject;}
查看完整描述

1 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

為此,您可以使用以下方法,通過 foreach 循環從訂單對象獲取產品 SKU。


在代碼中添加了帶有解釋的注釋


function filter_woocommerce_email_subject_new_order( $subject, $order ) {   

    // Blogname

    $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );

    

    // Get order ID

    $order_id = $order->get_id();

    

    // Get billing first name

    $first_name = $order->get_billing_first_name();

    

    // Get billing last name

    $last_name = $order->get_billing_last_name();

    

    // Get order total

    $order_total = $order->get_total();

    

    // Empty array

    $product_skus = array();


    // Loop through order items

    foreach( $order->get_items() as $item ) {

        // Get an instance of corresponding the WC_Product object

        $product = $item->get_product();

        

        // Push to array

        $product_skus[] = $product->get_sku();

    }

    

    // Array to string

    $product_skus_str = implode( ", ", $product_skus );

    

    // Subject

    $subject = sprintf( '[%s] Order (# %s) From %s %s Total %s SKU %s', $blogname, $order_id, $first_name, $last_name, $order_total, $product_skus_str );


    return $subject;

}

add_filter( 'woocommerce_email_subject_new_order', 'filter_woocommerce_email_subject_new_order', 1, 2 );



查看完整回答
反對 回復 2023-11-03
  • 1 回答
  • 0 關注
  • 183 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號