0
votes

I've been trying to find out how to hide certain payment gateway based on selected shipping. I have been working with this code but nothing so far. Any help with this?

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

}
}
1

1 Answers

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