Created
October 21, 2022 18:55
-
-
Save everaldomatias/ec00332ed1b614a91051ca2e1486e51f to your computer and use it in GitHub Desktop.
Add checkbox to WooCommerce login
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( 'woocommerce_register_form', 'custom_add_registration_privacy_policy', 11 ); | |
function custom_add_registration_privacy_policy() { | |
woocommerce_form_field( 'privacy_policy_reg', array( | |
'class' => array('form-row privacy'), | |
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'), | |
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'), | |
'label' => 'I\'ve read and accept the Privacy Policy', | |
'required' => true, | |
'type' => 'checkbox', | |
)); | |
} | |
// Show error if user does not tick | |
add_filter( 'woocommerce_registration_errors', 'custom_validate_privacy_registration', 10, 3 ); | |
function custom_validate_privacy_registration( $errors, $username, $email ) { | |
if ( ! is_checkout() ) { | |
if ( ! (int) isset( $_POST['privacy_policy_reg'] ) ) { | |
$errors->add( 'privacy_policy_reg_error', __( 'Privacy Policy consent is required!', 'woocommerce' ) ); | |
} | |
} | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment