How to exclude a variable price from the WooCommerce price filter?

I need to remove one specific variable price from the price filter and for the WooCommerce order by price.

I have 4 variable product, and I don’t want to show one variable attribute that contains the price $495 for all products in the price filter.

Read More

I just want to hide this specific attribute so it will not be counted in the price filter as well as in the wordpress order by price.

Thank you.

Related posts

Leave a Reply

1 comment

  1. You will need something like this:

    add_filter( 'woocommerce_sale_price_html',           'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_price_html',                'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_empty_price_html',          'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variable_sale_price_html',  'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variable_price_html',       'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variable_empty_price_html', 'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variation_sale_price_html', 'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variation_price_html',      'custom_remove_price_html', 20, 2 );
    
    function custom_remove_price_html( $price, $product ) {
    
        // if this is a product is a variable product.
        if ( $product->is_type( 'variable' ) ) { // updated
            // $price = '';
            return;
        }
        return $price;
    }
    

    If it doesn’t work as you want, you will need to fine tune conditionals inside the function, to feet your needs.

    You have to add this code snippet in the functions.php file of your active theme (or better of your active child theme).