Back to Top

Get Price Range for Configurable Product in Magento 2

Updated 13 March 2024

To display the Price Range of a configurable product in Magento, you can use a method provided by Magento to get the Minimum and Maximum Price. This post will explain how to obtain the range in a template file.

In your module structure create a layout file catalog_product_view_type_configurable.xml, in my case the file path is app/code/Webkul/PriceRange/view/base/layout/catalog_product_view_type_configurable.xml

<?xml version="1.0"?>
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="">
            <block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name=""  template="Webkul_PriceRange::product/price_range.phtml" />

Now, we will create template file price_range.phtml at path app/code/Webkul/PriceRangeCustomisation/view/base/templates/

$currentProduct = $this->getProduct();
$regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price');
<div class='price-box'>
    <span class="price">
            echo $regularPrice->getMinRegularAmount().'-'.$regularPrice->getMaxRegularAmount();

Also, the methods getMinRegularAmount() and getMaxRegularAmount() returns the price of  In Stock associated products only.

For further studying the method definition, you can refer to the file magento_root_directory/vendor/magento/module-configurable-product/Pricing/Price/ConfigurableRegularPrice.php

Searching for an experienced
Magento Company ?
Find out More

That’s all for the post, feedback is welcomed.

. . .

Leave a Comment

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

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home