You troubled about Guest checkout still active even after disabling guest checkout on WooCommerce

As you know that if you want to disable guest checkout, it’s supposed to be easy.

Normal way if going to WooCommerce settings:   WooCommerce >> Settings >> Accounts >> Account Creation >> Allow customers to create an account during checkout

U tick it off or on

But for some reason, it might refuse as I did on mine, there are usually two reasons; 1. your theme is not compatible or  2, another plugin is overriding your settings.

Then what to do  if Disable guest checkout is not working as it should be.

One might think of getting another theme, but it was not an option to me because I was done with everything in my WordPress website, so i could not go back to getting something new, moreover the client had liked what he was having.

I kind of wanted to switch one plugin by one, but all plugin I had where vitae, and I was feeling sleepy to go into all that.

So after taking a glass of water with some lemon, I decided to think out of the box, I decided what if I enforce non-logged-in users on the checkout page  to not access checkout but instead be redirected to registration page

How to redirect non-logged in users to a specific page?

WooCommerce’s check and redirect to log in before checkout script or code.

Infact this is the Simplest Way to  of avoiding guest checkout  when all ways have failed without an additional plugin if it even exists.
Force User Registration before visiting Checkout Page

Put code below into your WordPress theme functions file.

Note in code below checkout is the slug name of my page, so u replace it with yours

and https://webvator.com/register is the page name with registration form

// Code
add_action( ‘template_redirect’, ‘redirect_to_specific_page’ );

function redirect_to_specific_page() {

if ( is_page(‘checkout’) && ! is_user_logged_in() ) {

wp_redirect( ‘https://webvator.com/register’, 301 );
exit;
}
}

WooCommerce force login before checkout  code by webvator

Write a comment