4

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..?

6

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
  • 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
  • 1
    Agree with medmek's comment. Simply adding override files with the same names, into you own theme will do the trick. In my case, I wanted to change the order of the special and regular price blocks (without css, if possible) and change the 'Regular Price' label to 'Retail Price Was'. To do this, I copied the 'vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml' to my theme, made the text and layout order updates I needed and voila, it works. – Digital_Frankenstein Oct 1 '18 at 14:07

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.