虽然该功能在前端似乎运行良好,但在后端,我有:
严重未捕获错误:调用成员函数
这就是函数.
add_filter( 'woocommerce_available_payment_gateways', 'hide_payment_gateways_based_on_weight', 10, 1 );
function hide_payment_gateways_based_on_weight( $available_gateways ) {
if ( is_admin() )
return $available_gateways;
$total_weight = WC()->cart->get_cart_contents_weight();
if ( $total_weight >= 2000 && isset ($available_gateways['cod']) )
unset($available_gateways['cod']); // unset 'cod'
return $available_gateways;
}