Hi,
I’m using Gravity Forms for user registration in my WooCommerce site.
I have just one registration form.
In that form, there’s a checkbox that says something like:
“I am a professional customer (salon, etc.)”
I want to do something really simple:
- If the checkbox is checked, I want the user to get the role
wholesale_customer
- If the checkbox is not checked, I want the user to get the standard role like
customer
orsubscriber
I’ve already created a User Registration Feed, but I don’t understand how to use conditional logic to assign different roles depending on the checkbox.
Could someone please explain step-by-step how to do this?
I’m not a developer, so please keep the explanation as simple and clear as possible
I past te code in Code Snippets, but dosnt work:
add_action('gform_user_registered_2', 'ustaw_role_hurtownika', 10, 4);
function ustaw_role_hurtownika($user_id, $feed, $entry, $user_pass) {
// ID pola checkboxa
$checkbox_field_id = 12;
// Sprawdź, czy checkbox został zaznaczony
if (rgar($entry, (string)$checkbox_field_id) === 'Firma / Klient Profesjonalny') {
// Przypisz rolę "wholesale_customer"
$user = new WP_User($user_id);
$user->set_role('wholesale_customer');
}
}
Thank you so much in advance!