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(" // Function to uncheck payment methods and hide payment boxes function uncheckPaymentMethods() { // ONLY RUN IF MORE THAN 1 PAYMENT OPTION if ($('.woocommerce-checkout').find('input[name=\"payment_method\"]').length === 1) return; // UNCHECK CHECKED PAYMENT METHOD $('input[name=\"payment_method\"]').prop('checked', false); // CLOSE CHECKED PAYMENT DESCRIPTION BOX $('div.payment_box').hide(); } // Run the function on document ready $(document).ready(function() { uncheckPaymentMethods(); }); // Run the function on updated_checkout event but only once $(document.body).one('updated_checkout', function() { uncheckPaymentMethods(); }); "); }
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.
Hello, when we activate your snippet and select a payment method it is automatically unchecked, i saw someone else complained about this but you didn’t fix it yet.
Hi Youssef,
Could you please confirm if the payment method gets unchecked automatically when the page reloads? Also, we’ve updated the code in the post so that the payment method is unchecked initially. Once a payment method is selected, it will stay checked even if customers make changes on the checkout page or if the page reloads.
Hi thanks for this code snippet, I tell you that when I activate it and select a payment method it is automatically unchecked, could you please help me?
Hi Lady,
The code has been tested & works well at my end. Please try switching to a default WordPress theme and deactivating other plugins except WooCommerce to check if there is a theme/plugin conflict. Ensure that the version of WooCommerce is up to date. If the issue persists, please let us know if you have made any other customizations to your checkout page or payment gateways so that we can assist you better.