第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

在 WooCommerce 訂單上使用優(yōu)惠券代碼時發(fā)送電子郵件通知

在 WooCommerce 訂單上使用優(yōu)惠券代碼時發(fā)送電子郵件通知

PHP
慕蓋茨4494581 2023-09-15 17:42:05
使用特定優(yōu)惠券時如何向業(yè)務(wù)伙伴發(fā)送訂單通知?我在這里找到了應(yīng)用優(yōu)惠券時實例的解決方案: Send an email notificationwhen a certain coupon code is apply in WooCommerce但是,我需要找到提交訂單后何時提交的解決方案,因為訂單并不總是在應(yīng)用優(yōu)惠券后提交。每張優(yōu)惠券都有自己的電子郵件地址。
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗 獲得超6個贊

首先,我們在優(yōu)惠券管理頁面添加一個設(shè)置字段,用于設(shè)置優(yōu)惠券的電子郵件收件人:


// Add a custom field to Admin coupon settings pages

add_action( 'woocommerce_coupon_options', 'add_coupon_text_field', 10 );

function add_coupon_text_field() {

    woocommerce_wp_text_input( array(

        'id'                => 'email_recipient',

        'label'             => __( 'Email recipient', 'woocommerce' ),

        'placeholder'       => '',

        'description'       => __( 'Send an email notification to a defined recipient' ),

        'desc_tip'    => true, // Or false


    ) );

}


// Save the custom field value from Admin coupon settings pages

add_action( 'woocommerce_coupon_options_save', 'save_coupon_text_field', 10, 2 );

function save_coupon_text_field( $post_id, $coupon ) {

    if( isset( $_POST['email_recipient'] ) ) {

        $coupon->update_meta_data( 'email_recipient', sanitize_text_field( $_POST['email_recipient'] ) );

        $coupon->save();

    }

}

如果已為所應(yīng)用的優(yōu)惠券設(shè)置了電子郵件收件人,則系統(tǒng)會將每張所應(yīng)用的優(yōu)惠券的電子郵件發(fā)送到已提交的訂單。


警告!僅選擇以下功能之一:


對于 woocommerce 版本 最高 4.3 (新掛鉤)


// For Woocommerce version 4.3+

add_action( 'woocommerce_checkout_order_created', 'custom_email_for_orders_with_applied_coupon' );

function custom_email_for_orders_with_applied_coupon( $order ){

    $used_coupons = $order->get_used_coupons();


    if( ! empty($used_coupons) ){

        foreach ( $used_coupons as $coupon_code ) {

            $coupon    = new WC_Coupon( $coupon_code ); // WC_Coupon Object

            $recipient = $coupon->get_meta('email_recipient'); // get recipient


            if( ! empty($recipient) ) {

                $subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code );

                $content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );

                wp_mail( $recipient, $subject, $content ); // Send email

            }

        }

    }

}

或者對于所有 WooCommerce 版本(自版本 3.0 起)


// For all Woocommerce versions (since 3.0)

add_action( 'woocommerce_checkout_update_order_meta', 'custom_email_for_orders_with_applied_coupon' );

function custom_email_for_orders_with_applied_coupon( $order_id ){

    $order = wc_get_order( $order_id );


    $used_coupons = $order->get_used_coupons();


    if( ! empty($used_coupons) ){

        foreach ( $used_coupons as $coupon_code ) {

            $coupon    = new WC_Coupon( $coupon_code ); // WC_Coupon Object

            $recipient = $coupon->get_meta('email_recipient'); // get recipient


            if( ! empty($recipient) ) {

                $subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code );

                $content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );

                wp_mail( $recipient, $subject, $content ); // Send email

            }

        }

    }

}

代碼位于活動子主題(或活動主題)的functions.php 文件中。經(jīng)過測試并有效。

https://img1.sycdn.imooc.com//6504272100010f1f06520276.jpg

查看完整回答
反對 回復(fù) 2023-09-15
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號