How to Hide Add-to-cart Buttons in WooCommerce

Are you looking for a way to hide add-to-cart buttons in WooCommerce? We’ll show you how to hide add-to-cart buttons in WooCommerce easily and effectively.

When it comes to managing an online store, the more customers place orders, the better. So, why would you even want to hide the shopping cart buttons in the first place?

Although it may sound counterintuitive, disabling or hiding add-to-cart buttons in WooCommerce stores can bring benefits.

Besides customizing the WooCommerce checkout page, there are a few more reasons why you should remove the add-to-cart buttons.

  • You have premium products that you would like to preview that are not yet available for purchase.
  • You want to target different audiences with your marketing campaigns by reserving the add-to-cart buttons for specific user roles or products only.
  • Users who are not logged in can only view your products, but cannot access the order buttons. This forces them to register an account in your stores.
  • Your WooCommerce store serves as a catalog.
  • Your online stores no longer have certain products in stock or they are no longer available.

Let’s look at how to hide the “Add to cart” button in WooCommerce site-wide, for specific pages, products or user roles.

Method 1 – Hide shopping cart button across all pages

To hide the “Add-to-cart” button in the entire WooCommerce store, you need to install the PPWP Pro plugin and its WooCommerce integration extension.

While PPWP Pro protects products with passwords, the WooCommerce extension helps to integrate PPWP Pro with WooCommerce so that you can change the add-to-cart buttons more easily.

The process of hiding add-to-cart buttons on entire WooCommerce websites is done in 2 steps.

Step 1 – Password protect WooCommerce products

After you have installed and activated PPWP Pro and the WooCommerce Integration Extension, you need to do the following.

In your WordPress admin dashboard, go to Password Protection for WordPress > General. Select the “Products” type from the Post Type Protection drop-down list and save your changes.

choose "Product" in the Post Type Production drop down

Go to the “Products” tab and select the products whose add-to-cart buttons you want to hide.

choose products to hide add-to-cart button

Once you have done this, the entire product page will be protected by a password form by default.

password protect add-to-card button

Step 2 – Hide add-to-cart buttons in WooCommerce through a custom code

In the functions.php file of your (child) theme, add the following code to protect only the “Add-to-cart” button.

/**
 * Hide "Add to cart" on all password protected pages.
 */
function ppwp_replace_add_to_card() {
    echo get_the_password_form();
}

add_filter(
    'post_password_required',
    function ($required, $post) {
        global $post;
        if (!$post->ID) {
            return $required;
        }
        if (!function_exists('is_product')) {
            return $required;
        }
        if ($required && is_product()) {
            add_filter('woocommerce_is_purchasable', '__return_false');
            add_action('woocommerce_simple_add_to_cart', 'ppwp_replace_add_to_card');
            add_action('woocommerce_grouped_add_to_cart', 'ppwp_replace_add_to_card');
            return false;
        }
        return $required;
    },
    200, 2
);

All your “Add-to-cart” buttons on the WooCommerce product page will be replaced with password forms.

hide add-to-cart button under a password form

Method 2 – Hide add-to-cart buttons on specific pages only

In this case, you can decide on which WooCommerce-protected product pages you want to hide the add-to-cart buttons.

After you have protected your WooCommerce products with PPWP Pro, add the following code snippet to the functions.php file of your (child) theme.

/**
 * Hide Add to Cart only on certain pages (e.g. post_id=91)
 */
function ppwp_replace_add_to_card() {
    echo get_the_password_form();
}

add_filter(
    'post_password_required',
    function ($required, $post) {
        global $post;
        if (!$post->ID) {
            return $required;
        }
        if (!function_exists('is_product')) {
            return $required;
        }
        $posts_included = [91];
        if (!in_array($post->ID, $posts_included)) {
            return $required;
        }
        if ($required && is_product()) {
            add_filter('woocommerce_is_purchasable', '__return_false');
            add_action('woocommerce_simple_add_to_cart', 'ppwp_replace_add_to_card');
            add_action('woocommerce_grouped_add_to_cart', 'ppwp_replace_add_to_card');
            return false;
        }
        return $required;
    },
    200, 2
);

Note – You can get the post ID by hovering over the desired post title.

Method 3 – Disable Add-to-cart buttons for certain products

Suppose some of your products are out of stock and you need to temporarily disable the “add to cart” buttons. The following instructions will show you how to do this.

Basically, you need to determine the ID of your desired products and then insert the following code snippet into your functions.php file.

Go to Products in your WordPress dashboard. Hover over a product in the list and you will see a product ID.

get product ID

Alternatively, you can also click on the product to see its ID in your browser’s URL.

get product ID by URL

Copy this code and paste it into the functions.php file of your child theme.

/* REMOVE ADD TO CART BUTTON ON SPECIFIC PRODUCT IDs */
add_filter('woocommerce_is_purchasable', 'filter_is_purchasable', 10, 2);
function filter_is_purchasable($is_purchasable, $product ) {
    global $product;
    if( in_array( $product->get_id(), not_purchasable_ids() )) {
        return false;
    }
    return $is_purchasable;
}

function not_purchasable_ids() {
    return array(159);
}

As you can see in the code snippet above, we disable the “add to cart” button for the products with the ID 159. Remember to replace this ID with your actual product IDs. If you want to hide multiple buttons, add multiple products by separating the IDs with a comma.

Method 4 – Hide buttons for users who are not logged in

If you are offering a special offer for your loyal or registered customers, typically only those who receive your emails can access your offer via the attached discount links. But what if your customers share these links with their friends and family?

To avoid this scenario and make sure that only the right customers get to enjoy your discounts, you can hide the add-to-cart buttons in WooCommerce stores for non-registered users.

All you need to do is add the following script to the functions.php file of your child theme.

/* REMOVE THE "ADD TO CART" BUTTON FOR USERS WHO ARE NOT LOGGED IN */
if (!is_user_logged_in()) {
    // on the product page 
    add_filter('woocommerce_is_purchasable', '__return_false');
}

By using WordPress’ own function is_user_logged_in(), the “add-to-cart” button is only deactivated for users who are not logged in.

Method 5 – Remove Add-to-cart buttons based on user roles

This method is very useful if you run a membership site with multiple user roles. Add this code to the functions.php file of your child theme to remove the “Add to cart” button based on user roles.

For example, we apply this code for subscribers.

/* REMOVE THE "ADD TO CART" BUTTON FOR SUBSCRIBERS */
add_action('wp_loaded','get_user_role');
function get_user_role(){
    $current_user = wp_get_current_user();
    if(count($current_user->roles)!==0){
        if($current_user->roles[0]=='subscribers'){
            add_filter('woocommerce_is_purchasable', '__return_false');
        }
    }
}

In this code snippet, the first line helps determine if a user has a role. If the user role matches the one we specified (in this case, subscribers), the second line makes products for that role unsaleable.

You can change the user roles by replacing “subscribers” with the actual roles you want to target.

Conclusion

You now know how to disable add-to-cart buttons in the entire store, on specific pages and products, as well as for users who are not logged in and for specific user roles.

The truth is that among these methods, using PPWP Pro with its WooCommerce integration extension along with the provided codes seems to be the most efficient way. You get more control and flexibility compared to the code-only approaches.

Knowing how to hide add-to-cart buttons gives you the flexibility to customize your stores in different situations. Whether you’re running a catalog site, managing inventory issues, or creating exclusive member experiences, these methods have you covered.