I am designing a form for people to sign up for classes. Each class is a single product. I want to assign a custom capability to each product and then add the capability to the user who purchases each product. This capability allows access to pages and/or content related to that class/product. I just need some help assigning the capabilities to the user on submission.
Here is what I have so far:
add_action("gform_after_submission_3", "assign__user_cap", 10, 2);
function assign_user_cap($entry){
$user_id = get_current_user_id( );
$user = new WP_User($user_id);
//need to get array of field ids for the products purchased
//need to associate a capability with each product; perhaps as the admin name
foreach($field_ids as $field_id){
$cap_name = "access_" . $form["fields"][$field_id]["adminLabel"]; //creates custom capability "access_adminLabel" for each product
$user->add_cap($cap_name); //adds capability to the user who bought the product
return $user;
Can you help me with my syntax and the missing functions to get the field ids for purchased products? Am I heading in the right direction here?