0

We are running on Magento 2.3 and I want to remove the currency symbol from the product price and also remove the decimals when the price is .00

How can we achieve that?

I already changed the file: app/design/frontend/{{namespace}}/{{theme_name}}/Magento_Catalog/templates/product/price/amount/default.phtml to:

<?php /* @escapeNotVerified */ $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer(), 0) ?>

That works fine for the productlist page, but not the productpage.

Updating /vendor/magento/module-catalog/view/base/web/js/price-utils.js to var precision = 0, does not work well, because all prices do not have decimals in that case. But we only want to remove the decimals when the price is .00

How can we achieve that and also remove the currency symbol?

1 Answer 1

2

I am not sure what you want is this but check it.

For the product page I think you can look at vendor/magento/module-catalog/view/base/web/js/price-box.js

and around line no 149 you will see price.formatted = utils.formatPrice(price.final, priceFormat);

You check it in console.log(price.formatted); it will show the string which is displaying at the product page.

So you can change it as your requirement like below.

price.formatted = utils.formatPrice(price.final, priceFormat);
price.formatted = price.formatted.replace("$", "");
price.formatted = price.formatted.replace(".00", "");

Note : You should not change the core file

3
  • Many thanks! That works perfectly on the productpage. The only problem I now still have, is that the currency symbol on the categorylist page is stil displayed. Any idea how to edit app/design/frontend/{{namespace}}/{{theme_name}}/Magento_Catalog/templates/product/price/amount/default.phtml?
    – JGeer
    Commented Feb 1, 2019 at 7:49
  • And when the page load, it first load the default price displayed with ,00 and currency symbol and that will be replaced within a few honderd mili seconds. But is there a way to display the price by default in this new form?
    – JGeer
    Commented Feb 1, 2019 at 8:10
  • @HenkZ I fixed that display stuff on other pages with the same JavaScript but in a different file that loads on all pages. That's easy enough to set up because (as far as I know) only the price on the productpage get's rendered by KnockoutJS.
    – Asitis
    Commented Oct 4, 2019 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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