Disable guest checkout

I have a problem with my clients from the website. I want to make them to sign up, so I want to disable the guest checkout, they should could buy only if they have an account.

How can I do this?

Thanks in advance

Upvotes: 2

Views: 9139

Answers (2)

Savan Dholu
Savan Dholu

Reputation: 900

Option 1: Checkout - this image disable checkout

Checkout this image disable checkout

Option 2: Add this code of function.php file 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";
                break;
            }
        }
    }
    return $value;
}

Option 3 (Update): Checkout - this image disable checkout for guests in the current version of this update which is Woocommerce Version 3.6.5 I tried and it's worked for me. So now the guest have to login or sign up to continue. Checkout this image disable checkout

Upvotes: 5

sweety
sweety

Reputation: 11

Allow customers to place orders without an account can be enable or disable in Account&privacy tab in woocommerce -> settings

Upvotes: 1

Related Questions