javascript

Get the attribute value in product page programatically

in Magento_Catalog / template /product/ make a phtml file .

write the below code

$_product = $block->getProduct();
$pi = $_product->getData('giftwrap'); // giftwrap is attribute name 
if($pi==1){ echo "show image";}

Magento_Catalog/layout /catalog_product_view.xml

  <block name="catalog.mygifrwrap"  template="Magento_Catalog::product/giftwrap.phtml" class="Magento\Catalog\Block\Product\View"/>

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 9 =