隐藏付款基于选定的运输方式



我一直在试图找出如何隐藏某些支付网关基于选定的航运。我一直在用这个代码工作,但到目前为止什么都没有。有什么帮助吗?

add_action( 'woocommerce_after_checkout_form','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
 $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
 $chosen_shipping = $chosen_methods[0];
 if ($chosen_shipping == 'table_rate') {   

        function payment_gateway_disable_country( $available_gateways ) {
    unset(  $available_gateways['paytrail'] );
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
}
}
//Hide payment gateways based on shipping method
function payment_gateway_disable( $available_gateways ) {
    global $woocommerce;
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0];
    if( $chosen_shipping == 'table_rate' ) {
        unset($available_gateways['paytrail']);
    }
    return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable' );

最新更新