Skip to content

Instantly share code, notes, and snippets.

@rayflores
Last active May 20, 2016 16:25
Show Gist options
  • Save rayflores/7db772a69fedb2c8e69556d2cab0891c to your computer and use it in GitHub Desktop.
Save rayflores/7db772a69fedb2c8e69556d2cab0891c to your computer and use it in GitHub Desktop.
custom checkout filer
<?php
function custom_add_validation_rules() {
if ( ! isset( WC()->cart ) ) {
return;
}
// Check if emails are ligitimate, if its not set add an error.
if ( isset($_POST['additional_field_644']) && ! is_email( $_POST['additional_field_644'] ) ){
wc_add_notice( 'Email Address For Summaries is not a valid email address.', 'error' );
}
if ( isset($_POST['additional_field_598']) && ! is_email( $_POST['additional_field_598'] ) ) {
wc_add_notice( 'Email Address For Summaries (Retype) is not a valid email address.', 'error' );
}
if ( isset($_POST['additional_field_435']) && !is_email( $_POST['additional_field_435'] ) ) {
wc_add_notice( 'Backup Email is not a valid email address.', 'error' );
}
if ( isset($_POST['additional_field_176']) && !is_email( $_POST['additional_field_176'] ) ) {
wc_add_notice( 'Group Contact Email is not a valid email address.', 'error' );
}
}
add_action( 'woocommerce_checkout_process', 'custom_add_validation_rules' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment