Search

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

    Varun Shanbhag
Listen to this article
Hide Add to Cart
WooCommerce hide add to cart 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.

Have you ever needed to temporarily or permanently remove the Add to Cart button in WooCommerce? Whether it’s for customizing your store’s functionality, managing out-of-stock products, or requiring customers to contact you before purchasing, knowing how to hide the Add to Cart button can be incredibly useful.

WooCommerce is fantastic for creating engaging shopping experiences, but sometimes you need a bit more control over how your products are presented. Maybe you’re showcasing a product that’s not for direct sale, or you want to provide more information before a purchase is made.

In this article, I’ll show you the right way to hide the Add to Cart button in WooCommerce. We’ll go through step-by-step instructions to ensure you can do this without breaking your site or impacting the user experience.

If you run into any challenges or need customized solutions, don’t worry. Our WooCommerce experts are ready to help you out. Just reach out, and we’ll support you in optimizing your online store.

How Does Hiding the Add to Cart Button in WooCommerce Help?

Hiding the “Add to Cart” button in WooCommerce can really change how your store works and how customers interact with it. Here’s how:

  • Better Customer Experience: For high-value or customizable products, removing the button encourages customers to contact you for more information, leading to personalized interactions and better decision-making.
  • Inventory Management: If an item is out of stock, hiding the button makes it clear it’s unavailable, preventing customer frustration.
  • Cleaner Store Layout: Sometimes you have products just for display or promotions. Hiding the button keeps your site looking clean and professional, without confusing customers about what’s for sale.

Difference Between Hiding and Removing the Add to Cart Button

When it comes to managing your WooCommerce store, knowing whether to hide or remove the Add to Cart button can make a big difference.

Hiding the WooCommerce Add to Cart Button: Hiding the button means it’s still there on the product page, but customers can’t see it. It’s like putting a temporary cover over it. This is great for situations where you might want to make the product available again later, like if it’s out of stock or you’re doing some updates. The product page still shows all the details, but customers just can’t add it to their cart right now.

Removing the Add to Cart Button WooCommerce: Removing the button, on the other hand, means it’s completely gone from the product page. This is more of a permanent move and might need some extra work if you ever want to bring the button back. This option is good for products you never want to sell online, like discontinued items or those that require an in-person purchase.

How to hide add to cart button in WooCommerce

If you’re looking to hide the “Add to Cart” button in WooCommerce, there are a few different methods you can use. Here’s a brief overview:

  1. Using WooCommerce’s Default Settings: WooCommerce automatically hides the “Add to Cart” button for out-of-stock products. You just need to enable inventory management in the settings.
  2. Custom Code in functions.php: You can add custom code to your theme’s functions.php file to remove the “Add to Cart” button from product and shop pages.
  3. Using Filters: A simple and effective way is to use WooCommerce filters to control the visibility of the “Add to Cart” button based on product conditions.
  4. Plugins: There are several WooCommerce plugins available that allow you to hide the “Add to Cart” button easily without touching any code.

Now, let’s focus on the most effective method using a simple filter.

How to Hide the Add to Cart Button in WooCommerce – Using a Simple Filter

To hide the “Add to Cart” button efficiently, we can use a simple filter in WooCommerce. This method ensures that you don’t interfere with other functionalities or plugins. Here’s how you can do it:

Add the Filter in functions.php: Add the following code to your theme’s functions.php file. This code will make the product unpurchasable, thereby hiding the “Add to Cart” button for simple products and disabling the button for variable products.
php
Copy code

//This is to remove add-to-cart button from simple product page
add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’ );

Hide Add to Cart Button WooCommerce for Simple Product

Hide add to cart simple product
Before Adding Code
Hide add to cart simple product after 1
After Adding Code

//This is to remove add-to-cart button from variable product page

remove_action( ‘woocommerce_single_variation’, ‘woocommerce_single_variation_add_to_cart_button’, 20 );

WooCommerce Hide Add to Cart Button for Variable Product

Hide add to cart variable product
Before Adding Code
Hide add to cart variable product after
After Adding Code

This small snippet of code effectively hides the “Add to Cart” button without causing compatibility issues with other plugins or WooCommerce updates. For simple products, the button will be removed entirely, while for variable products, the button will be disabled.

Common Mistakes to Avoid

Initially, you might think of removing actions directly to hide the “Add to Cart” button. Here’s why that might not be the best approach:

Direct Action Removal:
php
Copy code
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);

  • This method can seem straightforward, but it often leads to issues because these actions are tied to other functionalities within WooCommerce. Removing them might break other parts of your site or interfere with other plugins.

The filter method is cleaner and ensures compatibility. By simply returning false for the purchasable condition, you avoid deeper issues with WooCommerce’s hook system and maintain the integrity of your site’s functionality.

Using Plugins to Hide the Add to Cart Button in WooCommerce

If coding isn’t your thing or you want an easier solution, there are several WooCommerce plugins available that can hide the “Add to Cart” button without any hassle. Here are a few reliable options:

  1. YITH WooCommerce Catalog Mode: This plugin allows you to transform your WooCommerce store into a catalog by hiding the “Add to Cart” button for all or specific products. It also offers other features like disabling reviews and prices for a streamlined catalog experience.
  2. WooCommerce Product Catalog: This plugin helps you hide the “Add to Cart” button, prices, and more. You can apply these changes to specific products, categories, or the entire store.
  3. Disable Add to Cart Button: A straightforward plugin that hides the “Add to Cart” button globally or on specific product pages. It’s easy to use and doesn’t require any coding skills.

These plugins provide a simple, user-friendly way to customize your WooCommerce store without plunging into code. They ensure your site looks clean and professional while preventing customers from purchasing certain products.

Using WooCommerce’s Default Settings to Hide The “Add to Cart” Button

WooCommerce automatically hides the “Add to Cart” button for out-of-stock products. To take advantage of this feature, you just need to enable inventory management in your settings. Here’s how:

  1. Enable Inventory Management:
    • Go to your WordPress dashboard.
    • Navigate to WooCommerce > Settings > Products > Inventory.
    • Check the “Manage stock” option.
  2. Set Product Inventory:
    • Go to the product page in your WooCommerce dashboard.
    • Scroll down to the “Product Data” section.
    • Click on the “Inventory” tab.
    • Enable “Manage stock” and set the stock quantity.

When a product’s stock reaches zero, WooCommerce will automatically hide the “Add to Cart” button, making it clear to customers that the product is out of stock. This feature helps you manage inventory efficiently and improves the customer experience by preventing them from trying to purchase unavailable items.

When you hide or remove the “Add to Cart” button in WooCommerce, you might encounter a few common issues:

  • Plugin Conflicts: Some plugins rely on the “Add to Cart” functionality, and hiding the button can cause conflicts. Always test changes in a staging environment first.
  • Theme Compatibility: Not all themes handle this change the same way. Custom templates might override WooCommerce behavior, so ensure your theme is compatible and test thoroughly.
  • User Experience: Hiding the button can confuse customers if they don’t understand why they can’t purchase a product. Provide clear information on the product page, such as indicating the item is out of stock or requires contact for purchase.
  • Persistent Cache: Changes might not appear immediately due to caching. Clear your site and browser cache after making updates to see the changes in real-time.

Being aware of these potential issues can help you implement the changes smoothly. If you encounter problems, our WooCommerce experts are here to assist.

Hiding or removing the Add to Cart button in WooCommerce can be a useful tool for managing your online store. 

Quite often than not, we turn to Google (or Bing if you prefer) 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. This will help you avoid common issues and ensure a smoother implementation process.

If you face any challenges or need assistance with WooCommerce customization, our experts are here to help. Don’t hesitate to reach out for support. We’re ready to provide you with the solutions you need to optimize your online store.

Use the woocommerce_is_purchasable filter to check specific product IDs and conditionally hide the button, or use a plugin for a user-friendly solution.

Yes, use the woocommerce_is_purchasable filter set to false for out-of-stock products to hide the button.

Yes, add custom code to your theme’s functions.php file using the woocommerce_is_purchasable filter to hide the button for specific user roles.

Popular plugins include WooCommerce Catalog Mode, YITH WooCommerce Catalog Mode, and WooCommerce Product Catalog for easy customization.

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:

    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

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