How to add check Terms & Conditions in the affiliate registration form
To add check Terms & Conditions in the affiliate registration form add the following code in the functions.php of your theme:
if( defined( 'YITH_WCAF' ) ){
if( ! function_exists( 'yith_wcaf_add_terms_checkbox' ) ){
function yith_wcaf_add_terms_checkbox(){
$checkbox = sprintf( '<label for="yith_wcaf_terms_and_condition"><input type="checkbox" name="yith_wcaf_terms_and_condition" id="yith_wcaf_terms_and_condition" value="yes" %s>%s <a href="%s">%s</a></label>', checked( isset( $_POST['yith_wcaf_terms_and_condition'] ) && 'yes' == $_POST['yith_wcaf_terms_and_condition'], true, false ), __( 'Agree to', 'yith-wcaf' ), get_the_permalink( get_page_by_path( '<SLUG OF YOUR AFFILIATES TERMS & CONDITIONS PAGE>' ) ), __( 'Affiliate Terms & Conditions', 'yith-wcaf' ) );
echo $checkbox;
}
add_action( 'yith_wcaf_register_form', 'yith_wcaf_add_terms_checkbox' );
}
if( ! function_exists( 'yith_wcaf_check_terms_checkbox' ) ){
function yith_wcaf_check_terms_checkbox( $validation_error ){
$enabled_form = get_option( 'yith_wcaf_referral_registration_form_options' );
if(
( ! empty( $_POST['register_affiliate'] ) && isset( $_POST['register_affiliate'] ) && wp_verify_nonce( $_POST['register_affiliate'], 'yith-wcaf-register-affiliate' ) ) ||
( ! empty( $_POST['register'] ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-register' ) && $enabled_form == 'any' )
){
if( empty( $_POST['yith_wcaf_terms_and_condition'] ) || $_POST['yith_wcaf_terms_and_condition'] != 'yes' ){
$validation_error->add( 'not_accepted_tos', __( 'Please, accept our Terms & Conditions', 'yith-wcaf' ) );
}
}
return $validation_error;
}
add_filter( 'woocommerce_process_registration_errors', 'yith_wcaf_check_terms_checkbox' );
}
}
After remember to replace <SLUG OF YOUR AFFILIATES TERMS & CONDITIONS PAGE> with the actual slug of the page