19

I know this question might be too broad, but I'm looking for a bit of direction. My client has a woocommerce store with 30-40 products. For whatever reason they do not want to sell online anymore, but they want to retain the product pages, information, etc. on their website.

Is there a way, using hooks or otherwise, to hide things like prices, add to cart button, etc. in woocommerce? Or should I just edit the php template files?

1
  • WooCommerce and other 3rd party plugin/theme dev support is off topic and not in this stacks scope. You should ask via their official support routes or in their groups and communities. This question is here for historical reasons
    – Tom J Nowell
    Commented Sep 30, 2021 at 11:56

3 Answers 3

23

luckily woocommerce has many hooks, this removes prices and buttons:

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );

you can dig into content-product.php and content-single-product.php if you need to remove more stuff.

I can imagine there's more than just the prices/buttons you want to hide/remove though (like pages/functions), this tutorial gives you some pointers

3
  • Am I right in thinking those hooks have to be inserted into functions.php? If so, is there a particular section I need to put them in to? If they work, presumably the cart functionality will no longer be visible, aside from some styling, is that right?
    – James
    Commented Dec 1, 2013 at 14:41
  • 1
    yes, you can put them in functions.php and it doesn't matter where you put them within another function. Usually all the way at the end of the file is the safest, as long as you don't put them after the last ?>. This will not remove the cart page, but it will actually remove the possibility of adding anything to the cart. If you don't like the cart page anywhere you should be relatively safe.
    – Ewout
    Commented Dec 5, 2013 at 9:10
  • It works. But this is strange. After applying this, the product images stopped from appear. It shows an empty space for theirs location, and when i pass the mouse over them and click them they show me the proper image. Do you have an idea on why is that happening?
    – Brethlosze
    Commented Aug 2, 2016 at 17:08
13

Extending the above code (thanks Ewout), the following code will get rid of all prices and 'add to cart' buttons on all woocommerce products, as well as provide an explanation as to why. I needed the code for a website that offers direct selling products and to comply with their rules, I cannot show prices to the general public.

Add the filter to your theme's functions.php file.

    add_filter('woocommerce_get_price_html','members_only_price');

    function members_only_price($price){

if(is_user_logged_in() ){
    return $price;
}

else {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    return 'Only <a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Registered Users</a> are able to view pricing.';
      }

}
2
  • This is strange. After applying this, the product images stopped from appear. It shows an empty space for theirs location, and when i pass the mouse over them and click them they show me the proper image. Do you have an idea on why is that happening?
    – Brethlosze
    Commented Aug 2, 2016 at 17:08
  • This code does not work in WooCommerce v3.2.1 :-)
    – Steve
    Commented Oct 19, 2017 at 2:44
1
add_filter( 'woocommerce_is_purchasable', '__return_false' );
add_filter( 'woocommerce_get_price_html', '__return_empty_string' );

This will totally prevent checkout and hide all prices by:

  • Making all product non-purchasable (line 1)
  • Emptying price HTML (line 2)

Not the answer you're looking for? Browse other questions tagged or ask your own question.