Skip Navigation

[Resolved] How to let existing user upgrade to another user role with CRED form

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to let existing user upgrade to another user role with CRED form after successful payment

Solution:
You can use the "cred_commerce_after_order_completed" hook in order to update the user role after successful payment.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/how-to-let-existing-user-upgrade-to-another-user-role-with-cred-form/#post-2376317

Relevant Documentation:
- https://toolset.com/documentation/programmer-reference/cred-commerce-api/

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by wilfredC 1 year, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2376119

How do I set up a form for an existing user to upgrade their role?

Basically, there have 2 roles for the user, one is the customer role which is the Woocommerce default register role, and another one is a premium membership.

I already set up a CRED form for newcomers to purchase for the premium role with the Toolset Form commerce.

But how do I set up a form just for the people who already register as a customer, and want to pay to upgrade for the premium role?

Thank

#2376317

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset offers the addon plugin Toolset Forms Commerce using which you can charge the users when they register and buy new membership:
- https://toolset.com/course-lesson/charge-users-for-registering-premium-accounts/

In your case, you want to allow the existing users to upgrade the membership to new one and update the user role accordingly. For that when if you follow the same Doc above and instead of using "Create new user" form, you should create a new user form for editing existing users and set this form to "Charge payment with this form".

And then set this edit user form to buy your product (new subscription - premium membership):
=> https://toolset.com/course-lesson/charge-users-for-submitting-content/#2-connecting-products-to-forms

And on payment success, you should update the user role using the Toolset Form Commerce hook:
For example:

add_action('cred_commerce_after_order_completed', 'func_update_user_role_after_order_completed',10,1);
function func_update_user_role_after_order_completed( $data ) {
    if ( isset($data['extra_data'][0]['cred_form_id']) && $data['extra_data'][0]['cred_form_id'] == 999999) {
        $user_id = $data['user_id'];
        $user = get_userdata( $user_id );
        $user->set_role( 'premium' );
    }
}

Where:
- Replace 999999 with your original form ID.
- We assume that you have "Premium" custom role created using Toolset Access.
- You can adjust the above code to remove existing user role "customer".

More info:
- https://toolset.com/documentation/programmer-reference/cred-commerce-api/

Can you please give try and let me know if you will require further assistance.

#2377743

It works!!!

But how can I hide the password field in the form? since the existing customer already login

#2378625

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

if you just do not want to hide the password field, you can remove the password field by editing your Toolset form and remove the password field and save your form.

Does that helps?

#2378915
form.JPG

I unable to remove the password field

#2378935

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What if you switch to expert mode and remove the password field(s) and save the form and check if that help you to resolve your issue.

#2383065

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.