Display the Variable Product Price Range in WooCommerce

Quick Summary
- Call get_price_html() on a product object to print the formatted price range, with currency symbol and sale markup, as WooCommerce templates do.
- In a product loop, get the product with wc_get_product() from the global post's ID; a non-product ID makes the method call fail.
- On the single product page, use the global product object with an is_type() check so the range prints only for variable products.
A variable product in WooCommerce has its own price for each variation. When you build a custom product loop or template, you can print the formatted price range with the product’s get_price_html() method. It returns the same HTML WooCommerce uses in its default templates, including the currency symbol and any sale markup.
Use the code in a theme template file, for example a custom shop loop or a WooCommerce template override in your child theme.
Inside a product loop
<?php
global $post;
// Get the WC_Product_Variable instance Object
$product = wc_get_product( $post->ID ); // Works for any product type
// Displaying the formatted "Min" - "Max" price range
echo $product->get_price_html();
?>global $postgives you the current post in the loop, andwc_get_product()turns its ID into a WooCommerce product object.get_price_html()works for any product type. For a variable product whose variations have different prices, it returns the lowest to highest range; when all variations cost the same, it returns a single price. Simple products show their normal price.- If the ID doesn’t belong to a product,
wc_get_product()doesn’t return a product object and the method call fails, so only use this in a loop of products.
On the single product page
On the single product page WooCommerce already sets up a global $product object, so you can skip the lookup and echo the price directly. The is_type( 'variable' ) check makes sure the range is only printed for variable products.
<?php if( $product->is_type( 'variable' ) ): ?>
<?php
echo $product->get_price_html();
?>
<?php endif ?>If you use this inside your own function or hook callback instead of a template, add global $product; first so the variable is available there. The default single product template already shows the price once, so this is mainly useful in a custom layout. To show only the lowest price with a Starting At label instead, see replacing the variable price range.
If you want price ranges and sale prices shown your own way, that’s part of my WooCommerce development work.
Related articles
- adding an AJAX add to cart button to the same loop: completes a custom product card
- printing each variation’s price and image: when a range isn’t detailed enough
