I have built a business directory using Custom Post types. I want to add functionality to charge business owners annual recurring membership fees to have their business directory listing be visible. I need help with planning the best way to do this using toolset plugins (legacy approach).
Thank you in advance.
Hi,
Thank you for contacting us and I'd be happy to assist.
When recurring payments are involved, you'll need the "WooCommerce Subscriptions" add-on for WooCommerce:
https://woocommerce.com/products/woocommerce-subscriptions/
This add-on works by automatically changing the user roles, based on the status of the recurring subscription.
We have a detailed guide on using this with Toolset at:
https://toolset.com/course-lesson/using-the-woocommerce-subscriptions-plugin-with-toolset/
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Based on the thread here:
https://toolset.com/forums/topic/woocommerce-subscription-cred-forms/
The woocommerce subscriptions plugin doesn't work with toolset forms. I have purchased the Subscriptio plugin from envato and i am now able to set a simple product to be a subscription.
How would I go about changing a CPT field value if a subscription isn't renewed before the end of the period?
Thanks for writing back.
> The woocommerce subscriptions plugin doesn't work with toolset forms.
- The Toolset user form is usually used to create/register a new user account. But when a subscription plugin is involved, you don't need it. It is better to let the subscription plugin and WooCommerce handle the new user registrations, through the normal checkout process.
> How would I go about changing a CPT field value if a subscription isn't renewed before the end of the period?
- All good subscription plugins offer built-in hooks and filters to execute custom code at the time subscription status change.
You can consult Subscriptio plugin's official support and documentation to learn about the available hooks and filters to programmatically add/edit the custom field values, at the time of subscription change.
( for example, set one custom field value when the subscription expires and change it to a different value once it renews )
I'm still working on getting this setup.
I created a form to charge for creating a premium user account with a select field to choose membership levels.
When the form is submitted, it redirects to the homepage despite my having chosen "Go to the checkout page" on the form.
I'm following these directions:
https://toolset.com/lesson-placement/lesson-placements-1645361-1651293/
Why is it not going to the checkout page?
I figured out that I had not created the woocommerce pages so it couldn't redirect to the checkout page.
I know that I will have other questions as I go through this. Please keep this ticket open.
OK, so still following the same directions listed above, when my site loads the checkout page, it shows fields for email address, username and password, even though those details were entered on the original form. I have double checked my settings, and they match what the tutorial says to set them to. Please advise.
Thanks for sharing these updates.
On my test website, when I followed the steps from that tutorial, I only see the email, first name, and last name fields getting repeated in the checkout form, which is expected.
If you'd like to fill these fields, with the same data that was added in the Toolset user form before coming to the checkout page, you'll need to include some custom code:
add_action( 'cred_submit_complete', 'tssupp_cred_customdata', 10, 2 );
function tssupp_cred_customdata( $post_id, $form_data ){
// process if specific form
if ( 12345 == $form_data['id'] ) {
// set email, first name and last name, in session data
WC()->session->set( 'custom_data', array( 'email' => $_POST['user_email'], 'firstname' => $_POST['first_name'], 'lastname' => $_POST['last_name']) );
}
}
add_filter( 'woocommerce_checkout_fields' , 'prefill_checkout_field_defaults', 20 );
function prefill_checkout_field_defaults( $fields ) {
// get custom data from the session
$data = WC()->session->get('custom_data');
// fill that custom data into relevant fields
$fields['billing']['billing_first_name']['default'] = $data['firstname'];
$fields['billing']['billing_last_name']['default'] = $data['lastname'];
$fields['billing']['billing_email']['default'] = $data['email'];
return $fields;
}
Note: Please replace "12345" with the actual ID of your user form.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
If you're also seeing the password field in the checkout form, please make sure that the account settings in the WooCommerce are as suggested in that tutorial.
( screenshot: https://toolset.com/wp-content/uploads/2020/06/woocommerce-settings-registration-1.png )
I have double and triple checked the woocommerce checkout settings, and they match what is shown in the image you linked.
I also added the custom code you shared, and it works partially.
I think the best thing at this point would be for you to enable private fields and take a look at my dev site, please.
Thank you.
Sure, I'll be happy to take a look inside.
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
Thank you for sharing the admin access.
The WooCommerce account page settings seem to be correct, but as there are a number of third-party plugins active on the website, one of them must be forcing the username and password fields, during the checkout.
I suspect, most likely it could be from the "Subscriptio" plugin so that users can't complete the checkout process without adding the username and password. This will ensure that it can attach the subscription/membership to the user, properly, when the order is placed.
For this particular case, a better alternative would be to remove the "Join the Chamber Now" user form from the "Join the Chamber NOW" page and instead, add custom add-to-cart links for each membership product.
( ref: hidden link )
When the user will click the target membership product's link, it will be added to the cart and the user will be redirected to the checkout page, where the registration process can be completed. This way, users won't have to use two separate forms.
My issue is (mostly) resolved now. Thank you!