Skip Navigation

[Resolved] Woocommerce subscription roles

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.

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 27 replies, has 3 voices.

Last updated by Minesh 1 month ago.

Assisted by: Minesh.

Author
Posts
#2776067

Can Minesh help me out? Since he knows the working of our site

We purchased woocommerce subscriptions and found out that it can only create one user role. While we work with multiple roles. So now when a client buys a package, they get the custom role we create AND the role woocommerce subscriptions creates.

Now when the renewal payment fails, or the client cancels their subscription, the custom role we created stays the same. The client can still use our platform.

Is there a way to solve this?

We would like that when a client stops his subscription, that his published content goes to concept, and preferable also gets deleted within a certain amount of time..

Is this possible?

Thanks in advance...

#2777188

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Actually, Toolset do offer any hooks related to WooCommerce Subscription events.

When I checked about canceling the WooCommerce Subscription, I found few hooks that you will require to use.

For example, you can use their action hooks:
- woocommerce_subscription_status_cancelled
=> https://woocommerce.com/document/subscriptions/develop/action-reference/#cancelled_subscription

- woocommerce_subscription_status_expired
=> https://woocommerce.com/document/subscriptions/develop/action-reference/#subscription_expired

I found few other reference:
- https://stackoverflow.com/questions/63073288/change-user-role-based-on-woocommerce-active-subscription
- https://stackoverflow.com/questions/54881259/woocommerce-subscriptions-remove-role-on-cancelled-subscription
- https://stackoverflow.com/questions/55230729/switch-user-role-on-subscription-expiration-in-woocommerce

Here is few Toolset related tickets:
- https://toolset.com/forums/topic/delete-users-posts-when-woocommerce-subscription-cancels/
- https://toolset.com/forums/topic/woocommerce-subscriptions-and-toolset-access-multiple-role-issue/

However - I strongly believe that you should check with WooCommerce Subscription support in this matter as they know all the available hooks available and then you proceed.

#2777287

Thank you.

Few, this gets too difficult for me I'm afraid. Perhaps I'll have to look for a simpler way where we have to do some manual work.

Apart from woocommerce subscription, When I delete a user, all his (custom) posts stay online, how can I set this that all post will also get deleted? (artist bio and his artwork)

#2777291
1000055924.jpg
1000055923.jpg

The payment process doesn't work anymore. We get a 404 when going to the checkout page, since installing subscriptions. A user account is made nevertheless. But it's set to client role.

Also the menu layout of the page gets corrupted after this.

#2777308

I see that Woocommerce subscriptions also works with variable products. I'm afraid it's not possible.. but it would be great if i could these variations to create a new user with different user roles, depending on that variation. But when i look at the toolset user form, i think it's not possible, since it only creates a user with one user role, i can't select product variations as wel. or is there a work around possible?

#2777379

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

This is a quick follow up to let you know Minesh is not available today but he'll be back shortly and reply to you as soon as possible.

Thank you for your understanding.
Mateus

#2777631

Minesh
Supporter

Languages: English (English )

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

Yes - you cant use variable product.

Please check the following Doc:
- https://toolset.com/course-lesson/charge-users-for-registering-premium-accounts/

Here is the Doc that shows information about how you can use WooCommerce Subscription plugin with Toolset:
=> https://toolset.com/course-lesson/using-the-woocommerce-subscriptions-plugin-with-toolset/

You can specify what product you want to offer to buy to user and for that you will have to add custom field. But here again, you can not use variable product but you will have to define each product variation as a separate product that means, if you have one product with three variation, so here you will have to create three simple product one for each variation and use the product ID with custom field.

Please check the following Doc:
- https://toolset.com/course-lesson/charge-users-for-submitting-content/#2-1-product-to-buy

#2777672

Thank you, I will try this again with the subscription doc. Ordering gives a lot of problems now.

When a user buys a premium subscription, we have 3, he gets 2 roles: one from toolset (the one that matters) and one from woocommerce subscription, which I don't need. Now, when the subscription ends, the toolset status stays, only the woocommerce status is changed. I tried this with this code, I wanted to delete all the roles and give the free 'Pakket 1' role, but that does not work:

add_action('woocommerce_subscription_status_updated', 'update_user_role_to_pakket_1', 10, 3);

function update_user_role_to_pakket_1($subscription, $new_status, $old_status) {
// Get the user associated with the subscription
$user_id = $subscription->get_user_id();

// Make sure we have a valid user
if ($user_id) {
$user = new WP_User($user_id);

// Check if the subscription has been canceled or put on hold
if ($new_status === 'cancelled' || $new_status === 'on-hold') {
// Remove all existing roles
$user->remove_all_roles();

// Add only the 'Pakket 1' role
$user->add_role('Pakket 1');
}

// Optional: Assign a different role if the subscription becomes active again
// if ($new_status === 'active') {
// $user->set_role('subscriber'); // Or another desired role
// }
} else {
// Optional: log an error if no valid user is found
error_log('No user associated with subscription ID: ' . $subscription->get_id());
}
}

#2778000
1000055930.jpg

1. I followed the toolset woocommerce subscriptions document, but unfortunately I still get an error when purchasing a subscription. See screenshot. When I start browsing after this failed subscribing process, the menu in the header gets deformed also? An account is created though, with a 'client' role. When i disable the Toolset WooCommerce Blocks and Toolset Forms Commerce plugins, then the payment process works.

So I'm afraid the problem is coming from toolset.

2. Also when ordering a subscription the client does not receive his email with password anymore. Instead he receives an email with a link to set his password manually, but that doesn't work either.

#2778057

Minesh
Supporter

Languages: English (English )

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

1. I followed the toolset woocommerce subscriptions document, but unfortunately I still get an error when purchasing a subscription. See screenshot. When I start browsing after this failed subscribing process, the menu in the header gets deformed also? An account is created though, with a 'client' role. When i disable the Toolset WooCommerce Blocks and Toolset Forms Commerce plugins, then the payment process works.
===>
That is strange and I will need to look at how you configure the form as well as WC Subscription configurations.

2. Also when ordering a subscription the client does not receive his email with password anymore. Instead he receives an email with a link to set his password manually, but that doesn't work either.
===>
Yes - the flow will be to reset the password and I need to check again for that why its not working.

Can you please send me link where you added the form and steps that I will have to follow that should help me to see the issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2778535

Minesh
Supporter

Languages: English (English )

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

Well - On the following step you shared:

Choose a username and a password and click on Ik ben geen robot

I see you shared chose username and a password but on the page:
- hidden link

I see it only offers username and email. Am I missing anything here?

#2778537

Yes, that's right. The password was set to be sent from toolset / wordpress with the auto generate password option. . Because i didn't want the customers to be able to use weak passwords

#2778610

Minesh
Supporter

Languages: English (English )

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

I see you are using WC subscription plugin.

Are you using any subscription product here or creating any subscription? If you are not using WC subscription then I will disable that plugin.

#2778666

Yes that's the issue. Please check my earlier messages in this thread

#2778705

I'll write down a recap/ summary of the problems, who have to with each other.

We bought the WooCommerce Subscription plugin because our customers need to renew every year. We had the website completely running and everything worked good, installing the subscription plugin is the latest step before we go live.
Now these problems came up

1. The payment process does not work anymore. You can try this with the art promotion subscription: hidden link There will come up an error prompt and when you scroll further the menu's are being mixed up / corrupted There is an account created with the role: klant (client) After that you receive an email where you can set a password, but i want the toolset form to give out the password. (That e-mail with the request to create a password does not work (procedure to get to this is described in the private message)
2. We have 4 different subscriptions with 4 different user forms and roles, from who 3 are payed subscriptions. But the subscriptions plugin only supports one. So when a account is created through the user form, the user receives 2 roles. What we need, after a subscription ends, that the role, given by the toolset software, will be deleted. So only the status that is changed by the woocommerce plugin will be set. (Pakket 1)

3. And then there is an extra request: When people fill out the user form to become a client, they are asked in the next page (woocommerce) to re-enter their email-address. We noticed during testing that people sometimes use another e-mail address there. Is it possible to populate that field with the e-mail address that they fill in in the toolset form?

Hope you can help us out once more... thnx