WooCommerce 2.6.14 – Change selected payment method by default

I recently updated my shop to WooCommerce 2.6.14 (ver. 3 breaks up menu editor), created Shipping Zones and disabled old shipping methods. I set up payment methods in this order: COD – COP – BACS and they list up correctly on checkout BUT ‘bacs’ is always selected as default. For flat rate and free shipping I allow cod/bacs and for local pickup I use cop/bacs, so I want to make cod or cop always selected as default or make the payment method unselected at all and let the customer do it.

This snippet deselects shipping but when I choose Flat Rate I get BACS method automatically selected again. Cleared all sessions, tried incognito mode, still not working properly..

// Code to clear default shipping option.
add_filter( 'woocommerce_shipping_chosen_method', '__return_false', 99);

// Code to clear default payment option.
add_filter( 'pre_option_woocommerce_default_gateway' . '__return_false', 99 );

Also in WC 2.5.5 I used this snippet for unsetting BACS for Local Pickup, but it is no more working with Shipping Zones, is there any other way?

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_pickup', $chosen_shipping_rates ) ) :
        // Remove bank transfer payment gateway
        unset( $gateways['bacs'] );
    return $gateways;
add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );

Thanks for any help.

Read more here: WooCommerce 2.6.14 – Change selected payment method by default

Leave a Reply

Your email address will not be published. Required fields are marked *