WooCommerce Remove ‘Add to Cart’ Button – Categories, Product ID’s, Shop Page, Product Page

There are different ways to hide the Add to Cart button, but the various ways are spread out all over the internet. I wanted to consolidate my favorite ways to hide the button in one post for easy access.

Also, I found only the below snippets work. There’s a simpler and more popular “remove” bit of code that doesn’t work for everyone and I don’t know why, yet, but it could be conflict with the site’s template. Regardless, the below code worked for me regardless of template.

Every example below requires you copy and paste the code directly into the woocommerce.php file via FTP located at:

wp-content > plugins > woocommerce > woocommerce.php

Just find your woocommerce.php file and in the space just above // Global for backwards compatibility enter the snippets there.

Also, always make a backup of your site and make sure you have a clean, original, unaltered version of you woocommerce.php file to drop into the folder via FTP in case you play with the code and produce an error and need to start over. For instance, you could save the original on your desktop and the altered version in a folder titled “altered PHP files.”

1) Hide “Add to Cart” on Shop and Category Pages – NOT the product page:

Find your woocommerce.php file and in the space just above // Global for backwards compatibility enter:

  add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );

    function remove_add_to_cart_buttons() {
      if( is_product_category() || is_shop()) { 
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
      }
    }

This will just hide the “Add to Cart” on Shop Pages and Category Pages, but leave it visible on the actual Product Page.

2) Hide “Add to Cart” Button by Product ID:

add_filter( 'woocommerce_is_purchasable', 'woocommerce_hide_add_to_cart_button', 10, 2 );
function woocommerce_hide_add_to_cart_button( $is_purchasable = true, $product ) {
    return ( $product->get_id() == 335 ? false : $is_purchasable );
}

Just replace 335 with your product’s ID. This will hide the “Add to Cart” everywhere and replace the text with “Read More” on Shop and Category Pages.

3) Hide “Add to Cart” Button by Product Category on Shop Page, Category Page and Product Page:

You will add this under the code from 1) Hide “Add to Cart” on Shop and Category Pages – NOT the product page and change “yourcategory” to the category on your site.

function remove_product_description_add_cart_button(){
    global $product;

    // Replace yourcategory with the category from your site 
    $category = 'yourcategory';
  
    if ( has_term( $category, 'product_cat', $product->id ) )
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

}
add_action('wp','remove_product_description_add_cart_button');

4) Replace “Add to Cart” Text and Redirect to Specific URL:

And last but not least, let’s say you want to hide the ‘Add to Cart’ button on the Shop and Category Pages and replace the text on the Product Page and also redirect the URL. Copy and paste the code above from 1) Hide “Add to Cart” on Shop and Category Pages – NOT the product page and then add:

// Change 'add to cart' text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'bryce_add_to_cart_text' );
function bryce_add_to_cart_text() {
        return __( 'Contact Us' );
}
/**
 * Redirect users after add to cart.
 */
function my_custom_add_to_cart_redirect( $url ) {
	$url = get_permalink( 13 ); // URL to redirect to (1 is the page ID here)
	return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );

Replace “Contact Us” with your text, and replace the number “13” with your page ID. You can find it by going to Posts > Edit > the page ID is the number located in the URL in your browser in edit mode.

You may also like...

Leave a Reply