管理员电子邮件中的优惠券代码以及优惠券金额

时间:2020-02-03 06:48:24

标签: php woocommerce

我一直在使用此代码在管理电子邮件中显示客户使用的优惠券代码,但是是否还可以显示每个优惠券代码的金额(对于多个优惠券),当前所有优惠券代码折扣均被视为管理员电子邮件中“折扣”下有1个折扣。

// 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>';
}

0 个答案:

没有答案