Last active
January 21, 2022 12:28
-
-
Save cartimize/76a0757031ec109ea8a22ef205644bb6 to your computer and use it in GitHub Desktop.
Here is the example for shipping and billing phone number validation. Add this custom code to your WordPress site
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
<?php | |
// Shipping filed validation | |
add_filter('cartimize_get_shipping_checkout_fields', 'cartimize_modify_shipping_checkout_fields_new', 100, 1); | |
function cartimize_modify_shipping_checkout_fields_new( $checkout_fields ){ | |
if ( isset($checkout_fields['shipping_phone']) && $checkout_fields['shipping_phone']['required'] == true ) { | |
$checkout_fields['shipping_phone'] = $checkout_fields['shipping_phone']; | |
$checkout_fields['shipping_phone']['custom_attributes']['data-parsley-pattern'] = '([0-9]{10})'; | |
} | |
return $checkout_fields; | |
} | |
// Billing filed validation | |
add_filter('cartimize_get_billing_checkout_fields', 'cartimize_modify_billing_checkout_fields_new', 100, 1); | |
function cartimize_modify_billing_checkout_fields_new( $checkout_fields ){ | |
if ( isset($checkout_fields['billing_phone']) && $checkout_fields['billing_phone']['required'] == true ) { | |
$checkout_fields['billing_phone'] = $checkout_fields['billing_phone']; | |
$checkout_fields['billing_phone']['custom_attributes']['data-parsley-pattern'] = '([0-9]{10})'; | |
} | |
return $checkout_fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use below prefix for South Africa phone number validation
^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$
For example
Shipping section
$checkout_fields['shipping_phone']['custom_attributes']['data-parsley-pattern'] = '^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$';
Billing section
$checkout_fields['billing_phone']['custom_attributes']['data-parsley-pattern'] = '^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$';