How to Use a Custom Price Template in Magento 2

Hello Magento buddies 🤘🏻

I am back with another blog post on how to use a custom price template in Magento 2.

Magento is incredibly impressive eCommerce platform, isn’t it? It allows high-end customization and the creation of storefronts, as we imagine. It truly empowers the store owners to tweak every minute details of the storefront including the price tag shown on various pages. As an enthusiastic store owner, you may want to use a custom price template in Magento 2 and change the look of the price tag to better match your Magento store’s theme.

Recently, I came across one such requirement of customizing the price template in Magento 2 for one of our clients and found the solution. In this blog post, I will share with you the complete solution to using a custom price template in Magento 2.

So, let’s begin!

Methods to Use Custom Price Template in Magento 2

To use a custom price template in Magento 2, we need to override the final_price.phtml file in Magento 2 with the custom template. It can be done in two ways:

  1. Override Template File Directly in Theme
  2. Change Template File in Custom Extension

1. Override Template File Directly in Theme

You can change the final_price.phtml directly in the vendor folder of the Magento source code. But, directly tweaking the source code of the Magento 2 is not advisable at all. Also, the changes can get reverted back in case of a Magento version upgrade. In order to prevent such reversal, it is advisable to override the template fine in the vendor folder by that in the theme.

Override the following path of the price template:

with

That’s it!

2. Change Template File in Custom Extension

If you are using a custom extension that tweaks the pricing layout in Magento 2; you can create a custom module to override the price layout file in Magento 2. Follow the below steps if you want to use a custom price template in Magento 2 using a custom extension.

Step 1: Create app/code/Vendor/Extension/etc/di.xml with the following code:

Step 2: Create app/code/Vendor/Extension/Plugin/FinalPricePlugin.php with the following code:

Step 3: Create final_price.phtml file at app/code/Vendor/Extension/view/frontend/templates/product/price/ and add your desired code for the price layout template.

That’s it.

Any doubts about the above method can be mentioned in the Comments section below. 😇

Also, do share the solution with the Magento community via social media. 😃

Thank you. 🍀

5
(based on 7 Reviews)
How to Use a Custom Price Template in Magento 2Author Magento Badge

Jignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.

Leave a Reply

Your email address will not be published.