Show a product attribute under price - Magento 2Show new attribute in product view.phtmlhow can i show group attribute name in product page?Show Simple Product attribute on homepageIs it possible to merge several attribute values and show it under single attribute name in the filtering?magento 2 captcha not rendering if I override layout xmlPrice format custom product price attributemain.CRITICAL: Plugin class doesn't existMagento 2 - show product attribute labelsMagento 2: Show/Hide product attribute based on other attribute valueShow “dropdown” attribute type on product grid

Why won't the ground take my seed?

What is the difference between handcrafted and learned features

Can a police officer film me on their personal device in my own home?

What exactly is a fey/fiend/celestial spirit?

Is there a category where products don't exist because uniqueness fails?

Prime parity peregrination

What is "oversubscription" in Networking?

Do space suits measure "methane" levels or other biological gases?

3D nonogram, beginner's edition

Is it allowed to spend a night in the first entry country before moving to the main destination?

Different budgets within roommate group

Does “comme on était à New York” mean “since” or “as though”?

Symbol for "not absolutely continuous" in Latex

Why transcripts instead of degree certificates?

Spicket or spigot?

Is this hogweed?

Golf the smallest circle!

Most elegant way to write a one shot IF

Can 'leave' mean 'forget'?

Most importants new papers in computational complexity

How to fix a dry solder pin in BGA package?

Was it really unprofessional of me to leave without asking for a raise first?

Did Wakanda officially get the stuff out of Bucky's head?

Does the Pi 4 resolve the Ethernet+USB bottleneck issue of past versions?



Show a product attribute under price - Magento 2


Show new attribute in product view.phtmlhow can i show group attribute name in product page?Show Simple Product attribute on homepageIs it possible to merge several attribute values and show it under single attribute name in the filtering?magento 2 captcha not rendering if I override layout xmlPrice format custom product price attributemain.CRITICAL: Plugin class doesn't existMagento 2 - show product attribute labelsMagento 2: Show/Hide product attribute based on other attribute valueShow “dropdown” attribute type on product grid






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying to show a product attribute underneath the price in Magento 2. I have overridden the template by adding it to my theme:



Magento_Catalog/templates/product/price/amount/default.phtml


This is the contents of this file:



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

// @codingStandardsIgnoreFile

?>

<?php /** @var MagentoFrameworkPricingRenderAmount $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>
<?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>


So I would assume that I need to add this at the top of the file:



<?php
$_product = $block->getProduct();
$myattr = $_product->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product);
?>


Then use the following to include it where I need it



<?php if($myattr != "") echo $myattr ?>


But I just get a blank page when I view it on the front end. Can anyone help please?










share|improve this question






















  • Try to overwrite vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml file to add new block. It may work

    – Vignesh Bala
    Nov 28 '18 at 10:49











  • I know how to add blocks via XML but not product attributes. Can you elaborate please?

    – Ordog
    Nov 28 '18 at 10:54











  • Is it needed every where at price displayed ?

    – Vignesh Bala
    Nov 28 '18 at 10:59











  • Yes, underneath every price :)

    – Ordog
    Nov 28 '18 at 11:02











  • You mean every page ?

    – Vignesh Bala
    Nov 28 '18 at 11:05


















0















I'm trying to show a product attribute underneath the price in Magento 2. I have overridden the template by adding it to my theme:



Magento_Catalog/templates/product/price/amount/default.phtml


This is the contents of this file:



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

// @codingStandardsIgnoreFile

?>

<?php /** @var MagentoFrameworkPricingRenderAmount $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>
<?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>


So I would assume that I need to add this at the top of the file:



<?php
$_product = $block->getProduct();
$myattr = $_product->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product);
?>


Then use the following to include it where I need it



<?php if($myattr != "") echo $myattr ?>


But I just get a blank page when I view it on the front end. Can anyone help please?










share|improve this question






















  • Try to overwrite vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml file to add new block. It may work

    – Vignesh Bala
    Nov 28 '18 at 10:49











  • I know how to add blocks via XML but not product attributes. Can you elaborate please?

    – Ordog
    Nov 28 '18 at 10:54











  • Is it needed every where at price displayed ?

    – Vignesh Bala
    Nov 28 '18 at 10:59











  • Yes, underneath every price :)

    – Ordog
    Nov 28 '18 at 11:02











  • You mean every page ?

    – Vignesh Bala
    Nov 28 '18 at 11:05














0












0








0








I'm trying to show a product attribute underneath the price in Magento 2. I have overridden the template by adding it to my theme:



Magento_Catalog/templates/product/price/amount/default.phtml


This is the contents of this file:



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

// @codingStandardsIgnoreFile

?>

<?php /** @var MagentoFrameworkPricingRenderAmount $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>
<?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>


So I would assume that I need to add this at the top of the file:



<?php
$_product = $block->getProduct();
$myattr = $_product->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product);
?>


Then use the following to include it where I need it



<?php if($myattr != "") echo $myattr ?>


But I just get a blank page when I view it on the front end. Can anyone help please?










share|improve this question














I'm trying to show a product attribute underneath the price in Magento 2. I have overridden the template by adding it to my theme:



Magento_Catalog/templates/product/price/amount/default.phtml


This is the contents of this file:



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

// @codingStandardsIgnoreFile

?>

<?php /** @var MagentoFrameworkPricingRenderAmount $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>
<?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>


So I would assume that I need to add this at the top of the file:



<?php
$_product = $block->getProduct();
$myattr = $_product->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product);
?>


Then use the following to include it where I need it



<?php if($myattr != "") echo $myattr ?>


But I just get a blank page when I view it on the front end. Can anyone help please?







magento2 product-attribute






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '18 at 10:37









OrdogOrdog

12417 bronze badges




12417 bronze badges












  • Try to overwrite vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml file to add new block. It may work

    – Vignesh Bala
    Nov 28 '18 at 10:49











  • I know how to add blocks via XML but not product attributes. Can you elaborate please?

    – Ordog
    Nov 28 '18 at 10:54











  • Is it needed every where at price displayed ?

    – Vignesh Bala
    Nov 28 '18 at 10:59











  • Yes, underneath every price :)

    – Ordog
    Nov 28 '18 at 11:02











  • You mean every page ?

    – Vignesh Bala
    Nov 28 '18 at 11:05


















  • Try to overwrite vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml file to add new block. It may work

    – Vignesh Bala
    Nov 28 '18 at 10:49











  • I know how to add blocks via XML but not product attributes. Can you elaborate please?

    – Ordog
    Nov 28 '18 at 10:54











  • Is it needed every where at price displayed ?

    – Vignesh Bala
    Nov 28 '18 at 10:59











  • Yes, underneath every price :)

    – Ordog
    Nov 28 '18 at 11:02











  • You mean every page ?

    – Vignesh Bala
    Nov 28 '18 at 11:05

















Try to overwrite vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml file to add new block. It may work

– Vignesh Bala
Nov 28 '18 at 10:49





Try to overwrite vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml file to add new block. It may work

– Vignesh Bala
Nov 28 '18 at 10:49













I know how to add blocks via XML but not product attributes. Can you elaborate please?

– Ordog
Nov 28 '18 at 10:54





I know how to add blocks via XML but not product attributes. Can you elaborate please?

– Ordog
Nov 28 '18 at 10:54













Is it needed every where at price displayed ?

– Vignesh Bala
Nov 28 '18 at 10:59





Is it needed every where at price displayed ?

– Vignesh Bala
Nov 28 '18 at 10:59













Yes, underneath every price :)

– Ordog
Nov 28 '18 at 11:02





Yes, underneath every price :)

– Ordog
Nov 28 '18 at 11:02













You mean every page ?

– Vignesh Bala
Nov 28 '18 at 11:05






You mean every page ?

– Vignesh Bala
Nov 28 '18 at 11:05











2 Answers
2






active

oldest

votes


















3














You can try with a separate phtml file and layout XML as describe below.



Assumed "model_number" is the custom attribute that you want to display and your custom theme is "VendorName_customtheme"



step 1:
create /app/design/frontend/VendorName/customtheme/Magento_Catalog/layout/catalog_product_view.xml



File catalog_product_view.xml



<?xml version="1.0"?> 
<page layout="1column" 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="MagentoCatalogBlockProductViewAttributes" name="product.mycustom.attribute" as="model_number" template="Magento_Catalog::product/view/custom_attrib.phtml" after="product.info.price" />
</referenceContainer>
</body>
</page>


step 2: create /app/design/frontend/VendorName/customtheme/Magento_Catalog/templates/product/view/custom_attrib.phtml



File : custom_attrib.phtml



<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$_product = $block->getProduct();
?>
<div class="">
<?php
$attribute = $_product->getResource()->getAttribute('model_number');
if ($attribute)

$attr_value = $attribute ->getFrontend()->getValue($_product); ?>
<?= $block->escapeHtml(__('Model no.')). $attr_value ?>
<?php ?>
</div>


step 3: Run this CLI command from your magento root



sudo rm -rf pub/static/frontend/*


enter image description here






share|improve this answer























  • I guess it's working product detail page only.

    – Vignesh Bala
    Nov 28 '18 at 12:32











  • Yes. What other places do you need to display this custom attribute.

    – Pritam Info 24
    Nov 28 '18 at 12:33











  • Ordog needs to display every where that means all pages

    – Vignesh Bala
    Nov 28 '18 at 12:35











  • This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

    – Ordog
    Nov 28 '18 at 13:02












  • A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

    – Pritam Info 24
    Nov 28 '18 at 14:37


















0














You can access the current product (Magento 2.3.x) within price template phtml using



$product = $block->getSaleableItem();





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f251616%2fshow-a-product-attribute-under-price-magento-2%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    You can try with a separate phtml file and layout XML as describe below.



    Assumed "model_number" is the custom attribute that you want to display and your custom theme is "VendorName_customtheme"



    step 1:
    create /app/design/frontend/VendorName/customtheme/Magento_Catalog/layout/catalog_product_view.xml



    File catalog_product_view.xml



    <?xml version="1.0"?> 
    <page layout="1column" 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="MagentoCatalogBlockProductViewAttributes" name="product.mycustom.attribute" as="model_number" template="Magento_Catalog::product/view/custom_attrib.phtml" after="product.info.price" />
    </referenceContainer>
    </body>
    </page>


    step 2: create /app/design/frontend/VendorName/customtheme/Magento_Catalog/templates/product/view/custom_attrib.phtml



    File : custom_attrib.phtml



    <?php
    $_helper = $this->helper('MagentoCatalogHelperOutput');
    $_product = $block->getProduct();
    ?>
    <div class="">
    <?php
    $attribute = $_product->getResource()->getAttribute('model_number');
    if ($attribute)

    $attr_value = $attribute ->getFrontend()->getValue($_product); ?>
    <?= $block->escapeHtml(__('Model no.')). $attr_value ?>
    <?php ?>
    </div>


    step 3: Run this CLI command from your magento root



    sudo rm -rf pub/static/frontend/*


    enter image description here






    share|improve this answer























    • I guess it's working product detail page only.

      – Vignesh Bala
      Nov 28 '18 at 12:32











    • Yes. What other places do you need to display this custom attribute.

      – Pritam Info 24
      Nov 28 '18 at 12:33











    • Ordog needs to display every where that means all pages

      – Vignesh Bala
      Nov 28 '18 at 12:35











    • This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

      – Ordog
      Nov 28 '18 at 13:02












    • A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

      – Pritam Info 24
      Nov 28 '18 at 14:37















    3














    You can try with a separate phtml file and layout XML as describe below.



    Assumed "model_number" is the custom attribute that you want to display and your custom theme is "VendorName_customtheme"



    step 1:
    create /app/design/frontend/VendorName/customtheme/Magento_Catalog/layout/catalog_product_view.xml



    File catalog_product_view.xml



    <?xml version="1.0"?> 
    <page layout="1column" 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="MagentoCatalogBlockProductViewAttributes" name="product.mycustom.attribute" as="model_number" template="Magento_Catalog::product/view/custom_attrib.phtml" after="product.info.price" />
    </referenceContainer>
    </body>
    </page>


    step 2: create /app/design/frontend/VendorName/customtheme/Magento_Catalog/templates/product/view/custom_attrib.phtml



    File : custom_attrib.phtml



    <?php
    $_helper = $this->helper('MagentoCatalogHelperOutput');
    $_product = $block->getProduct();
    ?>
    <div class="">
    <?php
    $attribute = $_product->getResource()->getAttribute('model_number');
    if ($attribute)

    $attr_value = $attribute ->getFrontend()->getValue($_product); ?>
    <?= $block->escapeHtml(__('Model no.')). $attr_value ?>
    <?php ?>
    </div>


    step 3: Run this CLI command from your magento root



    sudo rm -rf pub/static/frontend/*


    enter image description here






    share|improve this answer























    • I guess it's working product detail page only.

      – Vignesh Bala
      Nov 28 '18 at 12:32











    • Yes. What other places do you need to display this custom attribute.

      – Pritam Info 24
      Nov 28 '18 at 12:33











    • Ordog needs to display every where that means all pages

      – Vignesh Bala
      Nov 28 '18 at 12:35











    • This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

      – Ordog
      Nov 28 '18 at 13:02












    • A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

      – Pritam Info 24
      Nov 28 '18 at 14:37













    3












    3








    3







    You can try with a separate phtml file and layout XML as describe below.



    Assumed "model_number" is the custom attribute that you want to display and your custom theme is "VendorName_customtheme"



    step 1:
    create /app/design/frontend/VendorName/customtheme/Magento_Catalog/layout/catalog_product_view.xml



    File catalog_product_view.xml



    <?xml version="1.0"?> 
    <page layout="1column" 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="MagentoCatalogBlockProductViewAttributes" name="product.mycustom.attribute" as="model_number" template="Magento_Catalog::product/view/custom_attrib.phtml" after="product.info.price" />
    </referenceContainer>
    </body>
    </page>


    step 2: create /app/design/frontend/VendorName/customtheme/Magento_Catalog/templates/product/view/custom_attrib.phtml



    File : custom_attrib.phtml



    <?php
    $_helper = $this->helper('MagentoCatalogHelperOutput');
    $_product = $block->getProduct();
    ?>
    <div class="">
    <?php
    $attribute = $_product->getResource()->getAttribute('model_number');
    if ($attribute)

    $attr_value = $attribute ->getFrontend()->getValue($_product); ?>
    <?= $block->escapeHtml(__('Model no.')). $attr_value ?>
    <?php ?>
    </div>


    step 3: Run this CLI command from your magento root



    sudo rm -rf pub/static/frontend/*


    enter image description here






    share|improve this answer













    You can try with a separate phtml file and layout XML as describe below.



    Assumed "model_number" is the custom attribute that you want to display and your custom theme is "VendorName_customtheme"



    step 1:
    create /app/design/frontend/VendorName/customtheme/Magento_Catalog/layout/catalog_product_view.xml



    File catalog_product_view.xml



    <?xml version="1.0"?> 
    <page layout="1column" 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="MagentoCatalogBlockProductViewAttributes" name="product.mycustom.attribute" as="model_number" template="Magento_Catalog::product/view/custom_attrib.phtml" after="product.info.price" />
    </referenceContainer>
    </body>
    </page>


    step 2: create /app/design/frontend/VendorName/customtheme/Magento_Catalog/templates/product/view/custom_attrib.phtml



    File : custom_attrib.phtml



    <?php
    $_helper = $this->helper('MagentoCatalogHelperOutput');
    $_product = $block->getProduct();
    ?>
    <div class="">
    <?php
    $attribute = $_product->getResource()->getAttribute('model_number');
    if ($attribute)

    $attr_value = $attribute ->getFrontend()->getValue($_product); ?>
    <?= $block->escapeHtml(__('Model no.')). $attr_value ?>
    <?php ?>
    </div>


    step 3: Run this CLI command from your magento root



    sudo rm -rf pub/static/frontend/*


    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 '18 at 12:26









    Pritam Info 24Pritam Info 24

    1,2251 gold badge2 silver badges7 bronze badges




    1,2251 gold badge2 silver badges7 bronze badges












    • I guess it's working product detail page only.

      – Vignesh Bala
      Nov 28 '18 at 12:32











    • Yes. What other places do you need to display this custom attribute.

      – Pritam Info 24
      Nov 28 '18 at 12:33











    • Ordog needs to display every where that means all pages

      – Vignesh Bala
      Nov 28 '18 at 12:35











    • This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

      – Ordog
      Nov 28 '18 at 13:02












    • A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

      – Pritam Info 24
      Nov 28 '18 at 14:37

















    • I guess it's working product detail page only.

      – Vignesh Bala
      Nov 28 '18 at 12:32











    • Yes. What other places do you need to display this custom attribute.

      – Pritam Info 24
      Nov 28 '18 at 12:33











    • Ordog needs to display every where that means all pages

      – Vignesh Bala
      Nov 28 '18 at 12:35











    • This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

      – Ordog
      Nov 28 '18 at 13:02












    • A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

      – Pritam Info 24
      Nov 28 '18 at 14:37
















    I guess it's working product detail page only.

    – Vignesh Bala
    Nov 28 '18 at 12:32





    I guess it's working product detail page only.

    – Vignesh Bala
    Nov 28 '18 at 12:32













    Yes. What other places do you need to display this custom attribute.

    – Pritam Info 24
    Nov 28 '18 at 12:33





    Yes. What other places do you need to display this custom attribute.

    – Pritam Info 24
    Nov 28 '18 at 12:33













    Ordog needs to display every where that means all pages

    – Vignesh Bala
    Nov 28 '18 at 12:35





    Ordog needs to display every where that means all pages

    – Vignesh Bala
    Nov 28 '18 at 12:35













    This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

    – Ordog
    Nov 28 '18 at 13:02






    This is great and certainly a step in the right direction but as @VigneshBala mentioned I need to show this under the prices for Related Products, Upsells and on category pages too.

    – Ordog
    Nov 28 '18 at 13:02














    A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

    – Pritam Info 24
    Nov 28 '18 at 14:37





    A) You may need to override Blocks for Related Products, Upsells Products to show custom attribute. Also need to update phtml with custom code to display product custom attribute. B) To display product custom attribute in category pages, same code will works . Please make sure "Used in Product Listing" Storefront Properties for the custom attribute must set to Yes from Admin panel product attribute section.

    – Pritam Info 24
    Nov 28 '18 at 14:37













    0














    You can access the current product (Magento 2.3.x) within price template phtml using



    $product = $block->getSaleableItem();





    share|improve this answer



























      0














      You can access the current product (Magento 2.3.x) within price template phtml using



      $product = $block->getSaleableItem();





      share|improve this answer

























        0












        0








        0







        You can access the current product (Magento 2.3.x) within price template phtml using



        $product = $block->getSaleableItem();





        share|improve this answer













        You can access the current product (Magento 2.3.x) within price template phtml using



        $product = $block->getSaleableItem();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 18 at 13:42









        pajpaj

        2,6502 gold badges11 silver badges26 bronze badges




        2,6502 gold badges11 silver badges26 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f251616%2fshow-a-product-attribute-under-price-magento-2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?