为了账号安全,请及时绑定邮箱和手机立即绑定

在 WooCommerce 订单电子邮件通知中显示使用过的优惠券

在 WooCommerce 订单电子邮件通知中显示使用过的优惠券

PHP
当年话下 2022-12-23 14:31:20
我有一个显示已用优惠券的代码:add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 );function add_payment_method_to_admin_new_order( $order, $is_admin_email ) {        if( $order->get_used_coupons() ) {            $coupons_count = count( $order->get_used_coupons() );            $i = 1;            $coupons_list = '';            foreach( $order->get_used_coupons() as $coupon) {                $coupons_list .=  $coupon;                if( $i < $coupons_count )                    $coupons_list .= ', ';                $i++;            }            echo '<p></p>';            echo '<p><strong>Купон:</strong> ' . $coupons_list . '</p>';        } // endif get_used_coupons}以及在 WooCommerce 表行中显示信息的代码:add_filter( 'woocommerce_get_order_item_totals', 'bbloomer_add_recurring_row_email', 10, 2 );function bbloomer_add_recurring_row_email( $total_rows, $myorder_obj ) {    $total_rows['recurr_not'] = array(    'label' => __( 'Купон:', 'woocommerce' ),    'value'   => 'blabla'    );return $total_rows;}如何将使用过的优惠券转移到价值字段?像这样 'value' => 'used_coupon'
查看完整描述

1 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

由于您可以通过钩子访问该$order对象woocommerce_get_order_item_totals,因此您可以以相同的方式应用它。


所以你得到:


// After order table

function action_woocommerce_email_after_order_table( $order, $sent_to_admin, $plain_text, $email ) {

    // Get used coupons

    if ( $order->get_used_coupons() ) {

        // Total

        $coupons_count = count( $order->get_used_coupons() );


        // Initialize

        $i = 1;

        $coupons_list = '';


        // Loop through

        foreach ( $order->get_used_coupons() as $coupon ) {

            // Append

            $coupons_list .=  $coupon;


            if ( $i < $coupons_count )

                $coupons_list .= ', ';


            $i++;

        }


        // Output

        echo '<p><strong>Купон:</strong> ' . $coupons_list . '</p>';

    }

}

add_action( 'woocommerce_email_after_order_table', 'action_woocommerce_email_after_order_table', 10, 4 );


// Display on customer orders and email notifications

function filter_woocommerce_get_order_item_totals( $total_rows, $order, $tax_display ) {

    // Get used coupons

    if ( $order->get_used_coupons() ) {

        // Total

        $coupons_count = count( $order->get_used_coupons() );


        // Initialize

        $i = 1;

        $coupons_list = '';


        // Loop through

        foreach ( $order->get_used_coupons() as $coupon ) {

            // Append

            $coupons_list .=  $coupon;


            if ( $i < $coupons_count )

                $coupons_list .= ', ';


            $i++;

        }


        // Output

        $total_rows['recurr_not'] = array(

            'label'     => __( 'Купон:', 'woocommerce' ),

            'value'     => $coupons_list,

        );

    }


    return $total_rows;

}

add_filter( 'woocommerce_get_order_item_totals', 'filter_woocommerce_get_order_item_totals', 10, 3 );



查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 126 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号