【发布时间】:2019-04-02 14:57:15
【问题描述】:
如果通过将以下代码添加到主题 function.php 中选择了一种运输方式,我试图隐藏两种付款方式
// Filter payment gatways for different shipping methods
function my_custom_available_payment_gateways( $gateways ) {
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
if ( in_array( 'flat_rate:7', $chosen_shipping_rates ) ) {
unset( $gateways['stripe'] );
unset( $gateways['ppec_paypal'] );
}
endif;
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways',
'my_custom_available_payment_gateways' );
一切正常。除了我在产品页面上收到此错误。
警告:
in_array() 期望参数 2 为数组,在 [theme function.php 和行号] 中给出 null
【问题讨论】:
-
the code works properly and when the chosen shipping method selected that two payment gateway are not shown.但我在产品页面中也收到了 null 给定错误。
标签: php wordpress woocommerce shipping-method payment-method