Woocommerce Validation

Hi,


I wanted that Checkout on Woocommerce could validate email.

Like:

Email:

Confirm email:


And if they don't match, a error would be given.


I tried this on other theme and works: https://www.wpdesk.net/docs/validate-woocommerce-checkout-fields


Just installing that plugin and adding the following code to functions.php, but on this theme I get header error when adding the code:


/** * Can validate field by comparing value with other field. */class WPDesk_FCF_Validation_Confirm_Field { /** * Field to compare with validated field. * * @var string */ private $field_to_compare; /** * WPDesk_FCF_Validation_Confirm_Field constructor. * * @param string $field_to_compare . */ public function __construct( $field_to_compare ) { $this->field_to_compare = $field_to_compare; } public function hooks() { add_filter( 'flexible_checkout_fields_custom_validation', array( $this, 'register_custom_validation' ) ); } /** * Register custom validation. * * @param array $custom_validation . * * @return array */ public function register_custom_validation( $custom_validation ) { $custom_validation[ 'field_confirmation_' . $this->field_to_compare ] = array( 'label' => sprintf( __( 'Compare with %1$s', 'wpdesk' ), $this->field_to_compare ), 'callback' => array( $this, 'validate' ) ); return $custom_validation; } /** * Validate. * * @param string $field_label Field label. * @param string $value Field value. */ public function validate( $field_label, $value ) { $field_to_compare_value = sanitize_text_field( $_POST[ $this->field_to_compare ] ); $valid = $field_to_compare_value === $value; if ( ! $valid ) { wc_add_notice( sprintf( __( 'Invalid %1$s value.', 'wpdesk' ), '<strong>' . $field_label . '</strong>' ), 'error' ); } }}$fcf_validation_confirm_field = new WPDesk_FCF_Validation_Confirm_Field( 'billing_email' );$fcf_validation_confirm_field->hooks();

Comments

Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.