How to Display the Default Variation Price in WooCommerce

p1

Show Only the Default Variation Price in WooCommerce (Instead of a Price Range)

By default, WooCommerce displays a price range for variable products (for example, $20 – $50). While this is useful in some cases, it can also confuse customers or create hesitation during the buying process.

If you’d prefer to show only the price of the default variation, this post will walk you through how to do it with a simple PHP snippet.

Why Display Just the Default Variation Price?

Showing the exact price of the pre-selected (default) variation can improve the shopping experience in several ways:

  • It’s more specific and clear than a range.

  • It reflects what the customer actually sees selected.

  • It helps reduce decision fatigue.

  • It can even lead to higher conversions and a lower bounce rate.

How to Show Only the Default Variation Price

To change the default price display, you can use the following snippet in your theme’s functions.php file or within a custom plugin.

<?php

add_filter( 'woocommerce_variable_price_html', 'custom_variation_price_html', 10, 2 );
function custom_variation_price_html( $price, $product ) {

    $default_attributes = $product->get_default_attributes();
    if ( empty( $default_attributes ) ) return $price;

    foreach ( $product->get_available_variations() as $variation ) {
        $match = true;
        foreach ( $default_attributes as $key => $value ) {
            if ( $variation['attributes']['attribute_' . sanitize_title($key)] !== $value ) {
                $match = false;
                break;
            }
        }
        if ( $match ) {
            $variation_obj = wc_get_product( $variation['variation_id'] );
            return $variation_obj->get_price_html();
        }
    }

    return $price;
}

What Does This Code Do?

  • Hooks into the woocommerce_variable_price_html filter.
  • Checks if a default variation is set for the product.
  • If a match is found, it shows the price of the default variation instead of the full range.

Leave a Comment

Your email address will not be published. Required fields are marked *