Different customers may have different preferences or requirements when it comes to payment methods. Some might prefer credit cards, while others may prefer digital wallets or bank transfers. This customization is very useful in removing the default preselected payment option and providing customers with the flexibility to choose their preferred payment method.
add_action( 'woocommerce_before_checkout_form', 'ts_uncheck_default_payment_gateway' ); function ts_uncheck_default_payment_gateway() { wc_enqueue_js( " // ONLY RUN ON CHECKOUT PAGE LOAD $( document.body ).on( 'updated_checkout', function() { // ONLY RUN IF MORE THAN 1 PAYMENT OPTION if ( $( '.woocommerce-checkout' ).find( 'input[name=\'payment_method\']' ).length === 1 ) return false; // UNCHECK CHECKED PAYMENT METHOD $('input[name=\'payment_method\']').prop('checked', false); // CLOSE CHECKED PAYMENT DESCRIPTION BOX $('div.payment_box').hide(); }); " ); }
Output
The output shows that the default pre-selected payment method is removed and all the payment options are set to be unchecked on the WooCommerce checkout page. Additionally, the description gets hidden and when the user selects any payment method, then it is shown.
The following output shows the default preselected payment method that appears in the absence of implementing the above code.
Similarly, you can also remove the default pre-selected shipping method on the WooCommerce checkout page.