If you’re using Tripzzy, a popular WordPress plugin for managing travel bookings, you may want to customize the enquiry form to collect more information from your customers. One common request is adding a phone number field to the form, which can help improve communication with clients during the booking process.
While Tripzzy currently doesn’t support adding custom fields directly through the settings, you can easily extend the functionality with a bit of code customization. In this guide, we’ll show you how to add a phone number field to your Tripzzy enquiry form by modifying your theme’s functions.php
file.
Requirements #
Before we dive into the customization, make sure you’re using Tripzzy version 1.1.7 or later. This version includes the necessary hooks and filters to modify the enquiry form fields.
Adding a Phone Number Field to the Enquiry Form #
Follow these simple steps to add a phone number field:
Step 1: Create a Child Theme (If You Don’t Have One) #
First, you should always add custom code to a child theme to ensure that future theme updates don’t overwrite your changes. If you’re not using a child theme yet, create one by following these steps:
- Navigate to your WordPress installation folder via FTP or your hosting file manager.
- Open the
wp-content/themes/
directory. - Create a new folder and name it
your-theme-child
(replaceyour-theme
with your current theme’s name). - Inside the folder, create a
style.css
file and afunctions.php
file. - In the
style.css
file, add the following header information:/*
Theme Name: Your Theme Child
Template: your-theme
*/
- In the
functions.php
file, add this code to enqueue the parent theme’s styles:<?php
function your_theme_child_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'your_theme_child_enqueue_styles' );
Step 2: Add the Custom Code #
Once you’ve set up the child theme, you can proceed with adding the phone number field to the enquiry form.
- Open your child theme’s
functions.php
file. - Add the following code to customize the Tripzzy enquiry form:
add_filter(
'tripzzy_filter_enquiry_form_fields', function ( $fields ) {
$fields['phone_no'] = array(
'type' => 'text',
'label' => __('Phone Number'),
'name' => 'phone_no',
'id' => 'phone-no',
'class' => 'phone-no',
'placeholder' => __('Your Phone Number'),
'required' => true,
'priority' => 35,
'value' => '',
'is_new' => false,
'is_default' => true,
'enabled' => true,
'force_enabled' => true,
);
return $fields;
}
);
Step 3: Save and Test #
After adding the code, save the functions.php
file and upload it back to your server (if you’re working locally). Next, clear your site cache and browser cache to ensure the changes take effect immediately.
Now, navigate to your site’s enquiry form, and you should see the new phone number field added to the form.
How This Code Works #
The code uses the tripzzy_filter_enquiry_form_fields
filter to modify the existing enquiry form fields. Here’s a breakdown of what each part of the code does:
- type: Defines the type of the field, which is set to
text
. - label: The label that appears next to the field, in this case, “Phone Number.”
- name and id: These are used to identify the field in the form and in the HTML structure.
- class: Adds a CSS class to the field, useful for custom styling.
- placeholder: The placeholder text that appears inside the field.
- required: Setting this to
true
makes the field mandatory. - priority: Determines the order of the field in the form.
- enabled: Ensures the field is visible and active in the form.
Conclusion #
Customizing the Tripzzy enquiry form is a straightforward process with the right code snippet. By adding a phone number field, you can enhance communication with your customers and gather essential information right from the enquiry stage. This is especially useful for follow-ups or handling special requests.
If you encounter any issues or need further assistance, feel free to reach out to us. We value your feedback and are always looking to improve the Tripzzy plugin.
Happy customizing!