Tuesday, July 13, 2021

Allow Guest Checkout on Certain products – WooCommerce

  • Allow Guest Checkout on Certain products on WooCommerce
  • Want an option to enable checkout for guest on specific products

If you are looking for a solution for these problems on WooCommerce as I mentioned above, then you are at the right place.

WooCommerce has a lot of built-in customization possibilities, so it’s easy to make it your own. There are various options for setting up the checkout process, including asking for registration. This is completely dependent on how you want to perform your checkout.

By default WooCommerce have these Option:

  1. Allow Customers to place orders without an account, which means allow guest checkout on all products. You can’t choose a specific product for this the same.
  2. Allow Customers to login into an existing account during checkout
  3. And allow customers to create an account during checkout.

But these default options are not allowing to use of these functionalities on specific products.

So first of all, disable Guest Checkout Woocommerce. Now all products required login or registration on the checkout page.

Now, Follow these steps:

Allow Guest Checkout on Certain products

Go to your WordPress Dashboard and find Appearance on the sidebar. Hover the mouse on Appearance and click on the Theme Editor.

If You are visiting Theme editor the first time, then you may see one pop-up with a warning. Just click on the “I understand” button. Now select your child theme.

I suggest using the Child version of the WordPress theme, or you can select your main theme.

Find function.php and click on it. Now you can see the codes, scroll down and paste this code in the function.php

Copy Code

/*--------------------------------------
Woocommerce - Allow Guest Checkout on Certain products
----------------------------------------*/

// Display Guest Checkout Field
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
  global $woocommerce, $post;
  
  echo '<div class="options_group">';
  
  // Checkbox
  woocommerce_wp_checkbox( 
  array( 
	'id'            => '_allow_guest_checkout', 
	'wrapper_class' => 'show_if_simple', 
	'label'         => __('Checkout', 'woocommerce' ), 
	'description'   => __('Allow Guest Checkout', 'woocommerce' ) 
	)
   );
  
  echo '</div>';
}

// Save Guest Checkout Field
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields_save( $post_id ){
	$woocommerce_checkbox = isset( $_POST['_allow_guest_checkout'] ) ? 'yes' : 'no';
	update_post_meta( $post_id, '_allow_guest_checkout', $woocommerce_checkbox );
}

// Enable Guest Checkout on Certain products
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'enable_guest_checkout_based_on_product' );
function enable_guest_checkout_based_on_product( $value ) {

  if ( WC()->cart ) {
    $cart = WC()->cart->get_cart();
    foreach ( $cart as $item ) {
      if ( get_post_meta( $item['product_id'], '_allow_guest_checkout', true ) == 'yes' ) {
        $value = "yes";
      } else {
        $value = "no";
        break;
      }
    }
  }
  
  return $value;
}

Now Click on the Update file button. You can understand the process with the image below.

Allow Guest Checkout on Certain products

Now, it’s done!

Go to your products and find a check box option ( Allow Guest Checkout ) in the product data section.

 

Allow Guest Checkout on Certain products

I hope you like this guide. You can share this with your friends to help them regarding the Woocommerce Checkout as a guest on Certain products.

Woocommerce – Disable guest checkout on all products

You can stop guest checkout for all products by disabling the check box “Allow customers to place orders without an account.”

You can find this check box by following this path:

WordPress Dashboard > WooCommerce > Settings > Accounts & Privacy

disable guest checkout, WooCommerce,

Now, Enable the account creation and click on save changes. You can find this button (save changes) after scrolling down.

Allow to create an account during checkout – Woocommerce

After disable “Allow customers to place orders without an account.”

Check for/Select “Allow customers to create an account during checkout.” and “Allow customers to create an account on the “My account” Page”

Follow the same path – WordPress Dashboard > WooCommerce > Settings > Accounts & Privacy

disable guest checkout

It will be applied on all products on WooCommerce.

If you want to give an option to login for existing customer then check “Allow customers to log into an existing account during checkout.”

Don’t forget to click on Save Changes.

Once you enable this option in WordPress, then you can see the changes on checkout page.  One another mandatory field (Password) will be add on checkout page. Email and Password will be the mandatory filed after this process.

After entering the email and password, account will be created for the buyer.

If you want to add login and signup page before checkout then you can follow the next steps.

Force Authentification Before Checkout for WooCommerce

To allow force authentication before checkout on WooCommerce, you can use this Force Authentification plugin.

Once, you complete the process of disabling the test checkout and allow new account on checkout page, use this plugin.

After activation, you can check the changes on checkout page. If you don’t see any changes then clear your cache.

This plugin allow force authentication on WooCommerce checkout page, without login or registration your website not allow for checkout.

If you find this guide helpful, don’t forget to share with others. Thanks

Read:

Sharing is Caring

Don’t forget to share with others. Thanks! 

My Name is Rashvinder Narwal, I am in Website design and development profession from 2015. I love to share my knowledge with my readers over 15+ blogs in English and Hindi language. Thanks !

LEAVE A REPLY

Please enter your comment!
Please enter your name here