Problem: I have a CRED Commerce form that includes a select field where Users can choose a custom variation option. I would like to use that custom variation option to determine which product should be added to the User's cart.
Solution: First you need to modify the generic select field so that each option has a unique value.
Then, set up a custom field on the Listing post type that will hold the value of the Listing Option selection. Add that field to the CRED form, and hide it using CSS. Write custom JavaScript to copy the value from the Listing Option field into this hidden field before the form is submitted. Then you can access the Listing Option value in your cred_commerce_add_product_to_cart callback and do whatever you need to do with it to determine which product should be added to the cart. For example, this line in the code above will let you access the custom field value:
$pid = get_post_meta($post_id, 'wpcf-your-hidden-field-slug',true); // get the value of the Listing Option field
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 replies, has 2 voices.
Last updated by 6 years, 7 months ago.
Assisted by: Christian Cox.