Website Building » WooCommerce » How Do I Hide Add to Cart Button in WooCommerce for Specific Products?

How Do I Hide Add to Cart Button in WooCommerce for Specific Products?

Last updated on January 15, 2023 @ 3:33 pm

If you want to hide the Add to Cart button on specific products in WooCommerce, then there are a few different ways that you can do this. One way is to use the WooCommerce Product Visibility extension. This extension allows you to hide products from specific user roles, or completely hide them from the shop page.

Another way to hide the Add to Cart button is by using a conditional tag in your theme’s functions.php file. This will allow you to Target specific products and hide the Add to Cart button on those products only.

The WooCommerce Product Visibility extension is a great way to hide products from specific user roles or completely hide them from the shop page. To use this extension, simply go to the product page and select the user role that you want to hide the product from. The product will then be hidden from that user role only.

You can also use this extension to completely hide a product from the shop page. To do this, simply go to the product page and select the “Hide from Shop” option. The product will then be hidden from all users, regardless of their user role.

PRO TIP: If you are considering hiding the Add to Cart button for specific products in WooCommerce, be aware that this could have unintended consequences. For example, if a customer has products in their cart and then navigates to a product page where the Add to Cart button is hidden, they may not be able to checkout. If you decide to go ahead with this change, be sure to test it thoroughly on your site before making it live.

If you want to Target specific products and hide the Add to Cart button only on those products, then you can use a conditional tag in your theme’s functions. To do this, simply add the following code to your functions.php file:

function my_custom_product_hide_add_to_cart( $bool ) {
 global $product;
 if ( $product->get_id() == 123 || $product->get_id() == 456 ) {
  return false; }
 return $bool; }
add_filter( 'woocommerce_is_purchasable', 'my_custom_product_hide_add_to_cart', 10, 2 );

In this code, we are Targeting two specific products with the IDs 123 and 456. You can add as many products as you like by adding more lines to this code. Once you have added this code, the Add to Cart button will be hidden on those specific products only.

Hiding the Add to Cart button on specific products can be useful if you want to control who has access to purchasing certain products. By using either the WooCommerce Product Visibility extension or a conditional tag in your theme’s functions.php file, you can easily achieve this.

Madison Geldart

Madison Geldart

Cloud infrastructure engineer and tech mess solver.