WOO // PAYPAL禁用付款方式会导致致命错误

时间:2020-10-20 12:24:04

标签: php wordpress woocommerce

我与两个插件不兼容。 如果要购买特殊类别的产品,我需要禁用PayPal快速检查功能。 从前端的角度来看,这非常正常:

add_filter( 'woocommerce_available_payment_gateways', 'abo_no_paypalCheckout' );

function abo_no_paypalCheckout( $available_gateways ) {
global $woocommerce;

$cat_in_cart = false;
if (WC()->cart && !WC()->cart->is_empty()){
// Loop through all products in the Cart        
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    #echo ($cart_item['product_id']);
    // If Cart has category "download", set $cat_in_cart to true
    if ( (has_term( 'abc', 'product_cat', $cart_item['product_id'] ))  ) {
        $cat_in_cart = true;
        break;
    }
}
}    
// Do something if category "download" is in the Cart      
if ( $cat_in_cart ) {
unset( $available_gateways['ppec_paypal'] );

}
 return $available_gateways;
}   

以某种方式,我尝试访问woo>设置>付款时出现致命错误,并且在日志中出现此错误:

2020-10-19T12:05:58 + 00:00严重的未捕获错误:呼叫成员 函数inn中的get_cart() /www/shop/public/wp-content/themes/woondershop-pt-child/functions.php:536 堆栈跟踪: #0 /www/shop/public/wp-includes/class-wp-hook.php(288):abo_no_paypalCheckout(Array) #1 /www/shop/public/wp-includes/plugin.php(206):WP_Hook-> apply_filters(Array,Array) #2 /www/shop/public/wp-content/plugins/woocommerce/includes/class-wc-payment-gateways.php(160): apply_filters('woocommerce_ava ...',数组) #3 /www/shop/public/wp-content/plugins/woocommerce-subscriptions/includes/gateways/class-wc-subscriptions-payment-gateways.php(115): WC_Payment_Gateways-> get_available_payment_gateways() #4 /www/shop/public/wp-content/plugins/woocommerce-subscriptions/includes/admin/class-wc-subscriptions-admin.php(1853): WC_Subscriptions_Payment_Gateways :: one_gateway_supports('subscriptions') #5 /www/shop/public/wp-includes/class-wp-hook.php(288):WC_Subscriptions_Admin :: add_recurring_payment_gateway_informatio /www/shop/public/wp-content/themes/woondershop-pt-child/functions.php 在Zeile 536中

第536行是foreach的开头。

有什么想法吗?

谢谢!

-编辑--

代码已固定!

0 个答案:

没有答案