本文介紹了在管理新訂單電子郵件模板中添加應用的優惠券代碼 - WooCommerce的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
讓我澄清一下我的問題:
Let me clear my question:
- 我已經下載 &已激活用于電子商務功能的 WooCommerce 插件.
- 我想使用我的自定義插件在管理新訂單電子郵件模板中添加應用的優惠券代碼".
現在:
- 你能告訴我實際設置新訂單電子郵件模板的確切鉤子或函數,以便我覆蓋它嗎?
- 你能告訴我如何調用應用的優惠券代碼,以便我將其顯示在電子郵件模板中嗎?
如果你能幫助我,那就太好了.
It would be great, if you help me please.
推薦答案
這可以使用掛鉤在 woocommerce_email_order_details 操作掛鉤(例如)中的自定義函數來完成,該函數將在管理員電子郵件通知中顯示訂單中使用的優惠券:>
This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:
// The email function hooked that display the text
add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {
// Only for admins and when there at least 1 coupon in the order
if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;
foreach( $order->get_items('coupon') as $coupon ){
$coupon_codes[] = $coupon->get_code();
}
// For one coupon
if( count($coupon_codes) == 1 ){
$coupon_code = reset($coupon_codes);
echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
}
// For multiple coupons
else {
$coupon_codes = implode( ', ', $coupon_codes);
echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
}
}
代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.
經過測試并有效...
這篇關于在管理新訂單電子郵件模板中添加應用的優惠券代碼 - WooCommerce的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!