Magento2 Custom Attributes – How to Move Products Attributes Block After Price

attributescustom-attributesmagento2product-attribute

How do I move or show the product attributes currently showing at More Information to after the Price and Availability In Stock.

enter image description here

Here is the piece that shows the product attributes under More Information tab.

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

// @codingStandardsIgnoreFile

/**
 * Product additional attributes template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Attributes
*/
?>
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
?>
<?php if ($_additional = $block->getAdditionalData()): ?>
<div class="additional-attributes-wrapper table-wrapper">
    <table class="data table additional-attributes" id="product-attribute-
specs-table">
        <caption class="table-caption"><?= /* @escapeNotVerified */ __('More 
Information') ?></caption>
        <tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="col label" scope="row"><?= $block-
>escapeHtml(__($_data['label'])) ?></th>
                <td class="col data" data-th="<?= $block-
>escapeHtml(__($_data['label'])) ?>"><?= /* @escapeNotVerified */ $_helper-
>productAttribute($_product, $_data['value'], $_data['code']) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php endif;?>

Best Answer

Create one PHTML file in below location

app\design\frontend\Vendor\theme\Magento_Catalog\templates\product\view\ccolor.phtml

<?php
echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getColor(), 'color'));
?>

Now add your PHTML file in your XML file

app\design\frontend\Vendor\theme\Magento_Catalog\layout\catalog_product_view.xml

<body>
    <referenceBlock name="product.info.main">
        <block class="Magento\Catalog\Block\Product\View" name="ccolor" template="product/view/ccolor.phtml" />
    </referenceBlock>

    <move element="ccolor" destination="product.info.main" after="product.info.price" />
</body>

Flush cache and it should work fine.

Related Topic