Skip Navigation

[Resolved] Membership registration – checkout process

This thread is resolved. Here is a description of the problem and solution.

Problem:
When using the cred_commerce_after_order_completed hook, how is it possible to get the id of the user created by the process?

Solution:
The ID of the created user is stored in a hidden post meta field _cred_post_id stored with the WC order (which can be retrieved with get_post_meta).

Likewise if using Toolset Forms Commerce to charge users to publish posts, the ID of the published post is stored in the same field.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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+01:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Aaron Zame 5 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1148940

Hi there

Im currently building a site that users can register to become a member. There are three different subscription options that they can choose from. I'm using the Forms WooCommerce plugin as I want users to pay for their registration when they register.
I've added the three different subscription options into WooCommerce and made these products virtual products.
On the registration form they enter their name, email address and choose what subscription type they want. After they submit the form it redirects them to the checkout so that they can choose their payment type. The checkout page though still includes the billing details section.

Is there anyway to remove the billing details section? Because it is a virtual product I dont need to send them anything and I already have their name and email address from the registration form.

Do I need to use an external plugin to remove the billing section or can this be done through ToolSet?

Cheers
Aaron

#1149159

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

The workflow you describe using Toolset is built on top of the standard WooCommerce workflow, which requires the billing details even when buying virtual products that don't ship.

There isn't a Toolset solution, but you can use the WooCommerce API to modify the checkout page.

Here is an example post which describes fixing the issue, including linking to a code snippet you could use on your site that uses the woocommerce_checkout_fields hook to modify the checkout page: hidden link

See https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ for an official description.

#1149816

Great thanks, I was able to remove the billing details.
The trouble with removing the billing details is when the order gets inserted into WooCommerce it has the order number but no firstname and lastname of the user who made the order. This also means the emails that get sent out when a new order is made does not have the users name. Im assuming it gets the firstname, lastname from the billing fields.

I did read somewhere (cannot find it now) that I can control the billing fields through User Fields in Toolset. I've updated billing_firstname, billing_lastname, billing_email to be managed with Types.

On my user registration form I have included those three billing fields but have hidden them with css. From my understanding they should get auto populated from the user firstname field, user lastname field and user email field?

Cheers

#1149849

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

There is no reason to think they will get auto-populated.

If your registration field includes fields for first name and last name and you want to copy those to the hidden "billing_firstname" and "billing_lastname" fields, and do likewise with the email, you can either

- add some JavaScript to the form so that when a use enters a first name that value gets copied across to the hidden billing_firstname field, and ditto for the other fields, or
- don't include the fields in the form at all, and instead use the cred_save_data hook to add a little PHP so that when the user registration form is submitted and the user created, the relevant fields are copied across to the WC fields.

Which route you choose depends on whether you are more comfortable adding JS (or jQuery) or PHP.

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1150170

Ok I'm trying to update the WC fields using PHP, but because i'm adding payments to the form I'll need to use a Commerce Form Hook.
If I use cred_commerce_after_order_complete hook I lose the POST data from the registration form. If I use cred_commerce_form_action I still have the POST data from the form but I dont know the transaction id to update the billing fields in the database, e.g. update_post_meta($transactionid, '_billing_first_name', $_POST['first_name']);

Also the cred_commerce_after_order_complete hook, is there a way to get the ID of the new user that has been created by the registration form?

Cheers

#1150532

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I did some digging. It is not easy to find, but when you complete the process of registering the user by marking the order as complete (which then creates the user in wp_users), if you check wp_postmeta for that order you will see a hidden field "_cred_post_id" which stores the ID of what was created by this process.

In the case of registering a user, it is the user ID. (The same process can also be used for charging to publish posts, when it would be the ID of the published post.)

So with the cred_commerce_after_order_completed hook you have the order ID available (transaction_id), and you can use that to retrieve the user ID (_cred_post_id from wp_postmeta), which you can use to retrieve the name and email etc., which you can then use to update the WC billing fields (both on the order post meta and the user meta, they are duplicated it seems).

#1150851

Great, yes I was able to get the userid from the _cred_post_id field. Thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.