Customizing the purchase page of the WooCommerce plugin increases the user experience on your website. Often, you are required to remove add to cart button in WooCommerce for a few products. For example, if the item you are selling is out of order.
WooCommerce is one of the most useful plugins in WordPress. By installing this plugin you can simply convert a simple WordPress website into a professional online store and use its features. Before making any changes to the WooCommerce configuration, we highly recommend getting a backup of your website.
In this article, we would like to discuss how to remove add to cart buttons in WooCommerce.
How to Remove Add to Cart Button in WooCommerce Site-Wide?
Once you have completed the configuration and adding a product process, products will be displayed on the website with the default settings on the website.
As you can probably see, the add to cart button is placed right next to the product.
To remove this button, simply add the following code anywhere on the functions.php file. In some cases this code could break the functions.php file. Thus, it’s better to put in the woocommerce.php file.
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', 30 );
To access the file, enter your WordPress directory. From the wp-content folder go to plugins. Then choose either functions.php or woocommerce.php file.
To remove add to cart button in WooCommerce use the first code and to remove the price tag using the second code.
By using these commands, you can remove add to cart button in WooCommerce for the entire website.
Remove Add to Cart Button from Homepage and Archive Pages
The code we mentioned above removes add to cart button in WooCommerce for the entire website. If you would like to disable or remove the add to cart button from the homepage or archive pages, use the following code in either functions.php or woocommerce.php files:
function react2wp_is_shop_remove_add_to_cart_button() {
if ( is_shop() ) {
add_filter( 'woocommerce_is_purchasable', '__return_false' );
}
}
add_action( 'wp_head', 'react2wp_is_shop_remove_add_to_cart_button' );
Remove Add to Cart Button from Category
If you would to remove add to cart button from the category page and still keep it for other pages of your website, use the following code in either file:
function react2wp_is_shop_remove_add_to_cart_button() {
if ( is_product_category() ) {
add_filter( 'woocommerce_is_purchasable', '__return_false' );
}
}
add_action( 'wp_head', 'react2wp_is_shop_remove_add_to_cart_button' );
Remove Add to Cart Button from a Specific Category Page
By using the following code, you can hide the add to cart button from a specific category page in WordPress, but the add to cart button is still activated in other pages:
function react2wp_is_shop_remove_add_to_cart_button() {
if ( is_product_category( 'category_slug' ) ) {
add_filter( 'woocommerce_is_purchasable', '__return_false' );
}
}
add_action( 'wp_head', 'react2wp_is_shop_remove_add_to_cart_button' );
Remove Add to Cart Button in WooCommerce for A Specific Product
Often you may need to disable the add to cart button for a specific product in WooCommerce. There are multiple methods to achieve this.
1. The first and easiest method is to disable the add to cart button for that product. Keep in mind, by disabling this function, users won’t be able to purchase it.
2. The second method is to change the quantity of the product in question. By changing the quantity to 0, the ability to purchase will be disabled.
3. The last method is to add a filter. This filter identifies the product ID and disables the add to cart button for that item. By adding the following code to the functions.php file in your themes folder you can add this filter to WordPress.
add_filter('woocommerce_is_purchasable', 'woocommerce_cloudways_purchasable');
function woocommerce_cloudways_purchasable($cloudways_purchasable, $product) {
return ($product->id == your_specific_product_id (like 22) ? false : $cloudways_purchasable);
}
Conclusion
As we mentioned above, there are multiple methods to remove add to cart button in WooCommerce and you can choose whichever you need. The mentioned methods above can be used for all themes in WordPress.
Keep in mind, before making any changes to the website make sure you get a full backup in case anything goes wrong so you can restore the website back to its original state.