EDD Support Tickets

Add a Custom Field To The Ticket Submission Form

You can add a custom field to the ticket submission form by calling the function eddstix_add_custom_field(). The function takes two parameters:

  1. a unique field ID
  2. an array of arguments

This example adds a text field labeled, “Phone.” You can replace “Phone” on line 13 with your desired field label.

/**
 * Add a custom field to the ticket submission form. 
 * 
 * The field will also show on the Edit Ticket page in the back end. 
 */
add_action( 'init', 'my_eddstix_add_custom_field' );

function my_eddstix_add_custom_field() {

	if ( function_exists( 'eddstix_add_custom_field' ) ) {

		eddstix_add_custom_field( 'my_custom_text_field',  array(
			'title' => __( 'Phone', 'textdomain' )
			)
		);

	}
}

The field above will also be displayed on the Edit Ticket page in the back end. However, if you also want to display the field in a column in the admin tickets list, and also on a column on the front end customer’s view, then you’ll need to add the show_column argument like this (the only difference here is line 16):

/**
 * This example adds a 'show_column' argument.
 * 
 * This adds a custom field to the ticket form, just like above,
 * and also adds an argument to show the field column in the ticket list
 * on front end and back end.
 */
add_action( 'init', 'my_eddstix_add_custom_field' );

function my_eddstix_add_custom_field() {

	if ( function_exists( 'eddstix_add_custom_field' ) ) {

		eddstix_add_custom_field( 'my_custom_text_field',  array(
			'title' => __( 'Phone', 'textdomain' ),
			'show_column' => true
			)
		);

	}
}

By default, the type of field will be a text field. You can change the field type with the callback argument. The possible choices for the callback argument are ‘text’ (default), ‘textarea’, ‘url’, or ‘taxonomy’.

The following example adds a textarea field by setting the callback argument to ‘textarea’ on line 11.

/**
 * This adds a custom field to the ticket form, but 
 * it is a textarea instead of just a text field.
 */
add_action( 'init', 'my_eddstix_add_custom_field' );
function my_eddstix_add_custom_field() {
	if ( function_exists( 'eddstix_add_custom_field' ) ) {

		eddstix_add_custom_field( 'my_custom_textarea_field',  array(
			'title' => __( 'My Tax Field', 'textdomain' ),
			'callback' => 'textarea'
			)
		);

	}
}

You can add a ‘taxonomy’ field by setting the callback argument to ‘taxonomy’. If you add a taxonomy field, you’ll then have to add terms to this new taxonomy in your WordPress dashboard. You’ll see a new menu item for your new taxonomy under the Tickets menu. After you add some terms to the new taxonomy, they’ll appear in a select box on the ticket submission form. The customer will then be able to select one from this custom taxonomy while filling out the submission form.

If you add multiple fields, make sure that each field has its own unique ID. The ID is the first parameter of the eddstix_add_custom_field() function. The following example adds 2 custom fields. Notice that each field has its own unique ID on lines 7 and 14.

add_action( 'init', 'my_eddstix_add_custom_field' );
function my_eddstix_add_custom_field() {
	if ( function_exists( 'eddstix_add_custom_field' ) ) {

		// Custom Text field

		eddstix_add_custom_field( 'my_custom_phone_field',  array(
			'title' => __( 'Phone', 'textdomain' ),
			)
		);

		// Custom Taxonomy field

		eddstix_add_custom_field( 'my_custom_taxo_field',  array(
			'title' => __( 'My Custom Taxonomy Field', 'textdomain' ),
			'callback' => 'taxonomy'
			)
		);

	}
}

To make a custom field required on the ticket submission form, add this argument to the array of arguments:

'required' => true

For example, the following text field will be required to be filled out on the ticket submission form (see line 9):

add_action( 'init', 'my_eddstix_add_custom_field' );

function my_eddstix_add_custom_field() {

	if ( function_exists( 'eddstix_add_custom_field' ) ) {

		eddstix_add_custom_field( 'my_custom_text_field',  array(
			'title' => __( 'Phone', 'textdomain' ),
			'required' => true
			)
		);

	}
}

Updated on December 6, 2017

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]