WooCommerce: No Default Payment @ Checkout Page

When you land on the WooCommerce Checkout page, one payment option (radio button) will be selected by default. this is defined based on the last payment method (logged in customer), or the payment gateway sorting (logged out customer).

Often it happens, however, that customers forget to change their payment selection, and therefore end up checking out with the wrong payment option. Which means, more admin work.

With this simple snippet, we will inject some JS in the Woo Checkout page, so that on load, all payment method radio inputs will be unchecked. Super easy!

With the snippet below, whenever the Checkout page is accessed, there won’t be any pre-selected payment option. User is now forced to click on one of them, otherwise they’ll get an error.

PHP Snippet: Remove Default Payment Gateway On WooCommerce Classic Checkout Page Load

The purpose of the function is to uncheck the default payment method and hide the corresponding payment method description box if there is more than one payment option available.

In summary, when the WooCommerce checkout page is loaded or updated, this code checks the number of available payment options. If there is more than one option, it unchecks any currently checked payment method and hides the corresponding payment method description box. This can be useful to prevent a default payment method from being pre-selected when there are multiple payment options available during the checkout process.

/**
 * @snippet       No Default Payment @ Woo Checkout
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     Join https://businessbloomer.com/club/
 */

add_action( 'woocommerce_before_checkout_form', 'bbloomer_uncheck_default_payment_gateway' );
 
function bbloomer_uncheck_default_payment_gateway() {
	
	wc_enqueue_js( "
	
   		// FLAG TO TRACK IF WE'VE ALREADY RUN ON INITIAL LOAD
      	var initialLoadComplete = false;
		
      	// ONLY RUN ON CHECKOUT PAGE LOAD
      	$( document.body ).on( 'updated_checkout', function() {
		
			// SKIP IF WE'VE ALREADY RUN ON INITIAL LOAD
			if ( initialLoadComplete ) return false;
		
			// ONLY RUN IF MORE THAN 1 PAYMENT OPTION
			if ( $( '.woocommerce-checkout' ).find( 'input[name=\'payment_method\']' ).length === 1 ) {
				initialLoadComplete = true;
				return false;
			}
			
			// UNCHECK CHECKED PAYMENT METHOD
			$('input[name=\'payment_method\']').prop('checked', false);
			
			// CLOSE CHECKED PAYMENT DESCRIPTION BOX
			$('div.payment_box').hide();
			
			// MARK INITIAL LOAD AS COMPLETE
         initialLoadComplete = true;
			
     	});
		
   " );
	
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

6 thoughts on “WooCommerce: No Default Payment @ Checkout Page

  1. Hi! The code works when the checkout page is first displayed as no payment method is selected by default. However, the moment the user types in their delivery address, shipping method updates and, immediately, the first payment option is automatically selected, totally reversing the effect of your snippet. Any idea on what to do? Thanks.

    1. Gotcha. Took me a while, but maybe I’ve got a solution: no payment method should be automatically selected, unless you manually select it. Until then it won’t have a selection. Before I update this snippet, can you maybe help me with testing? Here’s the code:

      add_action( 'woocommerce_before_checkout_form', 'bbloomer_uncheck_default_payment_gateway' );
      
      function bbloomer_uncheck_default_payment_gateway() {
          wc_enqueue_js( "
              var userHasChosenPayment = false;
      
              // Detect manual payment method click
              $( document ).on( 'change', 'input[name=\"payment_method\"]', function() {
                  userHasChosenPayment = true;
              });
      
              $( document.body ).on( 'updated_checkout', function() {
                  if ( ! userHasChosenPayment ) {
                      if ( $( 'input[name=\"payment_method\"]' ).length > 1 ) {
                          $( 'input[name=\"payment_method\"]' ).prop( 'checked', false );
                          $( 'div.payment_box' ).hide();
                      }
                  }
              });
          ");
      }
      
  2. First of all, thank you so much for all your amazing WooCommerce customizations โ€” your snippets have helped me and countless others streamline our stores!

    I tested your “No Default Payment @ Woo Checkout” snippet and noticed an issue: the code keeps unchecking the selected payment method every time the checkout updates via AJAX โ€” for example, when a user selects a payment method. This happens because the updated_checkout event also fires when a payment method is chosen, not just on page load.

    As a result, users canโ€™t actually select a payment method, since it keeps getting automatically unchecked.

    1. You’re 100% right! I’ve now edited the snippet, can you give it another go and let me know please?

      1. Yes! It works now, thanks a lot for the quick fix.

        I did notice a small issue though: when I first land on the checkout page, the default payment method is still briefly shown and then gets unselected (which I assume is expected behavior).

        However, the fees associated with that pre-selected payment method still get applied โ€” even though the payment method itself is later unselected by the snippet. Itโ€™s almost like WooCommerce is calculating fees before the uncheck script runs.

        At first I thought this might be a limitation in WooCommerce, but Iโ€™ve seen some sites that donโ€™t show a default payment method at all โ€” not even briefly โ€” and donโ€™t apply any fees until a payment method is actually selected. So I think it might be possible to refine the snippet further to match that behavior.

        Just wanted to share in case it helps! Let me know if I can test anything further.

        1. Thank you Youssef. Can you please test this new version and see if it makes any difference: https://www.businessbloomer.com/woocommerce-no-default-payment-checkout-page/#comment-1025236

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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