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).
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?
> 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.
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.
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 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.