In a earlier post I wrote about hiding product prices on category pages. This post is similar on hiding prices, but focuses on the hiding of pricing based on the user role, or lack thereof (guest users).
Hiding Prices for Guest Users
First thing I want to show is hiding prices for all users that are not logged in. The snippet below will hide all product prices on the overview and product detail pages.
Hiding Cart/Checkout Prices and Totals for Guest Users
The above snippet doesn’t hide the prices or totals in the cart/checkout, to do that you’d want to add these additional lines of code to the prior snippet;
This snippet will hide the product prices in the items and total tables; however it will not remove the ‘Price’ and ‘Total’ table headings. If you also want to remove that, a snippet of CSS will can to be used to hide it. This is a PHP snippet that will only add the CSS when the user is not logged in.
Hiding Prices for Customers, Showing for Wholesale User Role
The prior snippets were only hiding prices for guest users. Next up are the same snippets with some changes. These (combined) snippet will only show prices for wholesale customers, not for regular or guest users.
In these snippets you can of course modify the ‘wholesale’ user role to your user role slug you’d like to show product prices for. In the snippet I’ve also added the ‘administrator’ role so admins also see the prices, plus you’ll know how to add additional user roles that will be able to see product prices.
This is great. What if you want to hide prices for a specific category inc sub categories for all but one user role?
Hi Vanessa,
That is possible of course; you’d want to further customize the snippet to include the subcategories (by default it only takes the direct matching categories).
You can change the snippet to show only for the setup user roles (in this example its only set for ‘administrator’ and ‘wholesale’ roles.
HI there thanks for the above. How do you reverse it, so prices are shown to everyone EXCEPT wholesale role?
ie. prices are hidden on product and cart for Wholesale roles.
Hi Nicholas,
You’d need to go through the code snippets and change all the conditional statements to only make it appear for guest users / not for a specific one.
Unfortunately I don’t have this readily at hand at the moment.
Cheers,
Jeroen
Hey, Please help me in hiding the price on the order received page too. Your this code has helped me a lot but my client needs to hide the price on the order received page too which comes after the checkout page. Please help me with this its urgent.
Many thanks in advance!
Hi Kinsey,
You can try to use the following;
add_filter( ‘woocommerce_order_formatted_line_subtotal’, ‘__return_empty_string’ );
add_filter( ‘woocommerce_get_order_item_totals’, ‘__return_empty_array’ );
It will still need some CSS to hide the table head at the very least. Its not the most elegant solution, but should work.
Cheers,
Jeroen
Hello!
Is there a way to keep the prices on the invoices but keep them hidden on the website?
So if the customer gets the email with the invoice then it would show the price there.
Right now it hides all the prices on there also.
Hi Kristofer,
I’m sure its possible, but as Woo doesn’t have invoices available natively I don’t have a code snippet readily available for it – it depends on the plugin you’re using for it.
Feel free to reach out through the contact form if you need any help creating such customization.
Cheers,
Jeroen
I am using the PDF Invoices & Packing Slips for WooCommerce plugin.
And then I added this code:
add_filter( ‘woocommerce_order_formatted_line_subtotal’, ‘__return_empty_string’ );
add_filter( ‘woocommerce_get_order_item_totals’, ‘__return_empty_array’ );
It worked on the checkout but then also worked with the invoices which I did not want to be hidden.
Hi Kristofer,
If may be possible to do make the code only work on the checkout page doing something like this:
add_filter( ‘woocommerce_order_formatted_line_subtotal’, function($default) {
if ( is_checkout() ) return __return_empty_string();
return $default;
} );
(untested)
Hope that helps,
Jeroen