Car Demon Code Docs

  1. Home
  2. Car Demon Code Docs

Car Demon Code Docs

The Car Demon PlugIn comes with several filters that developers can leverage.

You’ll find a complete list of these filters in the sidebar menu on this page.

Vehicle Display Filters

If you want to change the visual style of the vehicle listing pages and single vehicle pages you have several options, including creating your own templates page. Creating your own template pages gives you complete control over everything, but in many cases it’s overkill and can be a tedious and time consuming project. A much easier method is to simply filter the default listings.

Here’s a quick list of the filters that are available for modifying the vehicle displays.

apply_filters(‘cd_vdp_filter’, $output, $post_id );
apply_filters(‘cd_srp_filter’, $output, $post_id );

Let’s look at each of these individually.

1. cd_vdp_filter

This filter can be used to modify the Single Vehicle page(s). It sends two arguments; $output and $post_id. The first one contains the original content for the vehicle page and the second is the Post ID for the vehicle.

Here’s a quick example of how to use the filter:

add_filter('cd_vdp_filter', 'my_car_demon_single_car_list',10,2);
function my_car_demon_single_car_list($content,$post_id) {
 // $content is the default vehicle listing
 // $post_id is the id for the vehicle being displayed
 //= Make changes to $content, or replace it completely
 $content = 'My custom content';
 return $content;

2. cd_srp_filter

This filter works exactly the same way the single vehicle filter works. With this filter you’ll be modifying the vehicle search results and archive listings.

When using either of these two filters you might want to take advantage of car_demon_get_car($post_id) function. Just pass the post id and it will return an array containing the majority of the vehicle data that you’ll need. Set it to a variable and use print_r to see everything it returns.

Price Filter

Car Demon has 4 different fields that relate to price. You have the actual selling price, the MSRP field, a field for rebates and an additional field for discounts. Each of these fields is designed to hide if it hasn’t been populated and there’s a place in the settings where you can change the labels for these fields on all vehicles or even individually on a per vehicle basis.

This gives you a lot of power when it comes to the price field, but what if you want to tweak it even further. Maybe you want to add an icon next to the price or you want to change the font size, the color or maybe wrap the price in a custom div.

To give you even more control over the price we’ve added the car_demon_price_filter so you can modify the display any way you want.

This is an excellent place for you to hook into Car Demon to add other information as well.

Here’s a quick example:

add_filter('cd_price_filter', 'my_car_demon_price',10,1);
function my_car_demon_price($price) {
 // $price contains the default price content
 // Now do something to $price, like put it in a custom div
 $price = '<div id="my_div_name">'.$price.'</div>';
 return $price; 

Car Demon Query & Sorting Filters

Let’s say you’ve taken the bold step of adding your own custom field to one of the search forms. Once you have the field added we still need to tell Car Demon to use it. For this purpose we’ve added a filter to the Car Demon Query.

Another common request is give visitors more options to sort their vehicles. To illustrate this situation we’re going to use the car_demon_sort_filter to add a couple new sorting options to Car Demon, then we’ll use car_demon_query_filter to take advantage of them.

To start with let’s make sure that in the Car Demon settings we’ve selected to use the drop down sorting.

//= First let's modify the sorting form
add_filter('cd_sort_filter', 'my_car_demon_sort',10,1);
function my_car_demon_sort($car_demon_sorting) {
 // $car_demon_sorting contains the current sorting content
 //= Put everything on a single line
 $car_demon_sorting = str_replace(chr(10),'',$car_demon_sorting);
 $car_demon_sorting = str_replace(chr(11),'',$car_demon_sorting);
 $car_demon_sorting = str_replace(chr(13),'',$car_demon_sorting);
 //= Search for the sorting drop down
 $start = '<select id="order_by"';
 $stop = '</select>';
 preg_match( '#'.$start.'(.*?)'.$stop.'#', $car_demon_sorting, $form_piece );
 //= If the drop down is found then keep going
 if (isset($form_piece[0])) {
 //= Set the field to a variable so we can edit it
 $drop_down_field = $form_piece[0];
 //= Create a new option to sort by stock number
 $new_option = '<option value="_stock_value">Stock #</option>';
 //= Look for the </select> tag and replace it with $new_option + </select>
 $drop_down_field = str_replace('</select>', $new_option.'</select>', $drop_down_field);
 //= Now search $car_demon_sorting for the original drop down and replace it with our new one
 $car_demon_sorting = str_replace($form_piece[0], $drop_down_field, $car_demon_sorting);
 //= Return the modified sorting form
 return $car_demon_sorting;

//= Now we need to modify the query
add_filter('cd_query_filter', 'my_car_query',10,1);
function my_car_query($car_demon_query) {
 // $car_demon_query contains the current query
 //= Check to make sure order_by was set
 if (isset($_GET['order_by'])) {
 //= Sanitize it and set it to a variable
 $order_by = sanitize_text_field($_GET['order_by']);
 //= Since _stock_value is an existing meta field we can set it like this
 $car_demon_query['meta_key'] = $order_by;
 return $car_demon_query;

The end result is we can now sort our listings by stock number.

Car Demon Sort By

Other Filters

Car Demon also has filters for the Admin Settings and for the Email forms. If you’d like specific information on adding to the settings page or modifying the email forms just let us know. As time permits we’ll try to supply tutorials on these as well.


Was this article helpful to you? Yes 1 No 1

How can we help?