• Resolved intrepid32043

    (@intrepid32043)


    I have 10 vehicles added into Car Demon. When I click on order by price high to low some of the vehicles are out of order. As in a 31,800 priced vehicle is first, a 31,900 vehicle is second, a 31,995 vehicle third and then it starts going down from there: 29,995, 23,995, 21,495, etc.

    If I change the price enough, lets say the 31,995 I change to 32,000 it will go in the correct order, but the 31,800 and 31,900 are still out of order. Plus, I don’t really want to have to adjust the prices to make it work, I would rather it work with the prices I give it.

    If I order by low to high it displays everything correctly.

    If I go into PHPMyAdmin and look up the _price_value I can order them correctly by meta_value.

    Also, if I remove the commas from the value then it will order them correctly, but I like the look of the price with a comma.

    Here is the car listing page – https://ultimateridesonline.com/uro/cars-for-sale/?order_by=_price_value&order_by_dir=desc

    Anyone have any ideas?

    Thank you.

    https://www.ads-software.com/plugins/car-demon/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author theverylastperson

    (@theverylastperson)

    You can add a filter to your theme’s function.php that can add the comma back into your prices without changing the sort order.
    First you’ll need to remove all the commas from your prices.

    Next you’ll want to add your filter.
    Here’s a really quick example that should work for US based prices.
    If you’re located elsewhere you might need to modify this to meet your purposes.

    // Add a filter to car_demon_price_filter
    add_filter('car_demon_price_filter', 'my_price',10,1);
    function my_price($price) {
    	// $price contains the current price HTML
    	// create a regular expression to search for the 'final price'
    	$regex = '#\<div id="your_price" class="car_final_price"\>(.+?)\<\/div\>#s';
    	// search for our regular expression
    	preg_match($regex, $price, $matches);
    	// assign our result to a variable
    	$asking_price_original = $matches[1];
    	// remove the $ from price - assuming you're in the states, if you're else you may use a different currency symbol
    	$asking_price = str_replace('$', '', $asking_price_original);
    	// make sure this is a number
    	if (is_numeric($asking_price)) {
    		// format it by adding the currency symbol back to it, then use number_format to add the comma
    		$asking_price = '$'.number_format($asking_price, 0);
    		//replace the original price with the new $asking_price in the $price variable
    		$price = str_replace($asking_price_original, $asking_price, $price);
    	}
    	// return our modified price
    	return $price;
    }

    You can learn more about the different Car Demon filters here;
    https://cardemons.com/2015/03/13/car-demon-filters/

    Let us know if this works for you.

    -j

    Thread Starter intrepid32043

    (@intrepid32043)

    That worked great. Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Order by price High to Low not working correctly’ is closed to new replies.