Methods Woocommerce-根据选定的装运方式隐藏付款

Methods Woocommerce-根据选定的装运方式隐藏付款,methods,woocommerce,payment,shipping,gateway,Methods,Woocommerce,Payment,Shipping,Gateway,我一直在试图找出如何隐藏某些付款网关的基础上选定的航运。我一直在使用这个代码,但到目前为止什么都没有。有什么帮助吗 add_action( 'woocommerce_after_checkout_form','woocommerce_custom_surcharge' ); function woocommerce_custom_surcharge() { global $woocommerce; $chosen_methods = WC()->session->get( 'ch

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

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