Add privacy policy checkbox

PHOTO EMBED

Thu Mar 25 2021 16:15:29 GMT+0000 (UTC)

Saved by @Oldbroth3rz #php

remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
remove_action( 'woocommerce_register_form', 'wc_registration_privacy_policy_text', 20 );

add_action( 'woocommerce_checkout_terms_and_conditions', 'add_custom_privacy_checkbox', 20 );
add_action( 'woocommerce_register_form', 'add_custom_privacy_checkbox_register', 20 );

function add_custom_privacy_checkbox() {
	
	$privacy_policy_text = wp_kses_post( wc_replace_policy_page_link_placeholders( wc_get_privacy_policy_text( 'checkout' ) ) );
	
woocommerce_form_field( 'privacy_policy', 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' => '<span>' . $privacy_policy_text . '</span>',
));

}
function add_custom_privacy_checkbox_register() {
	
	$privacy_policy_text = wp_kses_post( wc_replace_policy_page_link_placeholders( wc_get_privacy_policy_text( 'registration' ) ) );
	
woocommerce_form_field( 'privacy_policy', 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' => '<span>' . $privacy_policy_text . '</span>',
));

}

add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
add_action( 'woocommerce_register_post', 'privacy_checkbox_error_message_registration', 10, 3 );

function privacy_checkbox_error_message() {
	if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
	wc_add_notice( __( 'Veuillez lire et accepter notre politique de confidentialité pour poursuivre votre commande.' ), 'error' );
	}
}
function privacy_checkbox_error_message_registration($username, $email, $validation_errors) {
	if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
			$validation_errors->add( 'privacy_policy_error', __( 'Veuillez lire et accepter notre politique de confidentialité pour pouvoir vous enregistrer.', 'woocommerce' ), 'error');
	}
}
content_copyCOPY