wordpress Woocommerce -隐藏基于所选运输方式的付款

q1qsirdb  于 2023-01-16  发布在  WordPress
关注(0)|答案(1)|浏览(164)

我一直试图找出如何隐藏某些支付网关的基础上选定的航运。我一直在与此代码,但迄今为止没有。任何帮助?

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' );

}
}
mwngjboj

mwngjboj1#

//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' );

相关问题