PHP警告:in_array()期望参数2为数组,给定null

时间:2015-12-17 02:24:13

标签: php wordpress paypal woocommerce

请帮忙。我无法弄清楚这一点,并授予我只是学习PHP 我尝试将代码添加到现有的woocommerce功能,如果购物车中有一组产品,则删除支付网关。 我认为从底部的第4行"添加了自动支付if语句"这是问题所在。提前谢谢。

public function is_available() {
    //added for autopay 1 line
    global $woocommerce;
    $is_available = parent::is_available();
    //added for autopay 2 lines
    foreach ($woocommerce->cart->cart_contents as $key => $values )
    $autopays = array(26108,30619,35613);
    // don't show on checkout page
    if ( ! $this->is_express_checkout() && is_checkout() && ! $this->show_on_checkout() ) {
        $is_available = false;
    }

    // don't display when order review table is rendered via AJAX
    if ( ! $this->is_express_checkout() && defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && $_POST['action'] == 'woocommerce_update_order_review' && ! $this->show_on_checkout() ) {
        $is_available = false;
    }

    // don't show on checkout > pay page
    if ( is_checkout_pay_page() ) {
        $is_available = false;
    }

    // don't show if the cart contains a subscription and manual renewals are not enabled
    if ( $this->get_plugin()->is_subscriptions_active() && WC_Subscriptions_Cart::cart_contains_subscription() && 'no' === get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no' ) ) {
        $is_available = false;
    }
    //added for auto pay if statement
     if(in_array($values['product_id'],$autopays)){$is_available = false;
    }
    return $is_available;
}

1 个答案:

答案 0 :(得分:0)

foreach的语法是

foreach (array_expression as $key => $value) {
    statement1...
    statement2... 
}

在您的代码中,您在foreach语句之后错过了开始和结束括号。