Skip Navigation

[Résolu] User , form and Product serial numbers

This support ticket is created Il y a 5 années et 5 mois. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Luo Yang Il y a 5 années et 4 mois.

Assisté par: Luo Yang.

Auteur
Publications
#1291229

Tell us what you are trying to do?

We have a product that each box will have a unique serial number.
"1 box - 1 serial number"

Then when the customer bought it, they could use that serial number to register in the website for their future benefit.

Flow:
1.Customer bought the product
2.Get the serial to register in website(form)
3.Compare the number to database
4.If repeat > Show error
5. If not repeat > Regist

Question:
1. Can I make a serial number fields that is a unique one?
2. Can I make a form to let the customer register their serial number.? And most important, validate that it did not been use to register yet.
3. Can it Save the serial number to user fields? so we can export to see who buy which serial.

#1291507

Hello,

There isn't such kinds of feature within Toolset plugins, it needs custom codes, here are my suggestions.

1) Create a custom post type "serial numbers", with two fields:
- serial number(single line)
- used (checkbox)

1) You can follow our document to setup a Toolset user form for creating "serial numbers" post, and charge them with Woocommerce plugin:
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/

2) After user submit the above post form, and complete Woocommerce order, you can use action hook "cred_commerce_after_order_completed" to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed

3) In this custom PHP function do these:
- Get the new post ID, see above document, parameter "cred_post_id"
- Use the new post ID to produce an unique serial number, for example:
lien caché
- save the serial number into "serial number" field:
https://codex.wordpress.org/Function_Reference/update_post_meta

4) After user log into your website, show him a wordpress page, in this page display a post view:
- Query "serial numbers" posts,
- filter by post's author is logged in user
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/
- display the "serial number" and "used" fields value
Then he will be able to share the "serial number" to his friends.

5) Create a user field "serial number" (single line)

6) Create a user form for register new users with above "serial number":
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-registering-users/

7) After guest submit above form, use filter hook "cred_form_validate" to trigger a custom PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

in this PHP function, do these:
a) Get the posted "serial number" field value
lien caché
use above value to query in "serial numbers" posts, with two filters:
- "serial number" field = posted "serial number" value
- "used" field = empty
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
b) If there isn't any result found, then return an error message
c) If there is a result found, then update the "used" field value to 1

For your reference.

#1294283

Hi Luo Yang
Thank you for your answer.
It is a lot , I will try to do what you suggested.
I need to have sometimes to test it .

#1294321

OK, please update this thread when you need more assistance for it, thanks