As per the WordPress forum policy, we can’t answer premium related questions on this forum. Could you please raise a ticket through our website so that our technical team will be able to help you.
Thank you!
Thread Starter
diegpl
(@diegpl)
Ok, I just sent u a message. I really would like to be able to do that through your plugin, since my client would be able to manage that by himself. However, I also would like to know how to do that through php. I do not know if that is on your scope, so here is the code, which is not working, do you know tell me why?
//https://rudrastyh.com/woocommerce/custom-checkout-validation.html - hook woocommerce_after_checkout_validation did not work
//https://stackoverflow.com/questions/28603144/custom-validation-of-woocommerce-checkout-fields
add_action( 'woocommerce_after_checkout_validation', 'misha_validate_fname_lname', 10, 2);
function misha_validate_fname_lname( $fields, $errors ){
if ( strpos( $fields[ 'billing_n_matricula' ], 300) === false ){
$errors->add( 'validation', 'Seu número de matrícula parece estar errado, favor digitar o correto.' );
}
}
It seems the code runs, since I see the validation warning, but it never gets true, to go ahead. Tks!
-
This reply was modified 6 years, 6 months ago by
diegpl.
-
This reply was modified 6 years, 6 months ago by
diegpl.
We have checked the code in detail. The issue is that, the second argument for the strpos will be a string type. Here in the code it is used as an integer type. Please change the code as per the below snippets.
add_action( 'woocommerce_after_checkout_validation', 'misha_validate_fname_lname', 11, 2);
function misha_validate_fname_lname( $fields, $errors ){
if ( strpos( $fields[ 'billing_n_matricula' ], '300') === false ){
$errors->add( 'validation', 'Seu número de matrícula parece estar errado, favor digitar o correto.' );
}
}
Hope this will help 🙂
Thank you!