1. Introduction
  2. Getting Started
    1. Installation
    2. Sample Data
  3. Theme Update
  4. Car Dealer Templates
  5. Front Submission
    1. FAQ
  6. Attributes
    1. Attributes Guide
  7. Addons
  8. Theme Settings
    1. General Settings
      1. Site Layout
      2. Site Logo
      3. Back To Top
      4. Site Preloader Option
      5. Site Header
      6. Topbar
      7. Search
      8. Page Header
      9. Site Footer
      10. Color Scheme
      11. Sidebar Settings
      12. Google API
      13. MailChimp API
      14. Performance
      15. Maintenance
    2. Inventory Settings
      1. Inventory Page
      2. Detail Page
      3. Detail Page (Mobile)
      4. Currency Settings
      5. Vehicles Listing Filters
      6. Vehicle Compare
      7. CarGurus Settings
      8. Export Vehicle Detail
      9. Geo Fencing Settings
      10. VINquery VIN Settings
    3. Lead Forms
      1. Request More Info
      2. Make an Offer
      3. Schedule Test Drive
      4. Email To Friend
      5. Financial Form
      6. Trade-In Appraisal
      7. All Forms - Field Labels
    4. Front Submission
      1. General Settings
      2. Page Settings
      3. Dashboard Endpoints
      4. Add Car Form Sections
      5. Additional Attributes
      6. Wishlist
      7. Dealer Review
      8. Advertise Item
      9. Listing Payment
    5. Page Layouts
      1. Blog Settings
      2. Archive Settings
      3. Single Post
      4. Team Page Settings
      5. Testimonials Settings
      6. 404 Page
    6. Woocommerce Settings
    7. Site Info/Social Sharing
      1. Site Contacts
      2. Social Profiles
      3. Social Sharing
    8. Custom Typography
    9. Custom CSS/JS
    10. Sample Data
    11. Team Page Template Setting
    12. FAQ Page Template Settings
  9. WPBakery Shortcodes/Elementor Widgets
    1. Vehicles Carousel / Vehicles List
    2. Promo Code
    3. Promo Code Image
    4. Testimonials
    5. Buttons
    6. Space
    7. Feature Box
    8. Feature Box Container / Feature Box Slider
    9. Counter
    10. Recent Posts
    11. Our Team
    12. Section Title
    13. Social Icons
    14. Quick Links
    15. Timeline
    16. Call To Action
    17. Multi tabs
    18. Custom Filters
    19. Clients
    20. Opening Hours
    21. Icon
    22. Newsletter
    23. List
    24. Image Slider
    25. Verticular Multi Tabs
    26. Video
    27. Video Slider
    28. Vehicles Search
    29. Vehicles Conditions Tabs
    30. Vehicles By Type
    31. Potenza Share
    32. Custom menu
  10. Theme Translation
    1. Translate with Poedit
    2. Translate with Loco Translate
    3. Translate with WPML Plugin
  11. Extra
    1. VINquery Decoder
    2. Vehicles Compare Functionality
    3. Financing Calculator
    4. Vehicles Category
    5. GEO fencing
    6. Promo Code
    7. Website Optimization
    8. Vehicle Review Stamps
    9. Dealer Inquiry Forms
    10. Import Functionality
      1. WP All Import
      2. Vehicle CSV Import
    11. Export Functionality
    12. PDF Generator
    13. Pricing Packages Plan (with Subscriptio Plugin)
    14. Sell Vehicle
    15. CarGurus Rating Badges
    16. GDPR Compliance
    17. Browser Support
    18. Retina Display
    19. How to rate this item
    20. WooCommerce / Shop integration
    21. Plugins Documentation
    22. Image Size
    23. Google Analytics
    24. Car Dealer 3.7.0
  12. FAQs
    1. How to add Custom Fields
    2. How to Remove Vehicle Attributes/Fields from Vehicle Details Page?
    3. WPALLIMPORT or ALLIMPORT common mistakes
    4. WebManager Integration
    5. How to make sold vehicle page?
    6. How to edit footer contents?
    7. Unable to Import Sample Data
    8. Got a Query?
    9. How do I contact support when support system down?
    10. How to Fix Outdated WooCommerce Templates?
    11. Getting Limit Error on Purchase Code Activation?
    12. How To Hide Out of Stock Products?
    13. Sample Data Look Different than Demo Pages?
    14. Enable WPBakery Page Builder in Posts and Custom Post Types?
    15. Missing style sheet error when installing the theme
    16. Unable to Save Page with WPBakery Page Builder
    17. Unable to use WP bakery page builder after WordPress update.
    18. Change the image of Sold Car?
    19. Translate car attributes in different language?
    20. Disable "Add Car" button from menu?
    21. How to change "Add Car" button text?
    22. Use Contact form 7 instead of Custom forms in Car detail page?
    23. Remove required field validation from Front End Car Submission form?
    24. Add/remove filters on the inventory page?
    25. Display Address and Phone number in the TopBar?
    26. Order the attributes on the car detail page?
    27. How to use "Pricing Plan" feature of Car Dealer theme?
    28. Why are all homepage demos not displayed until I install the default demo?
    29. Edit Inventory page with WpBakery/Elementor
    30. How to Fix a 403 Forbidden Error
    31. How to add a logo in the Make/Body Style attribute?
    32. Edit "Home Listing" Page
  13. Source & Credits
  14. Videos
  15. Downloads
  16. Changelog

How to add Custom Fields

Along with the Inventory section, the theme comes with various other sections (like Testimonials, Teams, FAQs, etc.) in the admin panel. All these sections contain custom fields to manage various data.

If you have a custom requirement and want to add the custom field(s) in inventory or other sections, you can use WordPress’s filter hooks to extend the existing fieldsets. All the fieldsets for all different sections contain a filter hook so that users can extend them by hooking a custom function.

You can find the filter hooks for each field-sets in their relevant code files, and code files are located at the below path.

WORDPRESS_ROOT\wp-content\plugins\cardealer-helper-library\includes\acf\fields

So, for example, if you want to add custom fields in the Inventory items, you will have to hook your custom function (with new fields definition/parameters) to the “cardealer_acf_car_data” filter tag, which is available in the “car-data.php” file (path of this file is given below).

WORDPRESS_ROOT\wp-content\plugins\cardealer-helper-library\includes\acf\fields\car-data.php

Advanced Custom Fields Pro (ACF)

We are using Advanced Custom Fields Pro (ACF) plugin to add fields in the backend. So, you can add new fields by registering new fieldsets using the ACF API. Please refer to the below documents for detailed information about registering new field(s) and available parameters for different field types.

Here is the sample code, in which we hooked a custom function to the “cardealer_acf_car_data” filter tag and added two “text” fields in the inventory items. Note that the below-provided code is just a sample code; you can customize it as per your requirements to add more fields and details. To add more field types, please refer to the ACF documentation links provided above.

function cardealer_child_extend_car_data_fieldset( $fieldset ){

  // Get old fields
  $old_fields = $fieldset['fields'];

  // prepare new fields
  $new_fields = array(

    /*--------------------------------------------------------------------
     * ADD YOUR NEW FIELD CODE INFORMATION BELOW
     *
     * DO NOT TOUCH CODE ABOVE
     *--------------------------------------------------------------------*/
     
    // Add Tab
    // This is must required to separate newly added fields from existing fields.
    array (
      'key'          => 'field_3a55ba3715a94c809a00866c8c55816a',
      'label'        => esc_html__('Custom Fields','theme-textdomain'),
      'name'         => '',
      'type'         => 'tab',
      'instructions' => '',
      'placement'    => 'left',
      'endpoint'     => 0,
    ),
    
    // Minimal Field Parameters
    array (
      // The value of the "key" parameter must be unique key containing alphanumeric characters. Do not leave it blank.
      // Use "https://www.uuidgenerator.net/version4" to generate unique key.
      'key'              => 'field_0d85650130514845b98b425f8ae34aa0',
      'label'            => esc_html__( 'Custom Field 1', 'theme-textdomain' ),
      'name'             => 'custom_field_name_1',
      'type'             => 'text',
    ),
    
    // Full Field Parameters
    // For detailed information about available parameters of different field types, please refer ACF's field type docuements.
    // https://www.advancedcustomfields.com/resources/#field-types.
    array (
      // The value of the "key" parameter must be unique key containing alphanumeric characters. Do not leave it blank.
      // Use "https://www.uuidgenerator.net/version4" to generate unique key.
      'key'              => 'field_770597ed1dbb4eba84294a63542da105', 
      'label'            => esc_html__( 'Custom Field 2', 'theme-textdomain' ),
      'name'             => 'custom_field_name_2',
      'type'             => 'text',
      'prefix'           => '',
      'instructions'     => '',
      'required'         => 0,
      'conditional_logic'=> 0,
      'wrapper'          => array (
        'width'=> '',
        'class'=> '',
        'id'   => '',
      ),
      'default_value'=> '',
      'placeholder'  => '',
      'prepend'      => '',
      'append'       => '',
      'maxlength'    => '',
      'readonly'     => 0,
      'disabled'     => 0,
    ),

    /*--------------------------------------------------------------------
     * ADD YOUR NEW FIELD CODE INFORMATION ABOVE
     *
     * DO NOT TOUCH CODE BELOW
     *--------------------------------------------------------------------*/

  );

  $merged_fields      = array_merge( $old_fields, $new_fields ); // Merge old and new fields.
  $fieldset['fields'] = $merged_fields;                          // Assign fields back to field-set.

  return $fieldset; // Return field-set.
}
add_filter( 'cardealer_acf_car_data', 'cardealer_child_extend_car_data_fieldset' );

Display Above Added Field Data on the Vehicle Detail Page

The above code will display the newly added field in the admin panel. If you want to display the newly added field(s) data on the vehicle details page on the front side, you will have to add field(s) data by hooking custom function to the “cardealer_car_attributes” filter hook.

Here is the sample code to display the above-added field’s data on the vehicle details page. You can add the below sample code in the child theme’s functions.php. And, in child-theme, the path of the functions.php should look like the path given below.

WORDPRESS_ROOT\wp-content\themes\cardealer-child\functions.php

function cardealer_child_extend_details_on_vehicle_detail_page( $attributes, $post_id ){

  // Debug This
  // Set "$debug_this" true, to display full list of available attribute keys (including attributes/fields).
  $debug_this = false;
  if( $debug_this ){
    echo '<pre>';
    print_r($attributes);
    echo '</pre>';
    exit;
  }

  // You can add new attributes like this
  /*
  $attributes[ 'attribute_key' ] = array(
    'attr' => esc_html__( 'Attribute Name', 'theme-textdomain' ),
    'value' => esc_html__( 'Attribute Value', 'theme-textdomain' ),
  );
  */
  // Here is the detai of parameters in above code.
  // attribute_key = Unique Attribute Key in small letters, without space and spacial character.
  // attr          = Attribute Name
  // value         = Attribute Value

  $custom_field_name_1 = get_field( 'custom_field_name_1', $post_id );
  if ( $custom_field_name_1 && ! empty( $custom_field_name_1 ) ) {
    $attributes[ $custom_field_name_1 ] = array(
      'attr'  => esc_html__( 'Custom Field 1', 'theme-textdomain' ),
      'value' => esc_html( $custom_field_name_1 ),
    );
  }

  $custom_field_name_2 = get_field( 'custom_field_name_2', $post_id );
  if ( $custom_field_name_2 && ! empty( $custom_field_name_2 ) ) {
    $attributes[ $custom_field_name_2 ] = array(
      'attr'  => esc_html__( 'Custom Field 2', 'theme-textdomain' ),
      'value' => esc_html( $custom_field_name_2 ),
    );
  }

  /*--------------------------------------------------------------------
  * ADD YOUR CODE ABOVE
  *
  * DO NOT TOUCH CODE BELOW
  *--------------------------------------------------------------------*/
  return $attributes;
}
add_filter( 'cardealer_car_attributes', 'cardealer_child_extend_details_on_vehicle_detail_page', 10, 2 );
Suggest Edit