Enabling Guest Checkout In WooCommerce: Bypassing Email Verification For Order Payment | Code For Developers

Enabling Guest Checkout in WooCommerce: Bypassing Email Verification for Order Payment

Enable guest payment, bypass email verification. Enhance user experience, boost conversions. Easy, efficient, and customer-friendly solution

Title: Enabling Guest Checkout in WooCommerce: Bypassing Email Verification for Order Payment

In WooCommerce, providing a seamless and convenient shopping experience is crucial for customer satisfaction. One common requirement is allowing users, even those not logged in, to complete their purchases without the hassle of email verification. In this blog post, we’ll explore a simple code snippet that achieves just that.

The Scenario:

By default, WooCommerce requires users to be logged in and verified via email before they can pay for an order. However, there are situations where you might want to enable guest checkout and skip the email verification step.

The Code:

Let’s dive into the code that makes this possible. This snippet should be added to your theme’s functions.php file or a custom plugin.

functions.php
add_filter( 'user_has_cap', 'mukto_pay_for_order_if_logged_out', 9999, 3 );

function mukto_pay_for_order_if_logged_out( $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' );

Breaking Down the Code:

  • Filter Hook Registration:
    The code hooks into the ‘user_has_cap’ filter, which is triggered when checking if a user has a specific capability. The priority is set high to ensure it runs late in the filter chain.
  • Function Definition:
    The function mukto_pay_for_order_if_logged_out is called when the ‘user_has_cap’ filter is triggered. It modifies user capabilities based on certain conditions.
  • Granting ‘pay_for_order’ Capability:
    If the requested capability is ‘pay_for_order’ and the order exists, the function grants the capability, allowing users to pay for the order.
  • Disabling Email Verification:
    Another filter is added to disable email verification for WooCommerce orders, ensuring a smoother checkout process.

Implementing the Code:

To implement this solution, simply add the provided code to your theme’s functions.php file or create a custom plugin. Once added, users, even those not logged in, will be able to complete their orders without the need for email verification.

Conclusion:

Enhancing the user experience in your WooCommerce store is essential for building customer loyalty. By allowing guest checkout and bypassing email verification for order payment, you can streamline the purchasing process and encourage more conversions. Use the provided code responsibly, keeping in mind the specific needs of your online store and your customers’ preferences.

Previous Code

Making Specific Products Unpurchasable or purchasable for a specific date in WooCommerce

How to make specific products not purchasable in W ...

Next Code

Adding and Removing Class Based on Element Visibility in the Viewport

Add class on element if it come in view and remove ...

Leave a Reply

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

If you find it useful

Buy me a coffee

ACF

Elementor

JavaScript

jQuery

Others

PHP

WooCommerce

WordPress

WP Plugin Dev

How to Implement Google Ads Conversion Tracking in WooCommerce

Learn how to add Google Ads tracking code to your ...

WooCommerce Discount based on Cart Item

A discount on the total order with condition based ...

Update WooCommerce Delivery cost with condition

Change Delivery price base on what item in cart ...

WooCommerce Checkout Conflict with Bootstrap 4.x

WooCommerce Checkout Conflict with Bootstrap 4.x. ...

Get WooCommerce product info

Show product info in the place as you wish to. It ...

top