1

I am trying to change the way prices are displayed on the product page and category pages.

If

Configuration -> Sales -> Tax -> Price Display Settings -> Display Product Prices In Catalog ---> "Including and Excluding Tax"

Magento by default display prices

$66

Excl. Tax: $60

Magento 2 Product Page Price Inc. Tax and Excl. Tax

I would like to display prices as

$60 Excl. Tax

$66 Inc. Tax

I have moved default.phtml to my child theme

/app/design/frontend/mytheme/mytheme/Magento_Catalog/templates/product/price/amount/default.phtml

But now I have no idea what needs to be done.

<span class="price-container <?php /* @escapeNotVerified */ echo $block->getAdjustmentCssClasses() ?>"
    <?php echo $block->getSchema() ? ' itemprop="offers" itemscope itemtype="http://schema.org/Offer"' : '' ?>>
<?php if ($block->getDisplayLabel()): ?>
    <span class="price-label"><?php /* @escapeNotVerified */ echo $block->getDisplayLabel(); ?></span>
<?php endif; ?>
<span <?php if ($block->getPriceId() && $id!=''): ?> id="<?php echo $id ?><?php /* @escapeNotVerified */ echo $block->getPriceId() ?>"<?php endif;?>
    <?php echo($block->getPriceDisplayLabel()) ? 'data-label="' . $block->getPriceDisplayLabel() . $block->getPriceDisplayInclExclTaxes() . '"' : '' ?>
    data-price-amount="<?php /* @escapeNotVerified */ echo $block->getDisplayValue(); ?>"
    data-price-type="<?php /* @escapeNotVerified */ echo $block->getPriceType(); ?>"
    class="price-wrapper <?php /* @escapeNotVerified */ echo $block->getPriceWrapperCss(); ?>"
    <?php echo $block->getSchema() ? ' itemprop="price"' : '' ?>>
    <?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>
</span>
  • If you select including price option It will automatically display both price on frontend – Ronak Chauhan Nov 29 '17 at 4:56
1
<?php if ($block->hasAdjustmentsHtml()): ?>
    <?= $block->getAdjustmentsHtml() ?>
<?php endif; ?>

Add this code before this block of code

<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>

Take a look at Snapshot

  • Hi I use your code but I don't see labels EXT TAX and incl TAX. – BartZalas Apr 22 '18 at 17:31
  • Hi @btek Please go to tax configuration (Stores->Configuration->Sales->Tax) Display Product Prices In Catalog should be set to Including and excluding tax – Syed Saleem Apr 25 '18 at 2:12
  • It's already set. I'm asking about labels. – BartZalas Apr 26 '18 at 6:50
  • Something is hiding them (labels Incl Tax and Excl. Tax) I use child of blank Magento theme. – BartZalas Apr 26 '18 at 20:04
  • Something is hiding them (labels Incl Tax and Excl. Tax) I use child of blank Magento theme smae issue facing it – Rv Singh Nov 15 at 8:46
0

To show labels i used this css:

.price-excluding-tax::before {
    content: attr(data-label) ": ";
    font-size: 1.1rem;
}
.price-including-tax::before {
    content: attr(data-label) ": ";
    font-size: 1.1rem;
}

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.