Hide product prices in selected categories

This little snippet will allow you to hide product prices in selected categories. Simply replace the slugs in the code below.

// Specific product category archive pages
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_loop_product_prices', 1 );
function hide_loop_product_prices(){
    global $product;

    if( is_product_category('PUT YOUR CATEGORY SLUG HERE') ):

    // Hide prices
    remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    // Hide add-to-cart button
    remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 30 );

    endif;
}

// Single product pages
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
    global $product;

    if( has_term( 'PUT YOUR CATEGORY SLUG HERE', 'product_cat', $product->get_id() ) ):

    // Hide prices
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

    // Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)
    if( ! $product->is_type('variable') ){
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
    } else {
        remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
    }

    endif;
}

 

gfdfgh


4 Comments

  • Giles Martin

    October 5, 2018

    Worked like a charm thank you 🙂

    Reply
  • Mieke

    May 4, 2019

    Thanks! This one works for me!

    Reply
  • mohan mandal

    September 11, 2020

    want to hide variable product price in product page only not in shop page and home page

    Reply
  • Stefano

    March 1, 2021

    Hi, how to fix for multiple categories?

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.