There are many plugins that allow you to setup special accounts for your wholesalers for example. Often times the user role feature of WordPress is used to identify users within a specific group. In this post I’ll show some examples of how you can display/hide prices for specific user groups, including only for specific products / categories.

The snippets in this post will only be for hiding prices, it will still continue users to add products to the cart.

Hiding all the prices

Lets start with a simple script first. This is a example of how you can hide all the prices no matter who is viewing.

I’ve made it so that it does still show prices on the admin, but you can easily comment that line out if you also want to hide prices there.

This code snippet hides all the prices on the product / archive pages, but not on the cart/checkout pages (or the cart widget). The following code also removes the cart item price / subtotal and the same for the checkout.

After using this code snippet it will leave the headings in the table. Unfortunately these cannot be removed with a code snippet, but there are two alternatives.

  1. By modifying the WooCommerce template files you can remove the columns from the totals table. The totals table is located in the cart/cart.php template file.
  2. You can hide them with CSS. A technical user could still uncover the product prices through, so depending on how important it is, this may or may not fit your requirements.

Here’s a CSS snippet that hides the prices on the items on the cart/checkout table and the cart widget:

/* Cart widget */
.woocommerce-mini-cart__total {
	display: none;
}

/* Cart */
.product-price, .product-subtotal {
	display: none !important;
}

/* Checkout */
.product-total *, th.product-total {
	display: none;
}

Again, this is not a foolproof solution.

Hiding prices for specific user roles

In the below code snippet it will hide the prices for all users with the ‘wholesale’ user role. In the sample code I’ve added multiple rows to show how you can can hide prices for different user roles. Adding more options to it is possible by following the shown format.

Hiding prices for guest users

To only hide it for guest users you can use the following simplified version;

Hiding prices in specific categories

With this version of the code snippet you can target specific categories to hide the prices for.

You can either modify the set categories to the slug of ID of the category.

If wanted you can also combine the snippets to only hide the prices in specific categories for a guest user;

Hiding prices for specific products

Here’s one last version where it only hides the prices for specific products based on the product ID.

 

Hope you’ve found this post helpful!

  • Jeroen Sormani

    I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

    Interested in talking about a WordPress project? Get in touch!

    Follow me on Twitter
  • 9 thoughts on “Hiding product prices in WooCommerce

    Roger Woodroofe December 6, 2017 at 5:16 am

    Hey Jeroen,

    Thanks for the post! This helped me out a lot getting started customising a site to selectively hide prices based on “Woocommerce Memberships” and “Categories”.

    Cheers
    Roger

    Wayne December 29, 2017 at 6:12 pm

    Hi Jeroen,

    Thank you. it really helped! Is it possible to hide prices for specific products on shop and single product page but display on cart, cart total and checkout?

    Jeroen December 30, 2017 at 2:39 pm

    Hi Wayne,

    You can use these code snippets as a basis, and add some additional code to do allow them to show on the cart/checkout pages accordingly.
    I don’t have something ready to go for that though.

    Cheers,
    Jeroen

    Hasan January 29, 2018 at 3:53 pm

    Jeroen Hello,

    First of all thank you for sharing code. I want to hide the prices of all the products on my website but I do not know where to add the codes you give. Could you please give me information? Where do I add the codes?

    Jeroen January 29, 2018 at 6:05 pm

    I’ve written a blog post about how you can add a code snippet to your site. You can find it here:
    https://shopplugins.com/how-to-add-a-code-snippet-to-your-site/

    Brett January 31, 2018 at 6:42 am

    Hi Jeroen,

    I tried the ‘hiding prices in specific categories’ but it also hides the prices in the cart page for all products added to cart, not just those in the category. Any chance you can update this?

    Wazo February 5, 2018 at 1:51 am

    Hey amazing article!! thank you! helped me a long way. Was wondering if you can help compare the title of the product. i want to hide prices for products that have “trade” in the product title. Also have an attribute trade=yes which I can use aswellbut i dont know how to. Tried the following but it didnt work;

    $page_title =get_the_title();
    if (strpos($page_title, ‘Trade) !== false) {

    Jarrod February 5, 2018 at 7:31 am

    What does the ‘ }, 10, 2 ); ‘ do in the last line of the code to hide categories?
    I’m trying to: HIDE prices UNLESS the user is logged in AND/OR the product has a TAG of ‘highlight’. I’m stumped!

    Jarrod February 5, 2018 at 10:56 am

    Never mind! I’ve figured it out! Thank you for an excellent resource. I wouldn’t have been able to meet my client’s request if it weren’t for this page!! Thank you!!

    Leave a Reply