Add to cart button is present on almost every product or a shop page of a WooCommerce store.
How to Remove the Add to Cart Button
Here I will show you how to remove the add to cart button from product pages and shop page. I will add the following hooks to woocommerce.php that is located wp-content/plugins/woocommerce:
function wpitech() { 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(); }
You will see that the button has been removed from the page.
How to Remove Add to Cart Button from Specific Product Pages
Most of the store owners don’t want to make products available for sale and for this we add a hook: wooCCmmerce_is_purchasable. This filter detects the product id of the product that is not for sale and it will return false. On the front end, the price is showing but the product has no add to cart button as it has been replaced by a notice “Product not for sold”. Add this code to the functions.php
add_filter('woocommerce_is_purchasable', 'wpitech_specific_product'); function wpitech_specific_product($purchaseable_product_wpitech, $product) { return ($product->id == specific_product_id (512) ? false : $purchaseable_product_wpitech); }