On my custom post(type Product) page CRED post form creates new post(type Order) .
How to get current Product data into form and post it?
For example:
We are on my Sample Product page and composing order(filling CRED form).
Form fields like customer name, mail etc are there.
Wish to add automatically product name and price to order.
Hi,
Thank you for contacting us and I'd be happy to assist.
To automatically populate the data in the form fields, you can use relevant Toolset shortcodes in the default value option in the form field settings.
For example, to get the current logged-in user's data, you can use the 'wpv-user' shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-user
Likewise, to get the data from the current product (whose single product page is being used), you can use the shortcodes like 'wpv-post-title', 'wpv-post-field' etc:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/
I hope this helps and please let me know if you need further assistance.
regards,
Waqar
Can You give me a sample piece of code to populate my product SKU(custom field slug is 'prod-sku') in to form field 'tel-sku'.
Here is the row in my order form:
[cred_field field='tel-sku' placeholder='SKU' force_type='field' class='form-control' output='bootstrap']
Yes, you'll include the field's value shortcode [types field='prod-sku'][/types] in the 'value' attribute like this:
[cred_field field='tel-sku' placeholder='SKU' force_type='field' class='form-control' output='bootstrap' value='[types field='prod-sku'][/types]']
Related documentation links:
https://toolset.com/documentation/customizing-sites-using-php/functions/
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field
Thanks Waqar,
This works fine. Help me also to post some Product field values to Orders if checkbox checked.
For example Product field Installation cost(field='installation') I wish to save into Order field Extras(field='extras') if customer checks checkbox.
Glad I could help.
For something like this you can use the 'cred_save_data' hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This hook can be used to fire a custom function that executes when the form's data (order) has been saved to the database.
In your function, you can check if the checkbox has been checked or not. And if checked, you can get the required custom field values from the product and save them in the 'extras' field of the order itself.
Looks good, but I am still processing.
Let's keep this ticket open for some time.
Sure, please take your time and the ticket will stay open for a couple of weeks.