Jump to content

Price decimals style in Prestashop 1.7.8.8


cristidam

Recommended Posts

Hello,

I would like to display the price decimals in the following style: image.png.018d24afce12cb4b9400f3be5259b0fd.png

I have updated classes/Tools.php, by adding <sup> tag to the decimals, but on the frontend the html gets converted to text an it shows 499<sup>00</sup>.

I have found an older post that gives a solution but it's for PS 1.6.

https://www.prestashop.com/forums/topic/557593-productprice-smaller-font-behind-the-comma/

Can someone help me with this issue?

Thank you!

 

Link to comment
Share on other sites

9 hours ago, ps8moduly.cz said:

Hi.

It needs to be added wherever the price parameter is nofilter.

For example: {$product.price nofilter}

Hi,

Thank you. This works fine, it's just that it's a lot of work to modify the decimal style everywhere. I was wondering if there is a way to add the <sup> element directly where the $product.price is formatted, I just can't find the file.

Thank you!

 

Link to comment
Share on other sites

  • 4 months later...
On 11/7/2023 at 4:19 PM, cristidam said:

Hi,

Thank you. This works fine, it's just that it's a lot of work to modify the decimal style everywhere. I was wondering if there is a way to add the <sup> element directly where the $product.price is formatted, I just can't find the file.

Thank you!

 

Hi,

Did you manage to fix this? I want the same price format effect for my prestashop 1.7

Thank you

 

Link to comment
Share on other sites

  • 1 year later...

Hi,

Here is the code to put in your theme's custom.js file:

document.addEventListener("DOMContentLoaded", function () {
	const priceElements = document.querySelectorAll(".current-price-value, .price");

	priceElements.forEach(el => {
		let text = el.textContent.trim();
		const regex = /(\d{1,3}(?:[.,'\u00A0]\d{3})*|\d+)[.,](\d+)/;
		const match = text.match(regex);
		if (match) {
			const integerPart = match[1];
			const decimalPart = match[2];
			const formattedNumber = `${integerPart}<sup>${decimalPart}</sup>`;
			el.innerHTML = text.replace(regex, formattedNumber);
		}
	});
});

And here is the code to put in your theme's custom.css file:

sup {
	font-size: 0.6em;
	vertical-align: top;
	position: initial;
	line-height: inherit;
}

 

Link to comment
Share on other sites

10 hours ago, Mediacom87 said:

Hi,

Here is the code to put in your theme's custom.js file:

document.addEventListener("DOMContentLoaded", function () {
	const priceElements = document.querySelectorAll(".current-price-value, .price");

	priceElements.forEach(el => {
		let text = el.textContent.trim();
		const regex = /(\d{1,3}(?:[.,'\u00A0]\d{3})*|\d+)[.,](\d+)/;
		const match = text.match(regex);
		if (match) {
			const integerPart = match[1];
			const decimalPart = match[2];
			const formattedNumber = `${integerPart}<sup>${decimalPart}</sup>`;
			el.innerHTML = text.replace(regex, formattedNumber);
		}
	});
});

And here is the code to put in your theme's custom.css file:

sup {
	font-size: 0.6em;
	vertical-align: top;
	position: initial;
	line-height: inherit;
}

 

hi Sir thank yo ufor your reply!

i have uploaded the first part in /theme/asses/js/custom.js     and the css code in the css file,  deleted cache, but unfortunately nothing has changed, can you help me proceed please

Link to comment
Share on other sites

Il y a 14 heures, jwd19 a dit :

hi Sir thank yo ufor your reply!

i have uploaded the first part in /theme/asses/js/custom.js     and the css code in the css file,  deleted cache, but unfortunately nothing has changed, can you help me proceed please

URL of your site ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...