Email fields comparison validation in Woocommerce checkout
up vote
1
down vote
favorite
I have a custom field called gift
and I am now trying to validate that against the billing_email
field. In other words, if the customer fills in the gift field and it is the same email as the billing email, an error should be shown when clicking "complete order" button.
It does not work. Any ideas why? Here's the code.
// verify that billing email and gift email are not the same
function billing_email_and_gift_validation( $posted ) {
$checkout = WC()->checkout;
if ( strcmp( $posted['billing_email'] == $posted['gift'] )) {
wc_add_notice( __( 'To send as gift, you cannot send it to yourself. That's the point of a gift, is it not?', 'woocommerce' ), 'error' ); } }
add_action( 'woocommerce_after_checkout_validation', 'billing_email_and_gift_validation', 10, 2 );
Thank you all if anyone can help.
php wordpress validation woocommerce checkout
add a comment |
up vote
1
down vote
favorite
I have a custom field called gift
and I am now trying to validate that against the billing_email
field. In other words, if the customer fills in the gift field and it is the same email as the billing email, an error should be shown when clicking "complete order" button.
It does not work. Any ideas why? Here's the code.
// verify that billing email and gift email are not the same
function billing_email_and_gift_validation( $posted ) {
$checkout = WC()->checkout;
if ( strcmp( $posted['billing_email'] == $posted['gift'] )) {
wc_add_notice( __( 'To send as gift, you cannot send it to yourself. That's the point of a gift, is it not?', 'woocommerce' ), 'error' ); } }
add_action( 'woocommerce_after_checkout_validation', 'billing_email_and_gift_validation', 10, 2 );
Thank you all if anyone can help.
php wordpress validation woocommerce checkout
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a custom field called gift
and I am now trying to validate that against the billing_email
field. In other words, if the customer fills in the gift field and it is the same email as the billing email, an error should be shown when clicking "complete order" button.
It does not work. Any ideas why? Here's the code.
// verify that billing email and gift email are not the same
function billing_email_and_gift_validation( $posted ) {
$checkout = WC()->checkout;
if ( strcmp( $posted['billing_email'] == $posted['gift'] )) {
wc_add_notice( __( 'To send as gift, you cannot send it to yourself. That's the point of a gift, is it not?', 'woocommerce' ), 'error' ); } }
add_action( 'woocommerce_after_checkout_validation', 'billing_email_and_gift_validation', 10, 2 );
Thank you all if anyone can help.
php wordpress validation woocommerce checkout
I have a custom field called gift
and I am now trying to validate that against the billing_email
field. In other words, if the customer fills in the gift field and it is the same email as the billing email, an error should be shown when clicking "complete order" button.
It does not work. Any ideas why? Here's the code.
// verify that billing email and gift email are not the same
function billing_email_and_gift_validation( $posted ) {
$checkout = WC()->checkout;
if ( strcmp( $posted['billing_email'] == $posted['gift'] )) {
wc_add_notice( __( 'To send as gift, you cannot send it to yourself. That's the point of a gift, is it not?', 'woocommerce' ), 'error' ); } }
add_action( 'woocommerce_after_checkout_validation', 'billing_email_and_gift_validation', 10, 2 );
Thank you all if anyone can help.
php wordpress validation woocommerce checkout
php wordpress validation woocommerce checkout
edited Nov 18 at 14:24
LoicTheAztec
80.1k125992
80.1k125992
asked Nov 18 at 13:38
WooDevil
1077
1077
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I have merged this validation with the gift validation from this question code you have made before, so you will remove it from your actual code as this function handle both of them:
add_action('woocommerce_after_checkout_validation', 'gift_custom_field_validation', 20, 2 );
function gift_custom_field_validation( $data, $errors ) {
// Validating that "Gift" is not empty when selected
if( isset($_POST['gift_msg']) && isset($_POST['gift']) && empty($_POST['gift']) )
$errors->add( 'gift', __( "You've chosen to send this as a gift, but did not submit a recipient email address.", "woocommerce" ) );
// Validating that "Gift" imputed email is different from billing email
if ( isset($_POST['gift']) && $data['billing_email'] === $_POST['gift'] ) {
$errors->add( 'gift', __( "To send as gift, you cannot send it to yourself. That's the point of a gift, isn't it?", "woocommerce" ) );
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I have merged this validation with the gift validation from this question code you have made before, so you will remove it from your actual code as this function handle both of them:
add_action('woocommerce_after_checkout_validation', 'gift_custom_field_validation', 20, 2 );
function gift_custom_field_validation( $data, $errors ) {
// Validating that "Gift" is not empty when selected
if( isset($_POST['gift_msg']) && isset($_POST['gift']) && empty($_POST['gift']) )
$errors->add( 'gift', __( "You've chosen to send this as a gift, but did not submit a recipient email address.", "woocommerce" ) );
// Validating that "Gift" imputed email is different from billing email
if ( isset($_POST['gift']) && $data['billing_email'] === $_POST['gift'] ) {
$errors->add( 'gift', __( "To send as gift, you cannot send it to yourself. That's the point of a gift, isn't it?", "woocommerce" ) );
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
add a comment |
up vote
1
down vote
accepted
I have merged this validation with the gift validation from this question code you have made before, so you will remove it from your actual code as this function handle both of them:
add_action('woocommerce_after_checkout_validation', 'gift_custom_field_validation', 20, 2 );
function gift_custom_field_validation( $data, $errors ) {
// Validating that "Gift" is not empty when selected
if( isset($_POST['gift_msg']) && isset($_POST['gift']) && empty($_POST['gift']) )
$errors->add( 'gift', __( "You've chosen to send this as a gift, but did not submit a recipient email address.", "woocommerce" ) );
// Validating that "Gift" imputed email is different from billing email
if ( isset($_POST['gift']) && $data['billing_email'] === $_POST['gift'] ) {
$errors->add( 'gift', __( "To send as gift, you cannot send it to yourself. That's the point of a gift, isn't it?", "woocommerce" ) );
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I have merged this validation with the gift validation from this question code you have made before, so you will remove it from your actual code as this function handle both of them:
add_action('woocommerce_after_checkout_validation', 'gift_custom_field_validation', 20, 2 );
function gift_custom_field_validation( $data, $errors ) {
// Validating that "Gift" is not empty when selected
if( isset($_POST['gift_msg']) && isset($_POST['gift']) && empty($_POST['gift']) )
$errors->add( 'gift', __( "You've chosen to send this as a gift, but did not submit a recipient email address.", "woocommerce" ) );
// Validating that "Gift" imputed email is different from billing email
if ( isset($_POST['gift']) && $data['billing_email'] === $_POST['gift'] ) {
$errors->add( 'gift', __( "To send as gift, you cannot send it to yourself. That's the point of a gift, isn't it?", "woocommerce" ) );
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
I have merged this validation with the gift validation from this question code you have made before, so you will remove it from your actual code as this function handle both of them:
add_action('woocommerce_after_checkout_validation', 'gift_custom_field_validation', 20, 2 );
function gift_custom_field_validation( $data, $errors ) {
// Validating that "Gift" is not empty when selected
if( isset($_POST['gift_msg']) && isset($_POST['gift']) && empty($_POST['gift']) )
$errors->add( 'gift', __( "You've chosen to send this as a gift, but did not submit a recipient email address.", "woocommerce" ) );
// Validating that "Gift" imputed email is different from billing email
if ( isset($_POST['gift']) && $data['billing_email'] === $_POST['gift'] ) {
$errors->add( 'gift', __( "To send as gift, you cannot send it to yourself. That's the point of a gift, isn't it?", "woocommerce" ) );
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
answered Nov 18 at 14:22
LoicTheAztec
80.1k125992
80.1k125992
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
add a comment |
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
thank you very much. Works.
– WooDevil
Nov 18 at 14:34
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361483%2femail-fields-comparison-validation-in-woocommerce-checkout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown