I am needing to use WC Subscriptions for recurring payments.
In the "The flow" section of https://toolset.com/documentation/user-guides/how-to-create-custom-searches-and-relationships-for-users/ , it describes the flow as:
--a new User registers with the website,
--then a WP profile/account is created,
--then the user logs in,
--then the user creates his/her Profile (a separate CPT, in the example its a *Contractor* Profile) using a front-end form.
--Then there can also be other forms for other separate submissions/posts (in the example a separate *Showcase* submission form).
So now I'm wondering 3 things:
1) Does that mean, per the above article--(because WC Subscriptions automatically creates the new WP accounts)-- that it's best to use the *Post Author field* to connect to the Profile (and other forms), rather than using a standard *Post Relationships* setup?
(The above-mentioned article says: "Alternatively, you could create a regular one-to-many relationship between Contractors and Showcases, but since the showcase entries will be added by the logged-in user through the front-end forms, it will be easier to use the same approach for both Contractors and Showcases.")
2) how does one hook up the newly created (WC Subscriptions) User to automatically redirect to the Profile form immediately after successful WC Subscriptions signup & WP newly created account? (or is the Manual Method described above the only way for new User to create their Profile page?) (Manual method is not the ideal, since one wants them to complete a Profile page, and if not immediately automatically redirected to the Profile form, they may not do it).
3) how to limit new User to be able to create only one Profile?
1) Does that mean, per the above article--(because WC Subscriptions automatically creates the new WP accounts)-- that it's best to use the *Post Author field* to connect to the Profile (and other forms), rather than using a standard *Post Relationships* setup?
In most cases, yes that is correct. You will use the Post Author to connect a User and a post. However it is not possible to link multiple Users to one post by post author because only one author is allowed by default in WordPress. To link multiple Users to a single post, you must use the proxy post type (Profile in this case) and post relationships.
2) how does one hook up the newly created (WC Subscriptions) User to automatically redirect to the Profile form immediately after successful WC Subscriptions signup & WP newly created account?
For very simple cases, you can add the following code snippet to functions.php to redirect to a custom URL after payment:
/* Redirect user after check out */
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( '<em><u>hidden link</u></em>' );
exit;
}
}
Change the URL as needed for your site. For more complex cases you may need assistance from the WC Subscriptions team since the payment process is not controlled by Toolset.
3) how to limit new User to be able to create only one Profile?
Use a View to determine whether or not the User has created a Profile yet. There is a process described in the documentation here: https://toolset.com/documentation/user-guides/how-to-create-custom-searches-and-relationships-for-users/#how-do-i-prevent-users-from-creating-more-than-one-contractor-post
Thank you, that helps a lot.
So....
1)-- for clarity: if I wanted one Post Author for each Profile/Contractor CPT post, but--(then for the most flexibility)--to allow multiple Authors to collaborate on other CPTs post (eg like a Showcase post), then the set-up would be:
--use Post Author to connect the form to create the user's Profile, but then use Post Relationships to connect the Profile CPT to other CPTs, like Showcase?
2a)--Does the code you supplied (thank you) for "Redirect user after check out" need to go below or above any particular code in the functions.php, or can it just be inserted at the very bottom of all the code in that file?
2b)--To confirm, the "..../your-page/" portion of the URL link in the code is changed to the name of the form or other page you want the user to be redirected to?
2c)--Can you give me an example of what would constitute a "simple" vs a "more complex" case (where WC Subscriptions would need to get involved)?
Thank you so much for all your kind help, I am truly grateful.
1)-- use Post Author to connect the form to create the user's Profile, but then use Post Relationships to connect the Profile CPT to other CPTs, like Showcase?
Yes, if you plan to connect multiple Users to one Showcase, it's best to link Profile posts to Showcases using Post Relationships. If this is not necessary, post author is easier to implement and more straightforward for use when filtering and searching with Views.
2a)--Does the code you supplied (thank you) for "Redirect user after check out" need to go below or above any particular code in the functions.php
If the file ends with ?>, the code I provided should be inserted just before those two characters. If those two characters are not shown at the end of the file, then you can insert the code at the very end of the file.
2b)--To confirm, the "..../your-page/" portion of the URL link in the code is changed to the name of the form or other page you want the user to be redirected to?
The name of the Form doesn't necessarily correspond to any URL. The name of the Page may not be the same as the URL slug, so you should change the entire URL to match whatever URL the User should be redirected to. Create that redirect custom page or post first so you know the exact URL.
2c)--Can you give me an example of what would constitute a "simple" vs a "more complex" case (where WC Subscriptions would need to get involved)?
- Your shop offers various products, and you only want this redirect to apply when someone has purchased a specific product.
- Your shop offers 10 different subscription products and each one should have a different redirect URL.
- You need different redirect URLs based on a combination of subscription products and you allow your Users to purchase multiple subscriptions in a single purchase.
Any of those situations will require more complex redirect logic.
Thank you for your very clear responses.
I'm wondering:
A) In your 2c) example
"Your shop offers 10 different subscription products and each one should have a different redirect URL.,
if one has a couple different WC Subscription products and one only wants the Free (non-paying) User to have access to certain CPT Forms (say, a "Free" CPT input form, and not a "Showcase" input form, which would be reserved for paying Users) can this be set up through Access? (This way, if the Free (non-paying) User decides to become a paying User they can keep their current account and "add on", rather than possibly needing to create a new 2nd account if the "Free" user was set up with WooCommerce Forms).
B) Is there any difference in speed/performance between using Post Relationship to connect other CPT forms to a main "Profile" form, vs Post Author to connect other CPT forms to a main "Profile" form?
Thank you for all your help, I am very grateful.
if one has a couple different WC Subscription products and one only wants the Free (non-paying) User to have access to certain CPT Forms (say, a "Free" CPT input form, and not a "Showcase" input form, which would be reserved for paying Users) can this be set up through Access?
Yes, if the difference between Free and Paying Users is defined simply by a different User role, then it's easy to set up this type of conditional logic in Access. We have inline Access Control shortcodes that you can use to show or hide specific Forms based on User role:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/
B) Is there any difference in speed/performance between using Post Relationship to connect other CPT forms to a main "Profile" form, vs Post Author to connect other CPT forms to a main "Profile" form?
Relationships are maintained in database tables that are separate from the main posts table, so any View with custom search or a query filter that depends on post relationships will inherently take longer than a post author query (post author is in the same posts table). The difference may or may not be negligible depending on the number of posts in your database and the complexity of your relationship queries.
Hi:
It's good to know that Toolset has "inline Access Control shortcodes that you can use to show or hide specific Forms based on User role.
I thought I read somewhere recently that, currently, having more than the designated WooCommerce User Role can cause conflicts, but that Toolset was going to add the ability to have multiple User Roles with WooCommerce soon. Has that occurred now? (I can't remember how old the post was that I read.)
If it's now possible to have more than one User Role with WooCommerce, can you please direct me to docs that explain further how to do this?
If it's possible, how to set this up with WC Subscriptions?
Thank you for all you help.
I thought I read somewhere recently that, currently, having more than the designated WooCommerce User Role can cause conflicts
This is still true. Assigning multiple roles to one User can cause conflicts with Access. We recommend using Access with a single User role.