Remove add to cart button in WooCommerce while disabling or keeping purchase functionality
remove add-to cart button woocommerce

Remove add to cart button in WooCommerce while disabling/keeping purchase functionality

The are millions of articles that showing you the “right” way of removing the add to cart button, while some of them are good, I keep seeing people asking for more specific solutions.

In this article, I will share with you all the possible ways of how to remove the add to cart button in WooCommerce while keeping/disabling the option to purchase a product.

Remove add to cart button from all pages and disabling purchase functionality

add_filter( 'woocommerce_is_purchasable', '__return_false'); // DISABLING PURCHASE FUNCTIONALITY AND REMOVING ADD TO CART BUTTON FROM NORMAL PRODUCTS
remove_action('woocommerce_single_variation', 'woocommerce_single_variation', 10); // REMOVING PRICE FROM VARIATIONS
remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20); // REMOVING ADD TO CART BUTTON FROM VARIATIONS

That is the most correct method on how to fully disable purchase functionality website wide and removing any add to cart button from any page.

Any theme, script or plugin that uses the purchase functionality of WooCommerce, directly or indirectly, will stop working.

Hide add to cart button from shop page/archive while keeping purchase functionality

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' );

Sometimes, you want to remove the add to cart button from the shop page(WooCommerce archive) while still keeping the purchase functionality on other areas of the website.

Remove add to cart button from category page while keeping purchase functionality

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' );

The same as removing the add to cart button from the shop page with a slight change to remove it from the category page instead. It is possible to use is_shop and is_product_category together, to do that, just change the if to if ( is_shop() || is_product_category() ).

If you want, you can hide the button on the specific category page(while keeping functionality)

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 from single product page while keeping purchase functionality

function react2wp_is_shop_remove_add_to_cart_button() {
   if ( is_product() ) {
      add_filter( 'woocommerce_is_purchasable', '__return_false' );
   }
}

add_action( 'wp_head', 'react2wp_is_shop_remove_add_to_cart_button' );

Removing add to cart button while still keeping purchase functionality has really rare use-cases. You would want to use this code only if you would like to allow purchases through other areas of the website(like a plugin) but not through the purchase page directly.

How to apply code fixes?

This is relatively simple; you have two options, choose one:

  1. Edit your functions.php file with your favorite FTP client adds these functions to the end of the file.
  2. Edit through the WordPress theme editor located at Appearance > Editor > functions.php and add these functions to the end of the file.

To summarize

There are many ways of removing/hiding the add to cart button with or without disabling purchase functionality, pick the one that you need or maybe merge two solutions into one(like using is_shop with is_product_category in the same function).

If you find that something is not working the way I wrote or just having trouble, leave a comment and I’ll try to reply as soon as possible.

  • Function: add_filter( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
  • Description:
    Hook a function or method to a specific filter action.
  • Args:
    • (string) $tag The name of the filter to hook the $function_to_add callback to.
    • (callable) $function_to_add The callback to be run when the filter is applied.
    • (int) $priority Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    • (int) $accepted_args The number of arguments the function accepts.
  • Return:
    • (true)
  • Function: add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
  • Description:
    Hooks a function on to a specific action.
  • Args:
    • (string) $tag The name of the action to which the $function_to_add is hooked.
    • (callable) $function_to_add The name of the function you wish to be called.
    • (int) $priority Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    • (int) $accepted_args The number of arguments the function accepts.
  • Return:
    • (true) Will always return true.
  • Function: remove_action( string $tag, callable $function_to_remove, int $priority = 10 )
  • Description:
    Removes a function from a specified action hook.
  • Args:
    • (string) $tag The action hook to which the function to be removed is hooked.
    • (callable) $function_to_remove The name of the function which should be removed.
    • (int) $priority The priority of the function.
  • Return:
    • (bool) Whether the function is removed.
  • Function: is_product
  • Description:
    Is_product - Returns true when viewing a single product.
  • Return:
    • boolean bool
  • Function: is_product_category
  • Description:
    Is_product_category - Returns true when viewing a product category.
  • Args:
    • string $term = '' (default: '') The term slug your checking for. Leave blank to return true on any.
  • Return:
    • boolean bool
  • Function: is_shop
  • Description:
    Is_shop - Returns true when viewing the product type archive (shop).
  • Return:
    • boolean bool

More about: Best WordPress web hosting 2019  

17 comments on “Remove add to cart button in WooCommerce while disabling/keeping purchase functionality”

  1. Thank you for your work on the above.

    How can I do the same for external/affiliate link on the product (But Product)?

    Instead of the end user being directed straight to the external link on the shop page I would like them to be directed to the product page before then being sent offsite.

    Thanks.

  2. Hi There, I want to be able to stop a customer making a purchase without selecting one of the addons first. There are 14 addon options and they must choose one before being able to click add to cart. At the moment they can make a purchase of a zero value product without chossing one of the 14 addon options which is not ideal. Any help or suggestions very, very gratefully received.

  3. Hi There, I want to be able to stop a customer making a purchase without selecting one of the addons first. There are 14 addon options and they must choose one before being able to click add to cart. At the moment they can make a purchase of a zero value product without choosing one of the 14 addon options which is not ideal. Any help or suggestions very, very gratefully received. And btw the workaround for hiding the zero value price you published rock! I really hope you can help or point me in the right direction.

    Thanks

  4. Hello where would I place this code at? I’ve been wanting to hide the add to cart button on my music category products on my website. Thank you for the help

    function react2wp_is_shop_remove_add_to_cart_button() {
    if ( is_product_category( ‘music’ ) ) {
    add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’ );
    }
    }

  5. Should I place the codes in “functions.php” which is located in the theme folder, OR place these hooks in woocommerce.php (found in the plugins folder)?

  6. I am having an unexpected error while removing add to cart button on my product page. I am using this tutorial for my reference code https://wpitech.com/hide-disable-add-to-cart-button-in-woocommerce-store/ . Is there any other way to hide add to cart button. This is the code that I am using to hide add to cart button on my product page

    function flav() {
    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();

  7. Thank you for the guide, I tried your code and it works, but I can’t tune it to my needs. I would like to disable “add to cart” button on ALL products within a specified category. I don’t want customer being able to purchase them, in any way and in any page.

    I tried to use “is_product_category ()” but it removes the button only on the category page and not in the single product page of that category. I also tried “is_product ()” and it removes the add to cart to all the products in my shop, no matter if I put the ID or the relative url of the product inside the ().

    So, is it possible to achieve what I am asking for? Thank you

  8. You can easily hide the Add to Cart button on the shop and product page easily by enabling and selecting the options in the plugin. On choosing both the shop page and the product page, the Add to Cart button is hidden in both the pages.

Leave a Reply

Your email address will not be published. Required fields are marked *