Menu Close

WooCommerce: Allow to “Pay for Order” Without Login

default

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!

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 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
 * @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;
}

add_filter( 'woocommerce_order_email_verification_required', '__return_false', 9999 );
View Source
Posted in WooCommerce Tips