1

I have added custom div in /var/www/html/pot/app/design/frontend/pot_customization/Magento_Catalog/templates/product/price/amount/default.phtml.

The div displays for all the products and works fine. But if a product have special price,the div displays two times near price .

Please provide me a solution to add my custom div after the price section.

default.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>

<?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"' : '' ?>>
    <span class='your-price'>Your Price</span>

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

<!-- custom div start -->
<?php $helper = $this->helper('x\ProductReview\Helper\Data');
?>
<div class="price-guarantee">
    <a href="<?php echo $helper->getBaseUrlData()."why-shop-with-us" ?>" class="guarantee-link">100 % Price Guarantee</a>
</div>
<div class = loyalty-points>
    <span>Loyalty Points<b> 4</b> <span>Learn more about our</span> <a href="<?php echo $helper->getBaseUrlData()."loyalty-points-program" ?>">loyalty points program</a></span>
</div>
<!--  End -->
0

You can create a custom module and add following files.

Magento/Catalog/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="product.info.main">
            <block class="Magento\Framework\View\Element\Template" after="product.price.tier" template="Magento_Catalog::afterprice.phtml" />
        </referenceContainer>
    </body>
</page>

Magento/Catalog/view/frontend/templates/afterprice.phtml

<!-- custom div start -->
<?php $helper = $this->helper('x\ProductReview\Helper\Data');
?>
<div class="price-guarantee">
    <a href="<?php echo $helper->getBaseUrlData()."why-shop-with-us" ?>" class="guarantee-link">100 % Price Guarantee</a>
</div>
<div class = loyalty-points>
    <span>Loyalty Points<b> 4</b> <span>Learn more about our</span> <a href="<?php echo $helper->getBaseUrlData()."loyalty-points-program" ?>">loyalty points program</a></span>
</div>
<!--  End -->

Replace Vendor and Module wherever needed.

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.