I use this code to create a second checkbox at the woocommerce checkout (for the privacy policy). To be compatible with the GDPR I would need to be able to prove that the user selected the checkbox. How could I do?
// Add terms and policy check box in checkout page
add_action( 'woocommerce_checkout_after_terms_and_conditions', 'add_terms_and_policy', 20 );
function add_terms_and_policy() {
$domain = 'woocommerce';
$gdpr_private_policy_link = sprintf( '<a href="%s" target="_blank">%s</a>',
home_url("/protest/privacy-policy/"), // The button link to the GDPR privacy policy page
__( "Privacy Policy", $domain ) // The button text
);
woocommerce_form_field( 'gdpr_terms', array(
'type' => 'checkbox',
'class' => array( 'terms gdpr_terms' ),
'input_class' => array('woocommerce-form__input-checkbox'),
'label_class' => array('woocommerce-form__label-for-checkbox'),
'label' => '<span>' . sprintf(
__( "I have read and accept the %s and understand how you manage my Data under GDPR", $domain ),
$gdpr_private_policy_link
) . '</span>',
'required' => true,
), '');
}
// Validate required GDPR private policy checkbox
add_action( 'woocommerce_after_checkout_validation', 'terms_and_policy_validation', 20, 2 );
function terms_and_policy_validation( $data, $errors ) {
if ( ! isset( $_POST['gdpr_terms'] ) ){
$domain = 'woocommerce';
$gdpr_text = sprintf(
__( "I have read and accept the %s and understand how you manage my Data under GDPR", $domain ),
__( "Privacy Policy", $domain )
);
$errors->add( 'gdpr_terms', sprintf( __( 'You must accept "%s".', $domain ), $gdpr_text ), 'error' );
}
}
Aucun commentaire:
Enregistrer un commentaire