-
-
Save mervick/8b724fc0ff4390c374d7381fea75f40b to your computer and use it in GitHub Desktop.
Validating Custom Fields
This file contains hidden or 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 | |
| add_action( 'wp_enqueue_scripts', 'child_enqueue_styles' ); | |
| function child_enqueue_styles() { | |
| wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); | |
| } | |
| add_action('woocommerce_after_checkout_validation', 'digthis_two_step_checkout_validate', 9999, 2); | |
| function digthis_two_step_checkout_validate($data, $errors) { | |
| $step = filter_input(INPUT_POST, 'current_step'); | |
| if( empty( $errors->errors ) && $step == 'step-1' ){ | |
| $errors->add( 'digthis', __( '<span id="digthis-prevent-error">Digthis Error</span>', 'woocommerce' ) ); | |
| } | |
| } | |
| add_action('woocommerce_before_checkout_billing_form', 'customise_checkout_category_user', 0); | |
| function customise_checkout_category_user($checkout) { | |
| woocommerce_form_field( 'inscription_textbox_cf', array( | |
| 'type' => 'text', | |
| 'class' => array( 'inscription-text_cf form-row-wide' ), | |
| 'label' => __( 'Codice Fiscale' ), | |
| 'required' => true, | |
| ), $checkout->get_value( 'inscription_textbox_cf' ) ); | |
| woocommerce_form_field( 'inscription_textbox_iva', array( | |
| 'type' => 'text', | |
| 'class' => array( 'inscription-text_iva form-row form-row-last' ), | |
| 'label' => __( 'Partita Iva' ), | |
| 'required' => true, | |
| ), $checkout->get_value( 'inscription_textbox_iva' ) ); | |
| } | |
| add_action('woocommerce_after_checkout_validation', 'validate_checkout_category_user', 10, 2); | |
| function validate_checkout_category_user($data, $errors) { | |
| $inscription_cf = filter_input(INPUT_POST, 'inscription_textbox_cf'); | |
| $inscription_iva = filter_input(INPUT_POST, 'inscription_textbox_cf'); | |
| if( $inscription_cf != 'digthis' ){ | |
| $errors->add( 'digthis', __( 'value should be digthis', 'woocommerce' ) ); | |
| } | |
| if( $inscription_iva != 'checkthis' ){ | |
| $errors->add( 'digthis', __( 'value should be checkthis', 'woocommerce' ) ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment