Add field to listing contact form

This article provides instructions for how to add a phone number to the Listing Contact form. The code could be different for what you might want to do.

To accomplish this with Business Directory Plugin, you will follow the instructions at the top of the developer hooks page.

/* Puts the field on the contact form at the bottom */
function example_add_custom_contact_field() {
  echo '<p>Phone Number: <input type="text" name="phone-number" /></p>';
add_action( 'wpbdp_contact_form_extra_fields', 'example_add_custom_contact_field' );

/* Validates the field if necessary */
function example_validate_custom_contact_field( $errors ) {
  if ( empty( $_POST['phone-number'] ) ) {
    $errors['phone-number'] = 'Phone number is required!';
  return $errors;
add_filter( 'wpbdp_contact_form_validation_errors', 'example_validate_custom_contact_field' );

/* Adds the field to the body of the contact email sent to the listing owner */
function example_add_custom_contact_field_to_email( $body ) {
  if ( isset( $_POST['phone-number'] ) ) {
    $body .= "\n\n";
    $body .= 'Phone Number: ';
    $body .= sanitize_text_field( $_POST['phone-number'] );
  return $body;
add_filter( 'wpbdp_contact_form_email_body', 'example_add_custom_contact_field_to_email' );

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support