0

hi I want to customize the price display in product details page Magento 2

magento 2 product price where I can customize the codes

(path)

my goal:

1) I want to add a label near the First price .

2) How I can display a discount in percentages (%) .

Can anyone tell me where I can do this updates ?

Magento version 2.2.6.

amount/default.phtml

<?php /** @var \Magento\Framework\Pricing\Render\Amount $block */ ?>

<span class="price-container <?= /* @escapeNotVerified */ $block->getAdjustmentCssClasses() ?>"
        <?= $block->getSchema() ? ' itemprop="offers" itemscope itemtype="http://schema.org/Offer"' : '' ?>>
    <?php if ($block->getDisplayLabel()): ?>
        <span class="price-label"><?= /* @escapeNotVerified */ $block->getDisplayLabel() ?></span>
    <?php endif; ?>
    <p>Exclusive of Tax : </p> <span <?php if ($block->getPriceId()): ?> id="<?= /* @escapeNotVerified */ $block->getPriceId() ?>"<?php endif;?>
        <?= ($block->getPriceDisplayLabel()) ? 'data-label="' . $block->getPriceDisplayLabel() . $block->getPriceDisplayInclExclTaxes() . '"' : '' ?>
        data-price-amount="<?= /* @escapeNotVerified */ $block->getDisplayValue() ?>"
        data-price-type="<?= /* @escapeNotVerified */ $block->getPriceType() ?>"
        class="price-wrapper <?= /* @escapeNotVerified */ $block->getPriceWrapperCss() ?>"
    ><?= /* @escapeNotVerified */ $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?></span>
    <?php if ($block->hasAdjustmentsHtml()): ?>
        <?= $block->getAdjustmentsHtml() ?>
    <?php endif; ?>
    <?php if ($block->getSchema()): ?>
        <meta itemprop="price" content="<?= /* @escapeNotVerified */ $block->getDisplayValue() ?>" />
        <meta itemprop="priceCurrency" content="<?= /* @escapeNotVerified */ $block->getDisplayCurrencyCode() ?>" />
    <?php endif; ?>
1

For the first Goal: 1) I want to add a label near the First price . Follow this Link You need to override

/vendor/magento/module-catalog/view/base/web/js/price-box.js And add your label : enter image description here

For the second Goal : 2) How I can display a discount in percentages (%)

Override this file :

vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml

Your override

app/design/frontend/Your/theme/Magento_Catalog/templates/product/price/final_price.phtml

And add the below code under this section <span class="old-price">...</span>:

 <span class="price-percentage">
        <?php $percentage = 100 - round(($finalPriceModel->getAmount()->getValue() / $priceModel->getAmount()->getValue())*100); ?>
        <?php echo $percentage ."% OFF"?>
    </span>
| improve this answer | |
  • i have enable two prices one is inclusive of tax and exclusive of tax the label is showing for both price so, how i can only show for one price.... – prabhakaran7 Jul 10 '19 at 8:44
  • price-percentage is not showing in front end.. – prabhakaran7 Jul 10 '19 at 8:48
  • Then open the hints where the price of exluding and including are , do a control there <?php if ($block->displayPriceExcludingTax()): ?> <span class="price"><?= /* @escapeNotVerified */ (add your label) $block->getDisplayAmountExclTax() ?></span></span> <?php endif; ?> , check you are doing the override ok for the price-percentage , check if the product has discount , clear cache and static files , run reindex . – Ylgen Guxholli Jul 10 '19 at 9:00
  • showing error for <?= /* @escapeNotVerified */ (add your label) $block->getDisplayAmountExclTax() ?> this line error : expected ): – prabhakaran7 Jul 10 '19 at 9:48
  • getDisplayAmountExclTax() is not a method – prabhakaran7 Jul 10 '19 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.