• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Woocommerce - Hide Price in Specific Category

xlx

Active member
Dec 13, 2018
187
74
28
Hello,

I have a ecommerce cart, built on woocommerce.
I need to hide the price in the category page for specific categories.
But the price should be displayed in the individual product page

Ive used this piece of code

PHP:
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );

following this article

The only issue being it hides the price for all categories, not specific ones
for example i want to hide headphones and covers.

Can someone please edit the code to hide only specific categories.

Thanks for helping
 
Last edited:
You should add a filter like:

Code:
add_filter( ‘woocommerce_get_price_html‘, function( $price, $product ) {
    $hide_for_categories = array( ‘category1‘, ‘category2‘ );
    if ( has_term( $hide_for_categories, ‘product_cat‘, $product->get_id() ) ) {
        return ‘‘; // hide price if in hidden price category list
    }
    return $price; // show price if not in hidden price category list
}, 10, 2 );

Add this code to your theme or child theme function.php
 
  • Like
Reactions: xlx
@slvrsteele Thanks for your awesome help.

This code does work on the shop page, and it does not show the price in the selected category.
But it also hides the price once i click the product, i do want to show the price when the user clicks on the individual product.

Thanks again for helping
 
Just change the condition:

Code:
add_filter( ‘woocommerce_get_price_html‘, function( $price, $product ) {
    $hide_for_categories = array( ‘category1‘, ‘category2‘ );
    if ( is_shop() && has_term( $hide_for_categories, ‘product_cat‘, $product->get_id() ) ) {
        return ‘‘; // hide price if in hidden price category list
    }
    return $price; // show price if not in hidden price category list
}, 10, 2 );

or a bit dirtier add a second if

Code:
add_filter( ‘woocommerce_get_price_html‘, function( $price, $product ) {
    $hide_for_categories = array( ‘category1‘, ‘category2‘ );
    if ( is_shop() ) {
        if ( has_term( $hide_for_categories, ‘product_cat‘, $product->get_id() ) ) {
            return ‘‘; // hide price if in hidden price category list
        }
        return $price; // show price if not in hidden price category list
    }
    return $price; // show price if not shop page
}, 10, 2 );
 
Last edited:
  • Like
Reactions: xlx
Thanks @slvrsteele .. ill surely check this and get back to you.

Appreciate your time and patience.
Thanks a Ton!
 
  • Like
Reactions: Mr G
@slvrsteele This works fantastic. thanks for helping bro,

Now i realize i failed to share a vital piece of information, the above code works flawlessly on my shop page. I have made a separate page for sale and have used wpbakery to pull products from my special categories on this page.

Can the same functionality be added to this specific page?
Really appreciate for your patience.
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock