61
Here’s a snippet regarding the “My Account” registration form and, once again, GDPR. If you get any website traffic from EU, you will need users to give you Privacy Policy consent – including when they register a new account on your WooCommerce website.
So, how do we display a checkbox on the My Account page, at the bottom of the registration form?
PHP Snippet: Add Privacy Policy Checkbox @ WooCommerce My Account Registration Form
/** * @snippet Add Privacy Policy Checkbox @ WooCommerce My Account Registration Form * @how-to Get tutoraspire.com FREE * @sourcecode https://tutoraspire.com/?p=74128 * @author Tutor Aspire * @testedwith WooCommerce 3.5.1 * @donate $9 https://tutoraspire.com */ add_action( 'woocommerce_register_form', 'tutoraspire_add_registration_privacy_policy', 11 ); function tutoraspire_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' => 'I've read and accept the Privacy Policy', )); } // Show error if user does not tick add_filter( 'woocommerce_registration_errors', 'tutoraspire_validate_privacy_registration', 10, 3 ); function tutoraspire_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; }