Magento – Magento 2 display configurable product Price Range in product page

configurable-productmagento2price

I want to display the price range for configurable products on the product page.

Best Answer

Please follow the below steps.

Step 1: Create a layout file catalog_product_view_type_configurable.xml on this path app/design/frontend/{{companyname}}/{{themename}}/Magento_ConfigurableProduct/layout/catalog_product_view_type_configurable.xml

<referenceBlock name="product.info.price">
    <block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name="wk.info.pricerange"  template="Magento_ConfigurableProduct::product/price_range.phtml" />
</referenceBlock>

Step 2: Create template file price_range.phtml on this path app/design/frontend/{{companyname}}/{{themename}}/Magento_ConfigurableProduct/templates/product/price_range.phtml

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