Home » WooCommerce: Allow to “Pay for Order” Without Login

WooCommerce: Allow to “Pay for Order” Without Login

by Tutor Aspire

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.6.2
 * @donate $9     https://www.tutoraspire.com
 */

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

function tutoraspire_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;
}

You may also like