2

as far as I understand this the price is rendered in:

/app/code/Magento/Catalog/view/base/templates/product/price/amount/default.phtml

But as I change it, it gets, of course, changed for every part of the site (like category view).

How can I change how my price is displayed in my product view? If I for example want to add labels for price incl. tax and excl. tax, tax amount, etc..?

4

In catalog_product_view.xml there is a block (product.price.render.default) which is responsible for price rendering.

That block you can find in below paths:

  1. /vendor/magento/module-catalog/view/adminhtml/layout/CATALOG_PRODUCT_COMPOSITE_CONFIGURE.xml
  2. /vendor/magento/module-catalog/view/base/layout/default.xml

which is this:

<block class="Magento\Framework\Pricing\Render" name="product.price.render.default">
        <arguments>
            <argument name="price_render_handle" xsi:type="string">catalog_product_prices</argument>
            <argument name="use_link_for_as_low_as" xsi:type="boolean">true</argument>
            <!-- set "override" configuration settings here -->
        </arguments>
    </block>

You can copy this block to catalog_product_view.xml inside body tag and change this

<argument name="price_render_handle" xsi:type="string">catalog_product_prices</argument>

to this

<argument name="price_render_handle" xsi:type="string">custom_catalog_product_prices</argument>.

Then create a new xml layout file with name custom_catalog_product_prices.xml and copy content from file /vendor/magento/module-catalog/view/base/layout/catalog_product_prices.xml.

After copy content you can see there is so many template set in this xml layout now you can modify templates according to you in custom_catalog_product_prices.xml file.

  • This does not seem to work, although I am unsure how i should add the template. Just like template="Module_Vendor::product/price/amount/custom.phtml" ? – TrytoFly Jan 23 '18 at 18:03
  • i have updated my answer please check. – dev_67Commerce Jan 24 '18 at 6:39
  • This worked, thank you very much for your help! – TrytoFly Jan 24 '18 at 12:50
  • 1
    there is one more catalog_product_prices.xml in Magento_Tax module, please explore and checke what changes you can append into your own. – dev_67Commerce Jan 29 '18 at 6:07
  • 1
    this seems a long way from the usual "add template in correct location and hope for the best", I'm wondering why .. anyway thank you ! – medmek Sep 21 '18 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.