Skip to content

Commit db8943f

Browse files
gpapf-save-national-format.php: Added new snippet.
`gpapf-save-national-format.php`: Added new snippet. Co-authored-by: Saif Sultan <[email protected]>
1 parent 5a8881b commit db8943f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Advanced Phone Field // Save Phone Number In National Format
4+
* https://gravitywiz.com/documentation/gravity-forms-advanced-phone-field/
5+
*
6+
* Save the phone number in the national format, rather than international.
7+
*
8+
* For example, rather than a US number saving as +15555551234, the number would be saved as (555) 555-1234.
9+
*/
10+
// Update "123" to your form ID and "4" to your Phone field ID.
11+
add_action( 'gform_save_field_value_123_4', function( $value, $entry, $field, $form, $input_id ) {
12+
13+
if ( ! is_callable( 'gp_advanced_phone_field' ) || ! class_exists( '\libphonenumber\PhoneNumberUtil' ) ) {
14+
return $value;
15+
}
16+
17+
$proto = gp_advanced_phone_field()->get_phone_number_proto( $value );
18+
$phone_number_util = \libphonenumber\PhoneNumberUtil::getInstance();
19+
if ( ! $proto ) {
20+
return $value;
21+
}
22+
return $phone_number_util->format( $proto, \libphonenumber\PhoneNumberFormat::NATIONAL );
23+
24+
}, 10, 5 );

0 commit comments

Comments
 (0)