I am looking to add a check to my woocommerce registration form to check if a referral code exists, that is set as a custom field (repeater) in the backend. It is currently set up with Advanced Custom Fields and set on an options page. It should check if code is in the repeater fields otherwise refuse registration. The code then needs to be added to the user and shown in the user backend.
I have tried to manipulate terms and conditions code on registration but havent got anywhere. Thanks
This is my ACF code to grab the valid codes for validation.
<?php
// check if the repeater field has rows of data
if( have_rows('referralcode', 'option') ):
// loop through the rows of data
while ( have_rows('referralcode', 'option') ) : the_row();
// display a sub field value
the_sub_field('referralvalue', 'option');
endwhile;
else :
// no rows found
endif;
?>
Here is the way to do it:
1) Add referral registration field
2) Validate (or check) referral registration field…
3) Save referral field data
Code goes in function.php file of your active child theme (or active theme). Tested and works.
And if you wish to display the field (and update the field) in edit user account form:
1) Edit referral registration field:
2) Update referral registration field:
Code goes in function.php file of your active child theme (or active theme). Tested and works.