How To Hide or Disable Add To Cart Button In WooCommerce Store
“Add to Cart” button is present on almost every page of a WooCommerce store. However, some store owners wish to either disable or remove this button on some products to make the product unpurchasable.
Remove button on product listing page use following hooks
1 2 |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart'); |
The code above needs to be included in functions.php which is located in your theme folder.
Remove the Add to Cart Button
Here is how to remove the Add to Cart button from product pages and product listing pages (also known as shop page). I will add the following hooks to woocommerce.php (located wp-content/plugins/woocommerce):
1 2 3 4 5 |
function WpBlog() { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart'); return WooCommerce::instance(); } |
At this point, refresh any product listing or shop page. You will find that the button has been removed from the page.
Remove Add to Cart Button from Specific Product Pages
There are conditions when the store owners wish to list the product on the store but might not wish to make them available for sale. This is made possible by adding a hook: wooCCmmerce_is_purchasable. Now every time this filter detects the product id of the product that is not intended for sale, it will return false. On the frontend, the price would be visible but the Add to Cart button would be replaced by a notice, “Product cannot be purchased”. Remember to add this code to the functions.php (located in the theme folder):
1 2 3 4 |
add_filter('woocommerce_is_purchasable', 'wpblog_specific_product'); function wpblog_specific_product($purchaseable_product_wpblog, $product) { return ($product->id == specific_product_id (512) ? false : $purchaseable_product_wpblog); } |
Conclusion
In this short tutorial, I presented the solution of a common problem of WooCommerce store owners. Not everyone wants the “Add to Cart” button on every page of their store. If you need help in implementing this idea on your store, do leave a comment and I will get back to you.
Create Faster WordPress Websites!
Free eBook on WordPress Performance right in your inbox.