I’m using the below code to make all products on woocommerce not purchasable unless the user is signed in.
function et_remove_atc(){
if( ! is_user_logged_in() ){
return false;
}else{
return true;
}
}
add_filter( 'woocommerce_is_purchasable', 'et_remove_atc' );
This only works for simple products and not variable products. I’ve tried to add the below additional filter, but this doesn’t work.
add_filter( 'woocommerce_variation_is_purchasable', 'et_remove_atc', 10, 2 );
What am I missing?
2
Answers
It’s Default woocommerce setting. you allow guest customer or not.
Uncheck checkbox allow customer to place order without account
Check this screenshot: https://prnt.sc/11fj0kc
You are using the right hook for variable products and its variations. Note that the add to cart button on variable products will stay grayed (disabled) for guests. If it is not the case, it can be due to a plugin, your theme customizations or some other customizations made by you.
The correct code to be used is:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
To remove variable add to cart button (on single product pages) for guests, use the following:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.