WooCommerce: Allow to “Pay for Order” Without Login

Some plugins such as “deposit” and “subscription” payments send customers to the “Pay for Order” page in order to complete a pending WooCommerce order. In certain cases, also, customer is forced to log in and this really affect sales conversion rate – instead of the checkout form customers see this notice: “Please log in to your account below to continue to the payment form“.

Here’s a quick snippet to make sure customers do not have to log in when on the “Pay for Order” page, so that they can immediately go ahead with the payment. The WooCommerce function in question is wc_customer_has_capability, and thankfully we can override this with the user_has_cap filter. Enjoy!

Screenshot of the “Please log in to your account below to continue to the payment form” notice that appears on the “Pay for Order” page

PHP Snippet: Allow Customer to “Pay for Order” if Logged Out (WooCommerce Checkout)

/**
 * @snippet       Pay for Order if Logged Out - WooCommerce Checkout
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'user_has_cap', 'bbloomer_order_pay_without_login', 9999, 3 );

function bbloomer_order_pay_without_login( $allcaps, $caps, $args ) {
	if ( isset( $caps[0], $_GET['key'] ) ) {
		if ( $caps[0] == 'pay_for_order' ) {
			$order_id = isset( $args[2] ) ? $args[2] : null;
			$order = wc_get_order( $order_id );
			if ( $order ) {
				$allcaps['pay_for_order'] = true;
			}
		}
	}
	return $allcaps;
}


Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

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.

52 thoughts on “WooCommerce: Allow to “Pay for Order” Without Login

  1. Just added this today and seems to work fine. WP 5.8 WC 6.0

  2. Is there anyway i can placed order without filling billing form..

    when i just click on Add to card Button redirect to asking payment page. just user complete payment and than go account page and fill details if he want to provide. otherwise no need to ask details.

    1. Hi Alkesh, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. Forgot to say, that the code I have provided, also allow to pay for open order without logging in. I mean that you can manually create an order in WooCommerce admin dashboard, and then give a link to customer for pay. So, with the code located above, the customer dont need to provide login and password. The customer can pay without any “you need to log in to pay for this order…”

    So, the code do the two things:

    1. Allow pay for order without logging in during the usual order using “add to cart” (recognizing customer using e-mail that he provide at form during checkout and then add his new order to existing profile. It can be convenient for LMS LearnPress for example – non-logged old user with old e-mail, buys a new course and new course automatically adding to his account)

    2. Allow pay for open order which been created through admin dashboard without needed of entrance in account from the side of an user.

  4. Our team have developed the solution to allow orders from existing customers without logging in.

    The solution have been tested on WooCommerce v5.3.0 and v5.4.0 (June 2021).

    The system uses e-mail address to recognize whether is it new customer or old. If it new user, then new account will be create during a checkout as usual. If this is a new order from OLD user with old e-mail address in database, then new order will be added to existing WordPress profile. There won’t be any messages like “user already registered, please, login)

    How does the code works?

    When a non-logged in user with existing profile clicks on “proceed to checkout” button, the code use cookie to authenticate user without password for a very short time to trick the woocommerce system. Then immediately logs user out and moves on to the normal checkout process.

    Here is the code. You need to put it in your theme “function.php” file (to end of the file or to top of the file):

    // Allow WooCommerce existing customers to checkout without being logged in (allow orders from existing customers in WooCommerce without logging in)
    function your_custom_function_name( $allcaps, $caps, $args ) {
    	if ( isset( $caps[0] ) ) {
    		switch ( $caps[0] ) {
    		case 'pay_for_order' :
    		$order_id = isset( $args[2] ) ? $args[2] : null;
    		$order = wc_get_order( $order_id );
    		$user = $order->get_user();
    		$user_id = $user->ID;
    		if ( ! $order_id ) {
    		  $allcaps['pay_for_order'] = true;
    		  break;
    		}
    
    		$order = wc_get_order( $order_id );
    
    		if ( $order && ( $user_id == $order->get_user_id() || ! $order->get_user_id() ) ) {
    		  $allcaps['pay_for_order'] = true;
    		}
    		break;
    		}
    	}
    	return $allcaps;
    }
    add_filter( 'user_has_cap', 'your_custom_function_name', 10, 3 );
    
    add_filter( 'woocommerce_checkout_posted_data', 'ftm_filter_checkout_posted_data', 10, 1 );
    function ftm_filter_checkout_posted_data( $data ) {
    	$email = $data['billing_email'];	
    	if ( is_user_logged_in() ) {
    	} else {
    		if (email_exists( $email)){
    			$user = get_user_by( 'email', $email );
    			if ($user){
    				$user_id = $user->ID;
    				wc_set_customer_auth_cookie($user_id);
    				session_start();
    				$_SESSION['p33'] = "133";			
    				$_SESSION['u'] = $user_id;			
    				
    			} else {
    				$user_id = false;
    			}
    		}
    	}
        return $data;
    }
    
    add_action( 'woocommerce_new_order', 'clearuser' );
    function clearuser($data) {
    	
    	if ($_SESSION['p33']==133){
    		//WC()->session->set('pp1',"0");
    		nocache_headers();
    		wp_clear_auth_cookie();		
    		
    		$yourSession= WP_Session_Tokens::get_instance($_SESSION['u']);
    		$yourSession->destroy_all();		
    		
    		$_SESSION['p33']='';
    		$_SESSION['u']='';
    	}
    }
    
    //End Allow Woocommerce Order Pay Without LogIn
    
    1. This Worked like A Charm,
      But On Checkout Page the Message is Still Displayed on Top…
      If you are a returning Customer Click to login.. That defeats the Purpose Slightly

      1. Mikhail, that’s awesome code, it worked great. The order was added to the existing account without having to login. Thank you!

  5. Thanks for sharing this script. It worked like a charm. I don’t know why there isn’t more solutions around sending WooCommerce invoices without the user needing to be logged in.

  6. Can’t seem to get this working with WP 5.6.2, WOO 4.9.2 and Subscriptions 3.0.11. When an user hit the ‘pay now’ button in the subscription renewal email, they are still redirected to the ‘my-account’ page. Anyone who got this working with subscriptions?

  7. Hey,,
    Code worked perfect with by passing the log in page which is awesome..

    But now After paying through PayPal the payment doesn’t go through and it just returns to the website with no items in cart..

    Payments were going though previously..

    Code error in log is

    [L_ERRORCODE0] => 10486

    Which is weird because that state it’s a card issue when it’s 100% isn’t the card

    1. Strange! Is that WooCommerce 5.0?

      1. Very strange!

        There is no error logs now, just returns to cart saying nothing in cart.

        Yes woo commerce 5.0

        As soon i remove your code, payment goes through when logged into an account.

        All setting on woo commerce are set to only check out as guest.

        1. And if you temporarily revert to Woo 4.9?

          1. Same issue!

            Any recommendations?

            It doesn’t seem to be an issue with the website or else it would get as far as the PayPal payment?

            Thoughts?

            1. Bump, has anyone been able to solve this issue?

  8. We are releasing a plugin for this, this week – does anyone still require this? If so let me know!

      1. Hi! Is this plugin yet released & does it also work for subscriptions?

        Thanks,
        Max

        1. Hello! Have you realized the plugin? Could you tell the name of the plugin?

  9. I am unfortnunately reporting that the code does not work for me either: I am running WordPress 5.6, WooCommerce 4.9, no Gutenberg, just a standard checkout. I installed the code to my functions.php file. But when trying to place a test order using a customer identity that already has a WordPress registration (but hasn´t placed a WooCommerce order yet), the WooCommerce checkout does not allow the order (for a product, not a subscription) to be placed – it says that a registration already exists and ask the user to log in before finishing the order.

    This surely must be a huge issue for all/anyone selling anything using a WooCommerce store: Forcing existing customers to log into their account is a major sales deterrent. A since lot of customers don´t remember their account details, they often have to go though a password reset first. But if we force them to do (log in to their account, but since they don´t rememeber their passwords they have to do a password reset first) this whilst in the middle of ordering, they will just abandon the order and go somewhere else.

    Am I wrong in thinking that there must be a simple solution to this (and this code not necessary at all)? Or are all those hundreds of thousands of people using a WooCommerce store just throwing their potential orders away by forcing their clients to log in before placing an order?

    1. Weird, I use this snippet on Business Bloomer checkout. Maybe your theme (or another plugin) is messing/conflicting with my snippet.

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentytwenty” theme (load the snippet there in functions.php) as explained here: https://www.businessbloomer.com/lesson/trwm4l01/

      Once you do that, does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

  10. Hi, tested on WordPress 5.5.1 with WooCommerce 4.5.1 and it is definitely not working at all. Login is still required to pay for order. The only thing that helped was removing two specific blocks from wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php
    Update of this snippet for newest WP & WOO would be appreciated …

    1. Maybe it doesn’t work with WooCommerce checkout Gutenberg block? Works on the default checkout, and I have no intention of using Gutenberg on the checkout – sorry

      1. Having the same (i think) issue, clean WordPress 5.5.1 with WooCommerce 4.5.2 and StoreFront (tried with other ones as well) theme.

        Adding code to the functions file and it still giving “Oops! That page can’t be found.” whiles trying to access “/order-pay/41?pay_for_order=true&key=wc_order_XDhEK1P3ekpJE” type of URL as logged out user.

        1. Please ignore my previous comment as it does work properly and the issue was with the client not adding all the needed billing fields.

          1. Nice!

            1. Hello, Mirek. Could you tell me what specific block have you removed?

  11. This one will work with latest version:

    public function my_woocommerce_before_checkout_form($checkout) {
         remove_filter( 'woocommerce_checkout_registration_required', '__return_true', 0 );
    }
    add_action( 'woocommerce_before_checkout_form', array($this,'my_woocommerce_before_checkout_form'), 10, 1 );
    
    1. Mine still works, actually

      1. Where to put it, Gil?

  12. This snippet is great! Thanks for putting this together!

    It does not work for renewal orders for subscriptions. I think that is because by default the pay for order page goes to the My Account page. Any thoughts on bypassing that so that a subscriber could pay without logging in??

    Thanks in advance!

    1. Hi Meg, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  13. Hi,

    This snippet doesn’t work on last WooCommerce version (

    1. Screenshot?

      1. I had the same experience tried adding the snippet to my child theme and it is still making me log in to pay for a order (woocommerce subscription order)

        1. I understand this was not created for woocommerce subscriptions is there anyway to get that functionality with subscriptions plugin

          1. Hey Levi, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  14. Hi,

    Interesting post. I have a similar problem.

    If I manually created an order without any info, how can I grant anyone with the link access without logging in?
    Slug example: order-received/view-order/XXXX.
    WooCommerce doesn’t authorise access because the order is not associated with an email address or account. My goal is to manually permit downloads through the order page.

    Thanks

    1. Hi Connor, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  15. Hi,
    Does this work with the woo subscription plugin?

    1. Don’t know James, did you try by any chance?

  16. It doesnt work anymore after recent woocommerce update as of OCT-30-2019

    1. Hi Sam, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  17. thank you so much for your help

    1. Welcome!

  18. Hi,

    Thank you for this. I was looking for this for the last 3 days.

    My customers usually have difficulties about login to pay their “pending payment” and for “renewal payments.”
    I am using Woocommerce Subcipriton to sending renewal notifications.
    What I wanted is letting customer click the link on their email and go to payment page directly without any login.

    I tested your code, it looks like working without Subscription plugin.
    But when I activated the subscription plugin it is redirecting to login page again with this URL
    …?wcs_redirect=pay_for_order&wcs_redirect_id=122

    It needs modification for Subscription but I have no idea how to do it.

    There is another ongoing discussion about this case on this URL: https://wordpress.org/support/topic/order-pay-without-login/

    I tested the code on that link too but the same result. Definitely, need some modification for Subscription.

    I just want to share my experience.

    Thank you for your work.
    M.

    1. Thank you!

  19. Hi Rodolfo!!! Again, one more great feature in this post!! thank you!!

    One question so, even if the user doesn’t have a registered account, once we send him the order url he will be able to pay no?

    1. I think so – do some tests and let me know 🙂

  20. Hi Rodolfo,
    Can you think of any risk with this snippet from a security perspective ?
    E.g. could a customer pay the wrong order ? could a hacker access order details ? etc
    Thanks

    1. Hello Jean 🙂 If WooCommerce is forcing login, for sure there must be a reason. However when I go to the “Pay for Order” page I don’t think there is sensitive data (please test), so it’s anonymous as long as I know.

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.