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, the 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“.
On top of that, there is another notification error for guest orders: “To view this page, you must either login or verify the email address associated with the order” – we’ll fix that as well.
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!
PHP Snippet: Allow Customers to “Pay for Order” if Logged Out @ WooCommerce Order Pay Checkout
/**
* @snippet Pay for Order if Logged Out - WooCommerce Order Pay
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
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;
}
add_filter( 'woocommerce_order_email_verification_required', '__return_false', 9999 );
This code no longer works. Nothing is displayed in the email.
Hi Mel, what do you mean? This code is for the “Order Pay” page
Hi Rodolfo!
Did you test this with WC 8.3.1?
It is not working for me using Woo Subscritpions 5.7.0.
If you disable Woo Subscriptions temporarily, does the snippet work?
Hi Rodolfo,
Your code works for initially loading the payment page without logging in. However, if the customer attempts the payment and it fails, they are redirected to a page telling them to log in or provide their email address. This seems to be new since WC 7.9.0.
I see. What’s the URL of this page?
I ahev the sime error, afeter payed the order, dont go on the thankyoupage
Ciao Giuseppe, this looks like a different error than the one mentioned above (on payment failed). Yours is when payment is successful, correct?
Yes, the order is payment successful. but dont go on thankyou page and i see the login form?
How to correct this?
I’ve just tested it again. It works perfectly when a logged out user pays for a guest order.
Other scenarios where the logged in user is different than the order customer (non guest order), you will get the login page instead.
Hi Rodolfo,
I have applied the code and nothing happened, the issue came up in one of the latest WC update.
Hey Wagner, what do you mean by “nothing happened”? Please note I’ve edited the snippet since Woo 7.8, and it’s working for me on this same website
I am using the WC 7.9.0 and here is an example of a page where was used to show a simple thank you page for non logged users – we don’t ask for user registration, only guests.
Your post was one of the few option for the issue that I have but even though I am still receiving the message to login with email. (once I include my email it launches the thankyou page, but the purchase tracking is on thankyou page and I can’t expect the user will include their email)
Here is an example of how the page should load in stag: https://dev.uccellodesigns.co.uk/checkout/order-received/34005/?key=wc_order_d26GE0EkNhYFB
I also update all settings available on WC admin dashboard.
Have you any idea of what it can be?
The line
removes that “login or verify” wall. Try again please
I have also encountered the same problem as Wagner. It works to allow the guest to pay but upon successful payment it navigated to a page that asks for a login.
Try using a priority of 999 – see updated snippet. Also please make sure the user who is paying for the order is not logged in. Let me know
Much appreciated, thank you. On the pay_for_order page no more login for users and no email confirmation for guests , super !
With GeneratePress theme and Snippets plugin.
Yay!
Just added this today and seems to work fine. WP 5.8 WC 6.0
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.
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!
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.
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):
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
Mikhail, that’s awesome code, it worked great. The order was added to the existing account without having to login. Thank you!
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.
Great!
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?
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
Strange! Is that WooCommerce 5.0?
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.
And if you temporarily revert to Woo 4.9?
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?
Bump, has anyone been able to solve this issue?
We are releasing a plugin for this, this week – does anyone still require this? If so let me know!
Sure, let us know
Hi! Is this plugin yet released & does it also work for subscriptions?
Thanks,
Max
Hello! Have you realized the plugin? Could you tell the name of the plugin?
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?
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!
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 …
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
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.
Please ignore my previous comment as it does work properly and the issue was with the client not adding all the needed billing fields.
Nice!
Hello, Mirek. Could you tell me what specific block have you removed?
This one will work with latest version:
Mine still works, actually
Where to put it, Gil?
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!
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!
Hi,
This snippet doesn’t work on last WooCommerce version (
Screenshot?
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)
I understand this was not created for woocommerce subscriptions is there anyway to get that functionality with subscriptions plugin
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!
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
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!
Hi,
Does this work with the woo subscription plugin?
Don’t know James, did you try by any chance?
It doesnt work anymore after recent woocommerce update as of OCT-30-2019
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
thank you so much for your help
Welcome!
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.
Thank you!
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?
I think so – do some tests and let me know π
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
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.