Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save propertyhive/cf478a9b7b8960b57538fafa26bd78a2 to your computer and use it in GitHub Desktop.
Save propertyhive/cf478a9b7b8960b57538fafa26bd78a2 to your computer and use it in GitHub Desktop.
add_filter( 'propertyhive_user_details_form_fields', 'split_out_tel_in_reg_form' );
function split_out_tel_in_reg_form($fields)
{
// Step 1: Split the array at the position where the new element needs to be inserted
$position = array_search('telephone_number', array_keys($fields));
$before = array_slice($fields, 0, $position, true);
$after = array_slice($fields, $position, null, true);
// Step 2: Define the new element
$new_element = array(
'telephone_number_code' => array(
'type' => 'text',
'label' => __( 'Telephone Number Code', 'propertyhive' ),
'show_label' => true,
'before' => '<div class="control control-telephone-number-code">',
'required' => false
));
// Step 3: Merge the arrays together with the new element in the correct position
$fields = array_merge($before, $new_element, $after);
if ( isset($_POST['telephone_number_code']) && isset($_POST['telephone_number']) )
{
$_POST['telephone_number'] = $_POST['telephone_number_code'] . ' ' . $_POST['telephone_number'];
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment