Search

How to Hide ‘Add to Cart’ Button in WooCommerce the RIGHT way?

Listen to this article
woocommerce-remove-buy-button

The go-to approach is to hide it is by using PHP. However, there are more than ONE way to hide/remove the ‘Add to Cart’ button in WooCommerce. It is, after all, a button, so you can hide it via CSS, JS, or PHP.

Want to learn how to hide the add to cart button in WooCommerce?

You’re at the right place.

WooCommerce has made it easier for businesses to create a unique and engaging shopping experience for their customers.

However, sometimes, there may be a need to hide the ‘Add to Cart’ button. This could be due to various reasons, such as customization preferences or specific product requirements.

In this article, I will guide you through the process of hiding the ‘Add to Cart’ button in WooCommerce the right way. By following our step-by-step instructions, you will learn how to effectively hide the button without compromising the functionality or the user experience of your online store without breaking your site.

Short on time? Let our WooCommerce experts help!

Consult for Free

How to hide add to cart button in WooCommerce – Custom Code

The simplest way to remove the ‘add to cart’ button is to remove two actions:

  • woocommerce_template_loop_add_to_cart
  • woocommerce_template_single_add_to_cart

Here’s the code for the same:

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

The reason is that the ‘Add to Cart’ button is displayed on these two actions.

This sounded perfect. It was just what I needed.

I didn’t give it another thought, so I used it. The add-to-cart button was removed from the needed WooCommerce product pages.

Now, in my coding rulebook, there’s one rule I always follow: ‘Test any changes before you proceed’. So I did, and i found out that my changes had affected another plugin on the site. 🙁

I had to investigate the reason for this. While doing so, I realized the approach I had chosen to hide the add-to-cart button was incorrect.

But luckily, I found the right solution.

How to hide add to cart button in WooCommerce – Reusing Code

More often than not, developers like you and me turn to Google, for an answer. We think the same way- “I can’t be the only one who’s faced this problem”, “Surely there are others who’ve solved this”– And you try to search for an answer, to save time.

I’m not against re-using code.

But you’ve got to investigate the code and test it well before using it.

The problem I faced was not critical. But the two lines of code which were seemingly innocent, packed some ammo I didn’t know I was unleashing.

You see, these actions (which are functions), fire additional hooks. For example, the woocommerce_template_single_add_to_cart function which resides in includes/wc-template-functions.php, contains the following piece of code:

function woocommerce_template_single_add_to_cart()
{
    global $product;
    do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
}

As you can see, it calls a method based on the product type. So, if the product type is ‘Simple’, it will call woocommerce_single_add_to_cart, which calls another template function.

So in the end removing the hook leads us to remove template files, for each WooCommerce product. And while the intention of removing the hook was to hide the add to cart button, it ended up removing a lot more than that.

Is this too overwhelming? Let our WooCommerce experts easily help you customize your site to increase ROI!

Contact Us

How to hide add to cart button – Using a simple filter

Now as mentioned, further investigation did lead me to the right answer. With a plugin like WooCommerce, the right way to remove the add-to-cart button was using a simple filter.

If you look at the code single-product/add-to-cart/simple.php, you’ll notice a simple filter:

global $product;
if ( ! $product->is_purchasable() ) {
    return;
}

Quick note by WooCommerce on what this hook is used for:

woocommerce-is-purchasable

The above code is run before any other functionality is checked. If the filter is_purchasable is set to true for the product, the ‘Add to Cart’ button is displayed, else the button is hidden.

And there lay the answer.

So, you just need to add the following:

add_filter( 'woocommerce_is_purchasable', '__return_false');

This small line of code will render the product unpurchasable and do it in a pretty simple way, and no hooks or templates will be removed, thus no incompatibility issues will creep up.

Quite often than not, we turn to Google (or Bing if you would prefer to do so), to look for an answer. But there isn’t a guarantee that the most popular answer is the right answer.

As a general guideline, always remember to do the needed research before implementing the solution.

If you need any help with WooCommerce customization or development, feel free to get in touch.

That’s all from me for now! Until next time, happy coding 🙂

Read More: How to Hide Pricing & ‘Add to Cart’ in WooCommerce without Need to Code

Varun Shanbhag

Varun Shanbhag

85 Responses

  1. Do you maybe know the snippet, so when people click ADD to cart, it doesn’t add the product to the cart?

    because i have changed the text of add to cart to CONTACT US and i have a redirection to contact page.

    The only thing is, when people are clicking on CONTACT us, it does redirect them, but add that item to the cart! 🙁

    I tried this snippet:

    /* remove add to cart class */
    add_filter(‘add_to_cart_class’, ‘woo_custom_cart_button_class’);
    function woo_custom_cart_button_class() {
    return __(‘more_info_button’, ‘woocommerce’);
    }

    Unfortunate that didn’t work, i guess that is only for old WC versions.

    Thank you and have a nice day

    1. Hi Alex,

      Instead of the code you’re using, you could try removing the add to cart button using the ‘woocommerce_is_purchasable’ filter.

      add_filter( 'woocommerce_is_purchasable', false );
      

      You would then have to display a different button which will redirect users to the Contact page. You could refer to this article: Reorder Content on WooCommerce Single Product Page to display a button instead of the Add to Cart button.

      Or, you could simply use a inquiry plugin like Product Enquiry Pro! Which adds a contact form pop-up and has the functionality to hide the Add to Cart button inbuilt 😀

  2. Hey! Nice article! Thanks for sharing your knowledge.
    I’m trying but was not able to make it work on my site.
    I want to remove the add to cart button if the user already bought the product.

    Here is my code:

    add_action(‘woocommerce_after_shop_loop_item’,’replace_add_to_cart’);
    add_action(‘woocommerce_single_product_summary’,’replace_add_to_cart’);
    add_action(‘woocommerce_checkout_update_order_review’,’replace_add_to_cart’);
    function replace_add_to_cart() {
    global $product;
    $current_user = wp_get_current_user();
    if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->id )) {
    //remove_loop_button();
    add_filter( ‘is_purchasable’, false );
    }
    }

    function remove_loop_button(){
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );
    remove_action( ‘woocommerce_checkout_update_order_review’, ‘woocommerce_checkout_payment’);
    }

    As you can see, I’m not calling the remove_loop_button anymore, just the filter you show us, But I’m not able to make it work. Am I using it in a wrong way?

    Thanks e congratz for your excellent site!

    1. The filter that has to be used is ‘woocommerce_is_purchasable’ instead of ‘is_purchasable’.
      You might need to give priority to the add action to give it a higher priority than woocommerce itself.
      add_action( ‘woocommerce_single_product_summary’, ‘replace_add_to_cart’ ,30);

      This is to ensure that your code runs before the add to cart button is added to the page. The priority(30) given might matter, it should be greater than default(10) for WooCommerce.

      1. Hi! Thanks for you help.
        Now it removes the button, but shows me an warning:

        Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /srv/…/wp-includes/plugin.php on line 235

        Seems that a function is expected on add_filter( ‘is_purchasable’, false );

        What do you think?

        Thanks!

        1. Hi Jojo,
          I hope you have changed the add_filter from ‘is_purchasable’ to ‘woocommerce_is_purchasable’.
          Please use only add_action(‘woocommerce_single_product_summary’,’replace_add_to_cart’); add action.
          Remove the other two add action which call the same method: replace_add_to_cart.

          The error being thrown is caused when a method is being called but doesn’t exist. Could you please post the entire error so that I can find out which method call failed.

          1. Hello there.

            So. This is my code now:

            add_action(‘woocommerce_single_product_summary’,’replace_add_to_cart’);
            function replace_add_to_cart() {
            global $product;
            $current_user = wp_get_current_user();
            if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->id )) {
            add_filter( ‘woocommerce_is_purchasable’, false);
            }
            }

            And this is the error message I got on my product page:

            Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /srv/www/mysite.dev/htdocs/wp-includes/plugin.php on line 235

            Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /srv/www/mysite.dev/htdocs/wp-includes/plugin.php on line 235

            Same message two times. Also, the add to cart button has gone. this is expected as the user had already bought the item.
            If I comment the line // add_filter( ‘woocommerce_is_purchasable’, false); the error message isn’t displayed anymore.

            Maybe we need some function on the add_filter like add_filter( ‘woocommerce_is_purchasable’, ‘FUNCTIONHERE’, false); or I’m wrong?

            Thanks for your attention!!

          2. Hey JoJo,
            You can try the below code:

            add_action( 'woocommerce_single_product_summary','replace_add_to_cart', 30 );
            function replace_add_to_cart() {
                global $product;
                $current_user = wp_get_current_user();
                if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->id )) {
                  add_filter( 'woocommerce_is_purchasable', 'hide_add_cart');
                }
            }
            
            function hide_add_cart() {
                return false;
            }
            

            The errors you are facing are because there is a method being called in line 235 of the plugin.php, but that method doesn’t exist.
            If the error is not resolved, you will have to look into this file to find which method is being called and then debug that.

          3. Hi Varun,
            great post!
            I just have a question: as Jojo I’ve got, instead of ‘add to cart’, the message ‘Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /web/htdocs/www.xxxxxx.com/wp-includes/plugin.php on line 235’

            Plugin.php function is:
            if ( !isset( $merged_filters[ $tag ] ) ) {
            ksort($wp_filter[$tag]);
            $merged_filters[ $tag ] = true;
            }

            reset( $wp_filter[ $tag ] );

            if ( empty($args) )
            $args = func_get_args();

            do {
            foreach ( (array) current($wp_filter[$tag]) as $the_ )
            if ( !is_null($the_[‘function’]) ){
            $args[1] = $value;
            $value = call_user_func_array($the_[‘function’], array_slice($args, 1, (int) $the_[‘accepted_args’]));
            }

            } while ( next($wp_filter[$tag]) !== false );

            array_pop( $wp_current_filter );

            return $value;
            }

            This is line 235: $value = call_user_func_array($the_[‘function’], array_slice($args, 1, (int) $the_[‘accepted_args’]));

            Could you help me?
            Thanks a lot and great work!
            Ariel

    1. Hi Tim,
      You would need to check the product category before setting the ‘woocommerce_is_purchasable’ filter to false. You can do this using the below code:

      global $post; 
      $terms = get_the_terms( $post->ID, 'product_cat' );
      foreach ($terms as $term) { 
         $product_cat_id = $term->term_id; 
         // check if $product_cat_id is the category id for which you want to hide the button, then set the filter
      }
      
  3. Thank you so much! This is working for me. Most of my products I just want to show the price and product description, but I do have a couple products that are purchasable. How do I do that? I am looking for some sort of box or something on the product page to mark it as purchasable… but that doesn’t seem to be right. Is there something I have to put in functions.php for those specific items that I want the button to display for?

    1. Amy,

      What you can do is add these products under a special category, and display the add to cart button only for if the product belongs to that particular category.

  4. Thanks for sharing, this works very well.

    Is there a way of hiding the button when the product is still purchasable? I want to use a product designer plugin (woocommerce product designer) that adds a ‘design from blank’ button under the add to cart. I want my customers to use the add to cart button within the designer page rather than the product page:

    http://custom-print-canvas.co.uk/product/20x20cm_8x8/

    1. Dan,

      If I understand your requirement correctly, you’ll need to use the filter to hide the ‘Add to Cart’ button from all product pages. You can then use the Add to Cart shortcode by WooCommerce to display the button on the designer page, and set the filter to true here. (But won’t the product designer plugin add this button anyway?)

      Hope this helps!

      1. I was hoping to eventually add products that didn’t use the designer plugin, so I need to be able to hide the add to cart button on selected product pages whilst ensuring all products are purchasable. The plugin already uses some means of showing the button

  5. Is it possible to add a “Contact Us” button instead of Add to cart button which will redirect to contact us page.if possible then how? thanks.

    1. Hey Benjamin,

      You could remove the ‘Add to Cart’ button using the code mentioned in the article. To show a ‘Contact Us’ button in place of the ‘Add to Cart’ button you would need to add a custom function on the ‘woocommerce_single_product_summary’ hook.

  6. Thanks for sharing. worked like a charm. The best way to hide, “add to cart button” without affecting other plugins (eg :- woocommerce product slider). Thanks again.

  7. Hi !
    I am understand your solutioon, but I use the plugin “Booking system pro” for renting a product. Now my customer cannot purchase the product via my renting plugin. The error code: sorry, purchasing is not possible. Do you have an idea?
    bye, Thomas

  8. This doesn’t work! I added the

    add_filter( ‘woocommerce_is_purchasable’, false );
    code

    to the simple.php page, and the “Add to Table” button is still on my woocommerce pages!

    1. Use `add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’ );`

      Second argument should be function name, not a bool value.

  9. Hi I have been researching a lot of how to remove the add to cart button and I tried your code add_filter( ‘woocommerce_is_purchasable’, false ); but for me it does not remove the button but simply does not let the user add to cart by saying that the combination is unavailable. What other code could I use?
    I tired the 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 ); but that removes the button but also removes my product photo.

    1. Hi Kris,

      The filter should have worked for you. What might be happening is that another plugin might be overriding the filter with its own value. Could you try adding a priority when specifying the filter?

      For example, add_filter( ‘woocommerce_is_purchasable’, false, 99, 2 );

      1. I tried clicking the reply on my question but it was not working. However, I used add_filter( ‘woocommerce_is_purchasable’, false, 99, 2 ); but nothing has changed. It does not seem to have affected my add to cart button period.

  10. hi – is there a way of removing the add to cart button on the single product page view BUT keep it as purchasable…. I’m using the mix n match extension and watch the single product page view to tell my customers more about the product – but the product may only be bought as part of a set (in a bigger mix n match product)
    Could I adapt the simple product add to cart php in some way?

  11. This code made the product purchasable but the post was title how to hide the add to cart button. This is the right answer if you want to shade out the add to cart button on the whole site but does not hide the add the cart button…unless i did it wrong

  12. I just added given code “add_filter ( ‘woocommerce_is_purchasable’, false )” at bottom of functions.php from admin dashboard (Appearance/Editor/Functions.php) It is hiding all ‘add to cart’ button now can’t see anywhere. 🙂 Great job. keep it on.

  13. For a selective ‘is_purchasable’ add this code in functions.php in a child theme

    add_filter(‘woocommerce_is_purchasable’, ‘my_woocommerce_is_purchasable’, 10, 2);
    function my_woocommerce_is_purchasable($is_purchasable, $product) {
    return ($product->id == whatever_mambo_jambo_id_you_want ? false : $is_purchasable);
    }

    1. Hi xcolo

      Thanks for your code. I’ve modified it to fits my needs. This is my code in case somebody is in need:
      add_filter(‘woocommerce_is_purchasable’, ‘my_woocommerce_is_purchasable’, 10, 2);
      function my_woocommerce_is_purchasable($is_purchasable, $product)
      {
      if (in_array( 510, $product->category_ids)) {
      return false;
      }else {
      return $is_purchasable;
      }
      }

  14. Hello,

    i add code:
    add_filter( ‘woocommerce_is_purchasable’, false );

    in to functions.php file on child theme. But nothing happend. Using enfold child theme. Where is the problem.
    Ludek.

  15. Any way to use this but keep other things like wishlist? I’m using the woocommerce wishlist plugin and it works fine, but when I add this filter it removes everything. Add to cart and wishlist button. Any ideas? I’m assuming because the wishlist function is intertwined with the is_purchasable hook or something.

    1. I really would like an answer on this question too! The hook does work properly if you want to remove all add to chart buttons, but I only would like to remove the add to chart button on the category page and not on the single page. Is there a solution?

    2. I’m also looking for a way to hide Add to Cart and the price, but still keep the Add to Wishlist button. Thank you.

  16. In functions.php (if you have a child theme, in functions.php of the child theme) do this:

    add_filter( ‘woocommerce_is_purchasable’, function() { return false; } )

    Working for Woocommerce 2.6.14

  17. Please use this (add this in functions.php)
    /*STEP 1 – REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */
    function remove_loop_button(){
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );
    }
    add_action(‘init’,’remove_loop_button’);

    /*STEP 2 -ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */
    add_action(‘woocommerce_after_shop_loop_item’,’replace_add_to_cart’);
    function replace_add_to_cart() {
    global $product;
    $link = $product->get_permalink();
    echo ‘<a href=”‘.esc_attr($link).'” rel=”nofollow”>SHOP NOW </a>’;
    }

  18. I think the best way is add the code in child theme or insert separate file in functions.php and insert code in it.

  19. WordPress expects a function in this filter.. I had issues with my website breaking because of this. Thankfully, WordPress has a ‘return false’ function built in which you can use.

    Use the following:

    add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’);

    1. This is a key improvement on the original solution (which was GREAT) to begin with. add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’); is the answer! Thank you Chris & Varun.

  20. add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’); this code is which page….

  21. Hi,
    I use woocommerce 2.6.14 but no code on this site works. I always get Errors insted of hidden button. Please can anybody help me ?

    I need to change the “add to cart button” on the single product page to a if my global variable $wp_session [‘breadclum’] is empty.
    If it is not emty, then the normal “add to cart button” should be on the page.

    1. Sorry, I forgot to insert my code

      add_filter(‘woocommerce_is_purchasable’, ‘my_woocommerce_is_purchasable’, 10, 2);
      function my_woocommerce_is_purchasable($is_purchasable, $product) {
      global $wp_session;
      return (empty( $wp_session[‘breadclum’]) == true ? false : $is_purchasable);
      }

      This make the “add to cart” button not purchasable on single product page but I do not know how I can insert a user definied button with link to a page instead on this place.
      Hope anybody can help me.

  22. For any shop page you can remove add to cart button through adding following hooks to woocommerce.php (located wp-content/plugins/woocommerce)

    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();
    }
    After refreshing you can see that the button has been removed from the page.

  23. Is there away to have this work if more than x amount of items with the same tag are added to the cart it would then not let you add anymore of those items to the cart.

  24. Hi. First, thank you so much for taking the time to write this. It is pretty awesome. With that said, can you please help me? I read all comments but nothing as worked for me.

    I added: add_filter( ‘woocommerce_is_purchasable’, false ); to functions.php

    The button is gone, but I get this in the front:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /home4/centp002/public_html/amzaver/wp-includes/class-wp-hook.php on line 288

    Thank you for your time and your help.

  25. Hello,
    I am wondering if you all can help. I am looking to create a second version of my retail shop that is only a catalog for wholesalers without a price or ability to buy.

    I want to remove the price and add to cart button functions only at a certain URL extension like http://www.mysite.com/wholesale.

    Thanks

  26. Would this work to remove add to cart and price for products that fall under a certain URL extension? Like http://www.mysite.com/wholesale

    $(function(){
    if (“url:contains(‘wholesale’)”) {
    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();
    }
    }

  27. Hi,

    You cannot pass the boolean FALSE to add_filter(), as it is not a valid callback function. So I think you mean for your code snippet to be:

    add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’ );

  28. Hi,

    can I make this filter work for specific users (say product p is hidden for user A but not for user B)?

  29. thank you for your post,

    I got the add to cart button in the variation products, so I copied and pasted the flowing code to the function.php in the child page,

    add_action( ‘woocommerce_single_product_summary’,’replace_add_to_cart’, 30 );
    function replace_add_to_cart() {
    global $product;
    $current_user = wp_get_current_user();
    if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->id )) {
    add_filter( ‘woocommerce_is_purchasable’, ‘hide_add_cart’);
    }
    }

    function hide_add_cart() {
    return false;
    }

    But it still not work, where did I do wrong?

  30. Interesting, but i am newbie working on WooCommerce product with Gravity Forms. In a product we have a multi-page form where we provided save and continue later link. This functionality is added to comeback and finish the form later at the user’s convenience.

    Everything works fine, except but when someone saves the form, i want to hide the Submit | Add to Cart button removed or hidden with jQuery or custom function.

    This is the page i need to help with: https://www.licensedagents.com.au/product/product-amarnath/#_form_38

    Is there a similar function or snippet or a jQuery script i can use of to hide that button?
    Thanks in advance.
    Amarnath

  31. For variations, the Add to Cart button is still there but ofc. the product cannot to bought. For simple products, the button is gone. Any idea how to “remove” it for variable products too?

  32. Hi,
    Great Content. I appreciate the way you describe. I would like to hear more from you.
    Thanks

  33. 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. 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();

  34. Hi,
    is there someone there who can help me?
    I added this code in the theme functions.php

    if (!function_exists(‘woocommerce_template_loop_add_to_cart’)) {
    function woocommerce_template_loop_add_to_cart() {
    global $product;
    if ( ! $product->is_in_stock() || ! $product->is_purchasable() ) return;
    woocommerce_get_template(‘loop/add-to-cart.php’);
    }
    }
    so my out of stock products will hide the add to basket button,
    and this works well
    but I want to replace it, after the product is out of stock, the buttons added to the cart are hidden and replaced with special texts, for example “expired”
    How to do it
    Thank you very much

  35. Where would I put the string mentioned,
    add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’);
    to specify a certain product or better yet category?

    1. Let me explain this line of code to you:

      add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’);

      Here, __return_false is a quick built-in function provided by WordPress to return a false statement.

      Which is equivalent to,

      add_filter( ‘woocommerce_is_purchasable’, ‘hide_add_to_cart_function’);

      function hide_add_to_cart_function() {
      return false;
      }

      So basically __return_false is used as a callback function hooked with that filter.

      This filter passes a product object with it so you can write your code like this.

      add_filter( ‘woocommerce_is_purchasable’, ‘hide_add_to_cart_function’, 10, 2 );

      function hide_add_to_cart_function( $return_value, $product ) {

      // For example, you want to filter ‘add to cart’ button for all the simple products.
      if ( $product->is_type( ‘simple’ ) ) {
      return false;
      }

      return $return_value;
      }

      This will hide add to cart button for all simple product type.
      The product object can help you filter your specific product.

      For a specific category, this is the way.
      add_action( ‘woocommerce_is_purchasable’, ‘hide_add_to_cart_function’, 10, 2 );

      function hide_add_to_cart_function( $return_value, $product )
      {
      // For example, you want to filter out add to cart button for all the products with category accessories.
      if ( has_term( ‘accessories’, ‘product_cat’ ) ) {
      return false;
      }

      return $return_value;
      }

      You can add this code in a custom plugin or a child themes function.php file.

  36. It just makes the item un-purchasable, but still displays the “Add to Cart” button.

  37. Hi, is there a way I can hide the add to cart button from the main page but not in quick-view popup window?

  38. Can anyone tell me how to add ‘Add to cart’ button to the affiliate product page which already has ‘Buy Now’ button linked with the affiliate site link?

  39. Query : I want to hide ” add to Cart button ” for
    guest users all over the website and for
    all products.

    Theme : Adiva

    Plugin : woocommerce

    I have researched a lot but there is no suitable plugin for this and I couldn’t find answer on changing the php code. Again please note that I want to hide ” add to cart button ” for any user who is not logged in. And it should be for all the products on the website not for a single product or group of products !

    1. This should work (just add it to your functions.php in your template directory):

      function hideAddtoCartforGuest () {
      if (!is_user_logged_in()) {
      // Add the filter if the user is not logged in
      add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’);
      }
      else {
      //do nothing if the user is logged in
      }
      }
      hideAddtoCartforGuest();

  40. Howdy Varun – I’m so glad I stumbled across your page doing a google search – I have been searching for days for a potential answer and I think I might finally be on the right track.

    I am trying to hide the add to cart button when the cart value is less than $150 and I cannot for the life of me figure out the best way to do this, but I think your tutorial above might lend some ideas to this.

    Could you possibly point me in the right direction please?

    Cheers,
    Phil.

  41. Thanks a lot for this. I was wondering if it is possible to apply this to variable good? This approach works well for the simple goods. However, for the variable goods the button is still there but it says that the good cannot be purchased?

  42. Thank you for this insightful article. Solve me one issue without adding another plugin. I used this code insert on or testbed and worked fine. We use an applointment system that creates appointments as products in woocommerce and wanted to remove ‘add to basket” since it breaks the workflow. Worked great and I’m grateful.

Leave a Reply

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

Get The Latest Updates

Subscribe to our Newsletter

A key to unlock the world of open-source. We promise not to spam your inbox.

Suggested Reads

WordPress Development

Custom WordPress Solutions, for You

LearnDash Development

Custom LearnDash Solutions, for You

WooCommerce Development

Custom WooCommerce Solutions, for You

WordPress Plugins

Scale your WordPress Business

WooCommerce Plugins

Scale your WooCommerce Business

LearnDash Plugins

Scale your LearnDash Business

Label

Title

Subtext

Label

Title

Subtext

Join our 55,000+ Subscribers

    The Wisdm Digest delivers all the latest news, and resources from the world of open-source businesses to your inbox.

    Suggested Reads

    WordPress Tips & Tricks
    Ketan Vyawahare

    How to Make Responsive Tables using CSS without Tag Read More »