• Resolved Jake

    (@jake2townz)


    Is this code still applicable to the new version of Woocommerce with Shipping Zones in effect? For some reason this doesn’t work anymore ever since I upgraded to the new version of Woocommerce. Thanks!

    <?php
    /**
    * Filter payment gatways
    */
    function my_custom_available_payment_gateways( $gateways ) {
    $chosen_shipping_rates = WC()->session->get( ‘chosen_shipping_methods’ );
    // When ‘local delivery’ has been chosen as shipping rate
    if ( in_array( ‘local_delivery’, $chosen_shipping_rates ) ) :
    // Remove bank transfer payment gateway
    unset( $gateways[‘bacs’] );
    endif;
    return $gateways;
    }
    add_filter( ‘woocommerce_available_payment_gateways’, ‘my_custom_available_payment_gateways’ );

    https://wordpress.org/plugins/woocommerce/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    The method_id ‘local_delivery’ won’t be the same with zones. Method IDs will differ.

    Thread Starter Jake

    (@jake2townz)

    Is there a documentation that presents an updated code using the Method ID?

    I have purchased the conditional shipping and payments plugin (1.2.0) just for this but its AJAX coding conflicts with the Booster for Woocommerce plugin, preventing me from adding conditions in the Payment Gateway field. Thus I have to forgo the former and choose the latter plugin since my site relies heavily on it.

    I hope you could help.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    I’ve seen “Booster” causing all sorts of issues. Maybe you should remove your dependence.

    About the issue, the name will be something like bacs:ID, with the ID being the shipping method instance’s ID.

    Thread Starter Jake

    (@jake2townz)

    Thank you! I’ll try this out.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Hiding certain payment gateways based on selected shipping method’ is closed to new replies.