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        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @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 (before "?>" if you have it). 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+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a 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.

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

  1. thank you so much for your help

    1. Welcome!

  2. 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!

  3. 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 ๐Ÿ™‚

  4. 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: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.