Skip Navigation

[Resolved] Creating WooCommerce products using custom fields of a user profile

This support ticket is created 5 years, 7 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.

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 puneetS-3 5 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1266459

Is it possible to Create WooCommerce products using custom fields of a user profile?
When a user creates a profile on my website, can I use his/her profile fields to create a WooCommerce product?

#1266597

Nigel
Supporter

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

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

Is it possible to Create WooCommerce products using custom fields of a user profile?

Probably, yes, but not with Toolset. You would need to create products programmatically using the WooCommerce API, so I suggest you read through the WooCommerce documentation to understand how you might do that: https://docs.woocommerce.com/

The one part where Toolset can help is, if you have a form to register users where they create their profile and fill out the user custom fields, you can use the cred_save_data Toolset API hook to trigger whatever code you write to create the WooCommerce product: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

I can help you with setting that up if you need it, but I can't help with the code to create WooCommerce products.

#1266657

It would be great if you could help me set it up.
I will share my website credentials soon on the same thread.

#1266667

Nigel
Supporter

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

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

I don't need access to your site.

The main part of your request is programmatically creating WooCommerce products, which I can't help you with, you'll have to consult the WooCommerce documentation, or a developer familiar with WooCommerce.

A small part is using the cred_save_data hook to trigger that code.

To do that you can add a code snippet at Toolset > Settings > Custom Code.

You can then paste in the following code:

/**
 * Custom form action
 */
add_action('cred_save_data', 'tssupp_user_form_submit', 10, 2);
function tssupp_user_form_submit($user_id, $form_data)
{
    $form_id = 123; // Edit for your form ID

    if ( $form_data['id'] == $form_id ) {

        // do something


    }
}

Edit the ID of the user form used to register the user profile.

The code itself doesn't do anything, but it will be triggered when the user form is submitted. The user ID is available which you can use to retrieve custom field values using the standard WordPress function get_user_meta (https://developer.wordpress.org/reference/functions/get_user_meta/).

Then you'll want to create the products according to the WooCommerce documentation.

#1269009

My issue is resolved now. Thank you!