Problem:
How to change a user's role when payment is made through Toolset Forms Commerce and then change it back again when the related post expires.
Solution:
The API hook cred_commerce_after_order_completed can be used to trigger code which changes the user role using the standard set_role method.
Reverting the role when the related post expires is slightly trickier, as there is no Toolset API hook for when a post expires.
In this case, when a post expires it is changed to draft status.
You can use the standard WP hooks that are triggered when changing a custom post status to draft (e.g. the draft_project hook for a project post type) to check when a post of the relevant type is changed to draft status, and then check whether the post expiration time has passed (meaning the change to draft was likely triggered by the expiration) using the value stored in a hidden custom field '_cred_post_expiration_time' that can be retrieved with get_post_meta.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed
https://developer.wordpress.org/reference/classes/wp_user/set_role/
https://codex.wordpress.org/Post_Status_Transitions
https://developer.wordpress.org/reference/functions/get_post_meta/
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 |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 4 replies, has 2 voices.
Last updated by 5 years, 3 months ago.
Assisted by: Nigel.