1

I'm trying to achieve the following in magento 2.2.2

products with the price of $ 0.00 should display the following text: "FREE" on the front-end

I've already created my custom theme and the folder of "Magento_Catalog". My question is, how can I achieve what I've described earlier? (or better said, where can I find the phtml or php files to copy them into my custom theme and customize them?)

2

you can edit your theme Magento_Catalog/templates/product/price/amount/default.phtml file and add price check there like below code updated :

<?php if ($block->getDisplayValue() == 0 ) { // Add 0 Price condtion ?>

<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; ?>
    <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; ?>
</span>
    <?php } else { ?>
    <span>Free</span>
    <?php } ?>

Or you can implement this logic where ever you want.

| improve this answer | |
  • ..you are a genius.. 2 days looking into this and you brought a simple yet effective solution... thanks.!!!!!! – Rainier Gaari Mar 26 '18 at 19:21
  • glad , your issue is solved – Naveed Asim Mar 27 '18 at 5:01

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.