WPSuperDealer

Changing Price Formats

Changing your price format

By default WPSuperDealer displays price and mileage fields as straight numbers with no actual formatting.

That means they look like this: $32500 and not $32,000 or $32.000 or any of the other formats you might find around the world.

Why isn’t this an option and how are you supposed to format them? Both are good questions.

It’s not an option, yet, because price formatting is complicated, especially when you consider the wide world and all the different ways prices are formatted.

This is on our roadmap for the future, but unless someone wants to be a hero and sponsor adding it then it might be awhile before there’s an integrated option built in.

Until then you can get sneaky and leverage a couple PHP filters to format the prices exactly the way you want. It’s not nearly as hard as it sounds and if you follow the simple steps below you’ll not only have your prices and/or mileage values formatted but you’ll also learn a couple cool tricks and since knowledge is power you can consider this a booster to your arsenal.

Step One

Install & Activate the “Code Snippet” PlugIn – Free from WordPress.org

Step Two

Go to Dashboard->Snippets->Add New:

Step Three

For title enter: WPSD Price Filter

Peel back the Code behind the Mask

Step Four

In the code section enter the following:

				
					

function my_wpsd_price_filter( $price ) {
	if ( is_numeric( $price ) ) {
		$price = intval( $price );
		//= number_format(number,decimals,decimalpoint,separator)
		$price = number_format( $price, 0, '', ',' );
	}
	print_r( 'huh' );
	return $price;
}
add_filter( 'wpsd_price_format', 'my_wpsd_price_filter', 11, 1 );

				
			

See line #5 and the number_format() stuff? That’s the little line of code that actually formats the number.

That function can be used to do all kinds of different formats, so you can make your prices exactly the way you want.

You can learn more about number_format() and the ways to use it here:
w3schools.com |  number_format

Step Four

Select: Only run on the site front-end

Step Five

Click the button “Save Changes and Activate”

Step Six

Cross fingers and check your prices!

Step Seven

Party like it’s 1999 because you just gained a new power, the ability to format your prices!

Eventually we’ll get around to adding an easy to use control to give everyone the ability to format prices a bit easier.

Until then we hope this information has proven useful and gives you the power you need to make your project exactly what you want.

If you’re interested in sponsoring this, or another new feature in WPSuperDealer, then fill out our contact form below and let us know.

Questions?

Send us a message

Built by the Heroes at

WPSuperTeam.com

Unleash your Hidden Hero!