cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add custom text under the price in frontend?

SOLVED

How do I add custom text under the price in frontend?

Hey Guys,

 

since I use Magento ver. 2.1.7. I Want to add a simple Text under every price in the frontend. 
The Text has to inform the customer, that the price includes 19% Taxes and has to include a link to the shippingcosts page. I need to do that, so my site fits to the german laws.

Can anybody help me with this issue, I'm struggling since a week to solve this problem. 

 

 

Thank you in advance! 

4 REPLIES

Re: How do I add custom text under the price in frontend?

Hi @BlackstoneFatih

 

Method - 1:  If you want to display custom text only in product view page, then create catalog_product_view.xml in your custom theme

app/design/frontend/Vendor/theme/Magento_Catalog/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" name="custom.text" template="Magento_Catalog::view/customtext.phtml" after="product.info.price"/>
        </referenceContainer>
    </body>
</page>

 

Now create customtext.phtml and add your custom text

 

app/design/frontend/Vendor/theme/Magento_Catalog/templates/view/customtext.phtml

 

Now flush the cache and check

 

Method - 2: If you want to display custom text after price at everywhere then override final_price.phtml

 

FROM

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

TO

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

 

Method - 3: Last and the most simple way to do it with CSS

 

 

.product-info-price .price:after {
    content: 'Custom Text';
}

 

 If Issue Solved, Click Kudos/Accept As solutions.

 

Re: How do I add custom text under the price in frontend?

Thank you very much! This solved all my problems! 

 

Re: How do I add custom text under the price in frontend?

okay, I tried to display the Text in the product listing page also, but method 2 won't work for me :/

Re: How do I add custom text under the price in frontend?

Hello Prince I've been able to create a custom attribute and place the price under the text my issue is getting the attribute inline with the price like so.

 

per deadlock.PNG

Is there a way to add a custom attribute here

Magento/Catalog/Templates/Product/Price/Amount/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"' : '' ?>>
<?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>

/*   If Code added here it falls in-line */ 


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

Any suggestions?