Skip to content

Instantly share code, notes, and snippets.

Created March 10, 2016 09:39
  • Star 16 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
WooCommerce Disable guest checkout for certain products
// Code goes in theme functions.php or a custom plugin
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'conditional_guest_checkout_based_on_product' );
function conditional_guest_checkout_based_on_product( $value ) {
$restrict_ids = array( 1, 2, 3 ); // Replace with product ids which cannot use guest checkout
if ( WC()->cart ) {
$cart = WC()->cart->get_cart();
foreach ( $cart as $item ) {
if ( in_array( $item['product_id'], $restrict_ids ) ) {
$value = "no";
return $value;
Copy link

How to disable guest checking for all products, untick in the wordpress does not work :(

Copy link

Hello, How can i do the opposite? How to enable guest checkout for certain products?

Copy link

Here is the opposite:

  • also adds a checkbox on the product to enable guest checkout

Copy link

How can I do this for a certain woocommerce category, not an array of product ids?

Copy link

ghost commented Jan 4, 2019

Hi dear friend
this hook «pre_option_woocommerce_enable_guest_checkout» used.
where is woocommerce defined?

Copy link

vahid162 commented Aug 25, 2021

I use this code to customize the email on the WooCommerce checkout page:

add_filter( 'woocommerce_billing_fields', 'ts_unrequire_wc_email_field'); function ts_unrequire_wc_email_field( $fields ) { $fields['billing_email']['required'] = false; return $fields; }

How can I specify that if a product needs to be registered, email will be required?

Copy link

bradthebluefish commented Jun 8, 2022

6 years old and still works for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment