Skip to content

Instantly share code, notes, and snippets.

@clifgriffin
Last active March 2, 2023 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clifgriffin/56fbcc449603cfe44dd1af104ad8efc5 to your computer and use it in GitHub Desktop.
Save clifgriffin/56fbcc449603cfe44dd1af104ad8efc5 to your computer and use it in GitHub Desktop.
<?php
// Add to functions.php or using the Code Snippets plugin
// Do NOT include opening PHP tag above (<?php)
add_filter(
'woocommerce_default_address_fields',
function( $fields ) {
unset( $fields['postcode']['custom_attributes']['data-parsley-length'] );
$fields['address_1']['custom_attributes']['data-parsley-pattern'] = '/^(?![A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2}).*$/';
$fields['address_1']['custom_attributes']['data-parsley-error-message'] = __( 'Please enter a valid address.', 'your-translation-domain' );
return $fields;
},
100001
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment