Created
July 10, 2024 10:58
-
-
Save propertyhive/cf478a9b7b8960b57538fafa26bd78a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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