Skip to content

Instantly share code, notes, and snippets.

@MarceloGlez
Last active July 13, 2021 17:21
Show Gist options
  • Save MarceloGlez/63169e883e37c45f8866280b61756f22 to your computer and use it in GitHub Desktop.
Save MarceloGlez/63169e883e37c45f8866280b61756f22 to your computer and use it in GitHub Desktop.
Genera un checkbox en registro para aceptar la política de privacidad cumpliendo con la RGPD Europea (Agregar líneas de código en function.php del child theme)
/*Genera un checkbox en registro para aceptar la política de privacidad cumpliendo con la RGPD Europea*/
add_action( 'woocommerce_register_form', 'bbloomer_add_registration_privacy_policy', 11 );
function bbloomer_add_registration_privacy_policy() {
woocommerce_form_field( 'privacy_policy_reg', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
'required' => true,
'label' => 'Acepto la <a href="https://tuweb.com">Política de Privacidad</a>',
));
}
// Show error if user does not tick
add_filter( 'woocommerce_registration_errors', 'bbloomer_validate_privacy_registration', 10, 3 );
function bbloomer_validate_privacy_registration( $errors, $username, $email ) {
if ( ! is_checkout() ) {
if ( ! (int) isset( $_POST['privacy_policy_reg'] ) ) {
$errors->add( 'privacy_policy_reg_error', __( '¡Es necesario aceptar la Política de Privacidad!', 'woocommerce' ) );
}
}
return $errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment