问题描述
请帮助我如何在 magento2 平台的产品页面上显示原始产品价格后的标签“包含所有税费”?
还要让我知道文件结构,我可以在其中轻松添加 HTML 代码以显示相同的内容。
请参阅屏幕截图以供参考:https://prnt.sc/10hqx9e
<div class="product-info-price"><div class="price-Box price-final_price" data-role="" data-product-id="" data-price-Box=""><span class="label-taxes"><label>Inclusive of all taxes</label></span></div></div>
上面的代码只是一个虚拟代码,但我使用了产品页面magneto2的默认div结构。
请帮忙!
提前致谢。
解决方法
首先如果您只想在产品视图页面中显示自定义文本,则在路径 app/design/frontend/Your-theme/theme/Magento_Catalog/layout/catalog_product_view.xml 上的自定义主题中创建 catalog_product_view.xml
添加此代码
<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>
现在在路径 app/design/frontend/Your-theme/theme/Magento_Catalog/templates/view/customtext.phtml 上创建 customtext.phtml 文件
添加以下代码
<div class="product-info-price">
<div class="price-box price-final_price">
<span class="label-taxes">
<label><?php echo __("Inclusive of all taxes") ?></label>
</span>
</div>
</div>
不要忘记清除缓存:)