• Resolved aleksdab

    (@aleksdab)


    Hi,

    I would like to hide the prices of product variants. I have a code that works, but it also hides the price range on category pages. Do you know how to modify this code so that it works only within product pages, not categories? I would greatly appreciate your help.

    function patricks_custom_variation_price( $price, $product ) {

        $target_product_types = array(

            'variable'

        );

        if ( in_array ( $product->product_type, $target_product_types ) ) {

            // if variable product return and empty string

            return '';

        }

        // return normal price

        return $price;

    }

    add_filter('woocommerce_get_price_html', 'patricks_custom_variation_price', 10, 2);

    Best regards,

    Ola

Viewing 1 replies (of 1 total)
  • Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    I understand you’d like to hide the prices of product variants specifically on product pages while keeping the price range visible on category pages. Your current code applies globally, which is why it also affects the category pages.

    To ensure the modification works only on product pages, you can use the is_product() conditional function. Here’s an updated version of your code:

    function patricks_custom_variation_price( $price, $product ) {

    $target_product_types = array(

    'variable'

    );

    if ( is_product() && in_array ( $product->product_type, $target_product_types ) ) {

    // if variable product return and empty string

    return '';

    }

    // return normal price

    return $price;

    }

    add_filter('woocommerce_get_price_html', 'patricks_custom_variation_price', 10, 2);

    Please note that we do not provide support for customization. If that code does not work, I recommend?WooExperts?and?Codeable.io?as options for getting professional help. Alternatively, you can also ask your development questions in the??WooCommerce Community Slack?as custom code falls outside our usual?scope of support

    Thank you

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.