implode导致无效参数显示在管理员销售电子邮件上

问题描述 投票:0回答:1

任何时候我们有没有使用优惠券的销售,我收到错误的电子邮件说明implode()无效的参数functions.php

直到最近,我还没有引起这个问题,然后我将网站从一个主机移动到另一个主机并更新了所有插件。

电子邮件功能挂钩显示文本

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

如果客户不使用优惠券,它应该是空白的或者说“没有使用优惠券” - 我不确定为什么多个优惠券区域在他们不使用任何优惠券时导致该部分。

而不是它的工作,我只是得到这个无效的参数来破坏错误

php wordpress implode
1个回答
0
投票

尝试使用array_push而不是$coupon_codes[]

$coupon_codes = array();
foreach( $order->get_items('coupon') as $coupon ){
      //$coupon_codes[] = $coupon->get_code();
      array_push($coupon_codes,$coupon->get_code());//changes
}

一些主机在阵列创建中不支持qazxsw poi。

© www.soinside.com 2019 - 2024. All rights reserved.