Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Remove/Hide add to cart button in Woocommerce if the user is not logged in
//Option One (if you decided to use Option Two then remove this function and its action hook)
function remove_add_cart_button(){
$isLoggedIn = is_user_logged_in();
if(false == $isLoggedIn){
//if the user is not login then remove add to cart button by removing the action hook
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
//Option Two (If you decided to use Option One then don't add the following code)
add_filter('woocommerce_is_purchasable', 'my_woocommerce_is_purchasable', 10, 2);
function my_woocommerce_is_purchasable($is_purchasable, $product) {
$isLoggedIn = is_user_logged_in();
if(true == $isLoggedIn){
//Make product purchasable to logged in user
return true;
//Make product not purchasable to unlogged in user
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment