In this FAQ, we provided example of how to customize “Financial form” to add/remove new fields. You can do the same for other custom dealer forms.
Please follow the below steps to customize :
Step 1: Add/Remove form fields ACF field group.
For this, filters are provided for each dealer forms(Except Email to a Friend because we do not have stored data for this form) which you can get from core file for each lead form(Located at “YOUR_INSTALLATION/wp-content/plugins/cardealer-helper-library/includes/acf/fields/”).
For example, for “financial form” use the following filter function where you will get all the fields of financial form, and you can change them as per your need. For your reference, you can take help from existing core the file at “YOUR_INSTALLATION/wp-content/plugins/cardealer-helper-library/includes/acf/fields/financial-form.php”.
add_filter('cardealer_acf_financial_form', 'extend_cardealer_acf_financial_form');
function extend_cardealer_acf_financial_form($args){
// Debug This
// Set "$debug_this" true, to display list of fields
// Make changes into '$args' array and unset fields you want to remove
$debug_this = false;
if( $debug_this ){
echo '<pre>';
print_r($args);
echo '</pre>';
exit;
}
return $args;
}
Step 2: Override the template file of the form
Template file for each form is located at “YOUR_INSTALLATION/wp-content/themes/cardealer/template-parts/cars/single-car/forms/” you can change it as per your need.
For financial form, copy the template file used to build “financial form” located at “YOUR_INSTALLATION/wp-content/themes/cardealer/template-parts/cars/single-car/forms/financial_form.php” and paste it within child theme following the same directory structure. After that, make changes in that child theme template file according to your need.
Step 3: Handle updated post fields of form.
For updated fields, you will need to override the existing code(which is handling the original form fields). Such code is located at “YOUR_INSTALLATION/wp-content/plugins/cardealer-helper-library/includes/dealer_forms”
For override that code, you need to remove actions first(which handles original post fields). You can get actions for each forms from the related core files located at “YOUR_INSTALLATION/wp-content/plugins/cardealer-helper-library/includes/dealer_forms”
For financial form, use the below code in the child theme functions.php file. For your reference, you can take help from existing function “cdhl_financial_form_action” located in the file at “YOUR_INSTALLATION/wp-content/plugins/cardealer-helper-library/includes/dealer_forms/financial_form.php”.
remove_action('wp_ajax_financial_form_action','cdhl_financial_form_action');
remove_action('wp_ajax_nopriv_financial_form_action','cdhl_financial_form_action');
add_action('wp_ajax_financial_form_action','cardealer_child_financial_form_action');
add_action('wp_ajax_nopriv_financial_form_action','cardealer_child_financial_form_action');
function cardealer_child_financial_form_action() {
// Add your code to handle post fields
}
That’s it.