Home › Toolset Professional Support › [Resolved] Product update post meta
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 |
---|---|---|---|---|---|---|
- | 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)
Tagged: CRED API, Toolset Forms
Related documentation:
This topic contains 25 replies, has 3 voices.
Last updated by Bochnacki 7 years, 4 months ago.
Assisted by: Luo Yang.
1. I have a Custom Field "featured-opt" with a few checkboxes. It is assigned to products and posts.
2. To the cart I have added products that can be combined with purchases made through CRED forms.
3. Each of these added products has one (for each product other) selected from the "featured-opt" CF.
I want to after buy one of these products, has saving the CF value to the created post. Screen "featured-opt.jpg".
I wrote the code:
add_action( 'cred_commerce_after_payment_completed', 'add_featured_option', 10, 1 ); function add_featured_option( $data ) { $featured_option = $data['cred_product_id']; //WooCommerce Product ID associated to the buying process $post_id = $data['cred_post_id']; //Post ID that was created/edited with the form update_post_meta( $post_id, 'wpcf-featured-opt', $featured_option); }
Unfortunately this code does not work and I do not know how to fix it.
Can anyone help me?
Hello. Thank you for contacting the Toolset support.
Well - Types checkboxes fields are special complicated fields and its stored as serialized array which is hard to access.
I suggest you convert your custom field checkboxes option to custom taxonomy and add options as taxonomy terms and then try to use WordPress's standard function wp_set_object_terms to setup associated taxonomy term values.
=> https://codex.wordpress.org/Function_Reference/wp_set_object_terms
Sorry, but I do not understand your suggestion.
I do not know how the new taxonomy can help solve my problem.
I need to give the user additional paid options when buying/adding a post.
So the user using the CRED form adds post, and additionally has the option to buy options for this post.
I really do not know how it can be done using taxonomists...
As I understand you have the custom field which stores the checkboxes option value - which is attached to your post type - correct? If yes,
What you should do is transform checkboxes options to taxonomy terms. To do that, you should create a custom taxonomy and add checkboxes option names as taxonomy terms - Could you please confirm you understand this.
"As I understand you have the custom field which stores the checkboxes option value - which is attached to your post type - correct? If yes," - exactly.
Taxonomy I created, but I do not understand "and add checkboxes option names as taxonomy terms" ????
How do I do that?
I admit that I still do not see the point of this solution.
How can it later be selected/added in the basket? Is this new taxonomy supposed to be assigned to a product? How can a user pay for an additional option?
Well - you have "option 1", "option 2" etc..etc.. setup as checkboxes correct?
Now, to newly created taxonomy add "option 1" and "option 2" as taxonomy terms.
How do I do that?
I do not see any fields to add "option 1" and "option 2".
Can you describe it more closely to me - where in the boxes? Or maybe give screen.
Well - have you created custom taxonomy? If yes - have you attached the taxonomy to your post type?
Don't forget to set your taxonomy "Hierarchical ".
See this Doc on taxonomy with all info:
https://toolset.com/documentation/user-guides/create-custom-taxonomies/
So I did.
I also added "option 1" and "option 2".
What's next?
Now - I would like to know, what will be the relation of product ID and taxonomy term when order is completed?
I mean, with regards to current setup, what status you want to update when order is completed?
Custom filed has a "featured-opt" slug and options: inhome, featured, intop.
One of the options I assigned to each product:
Produkt 1 -> inhome
Product 2 -> featured
Product 3 -> intop
So depending on which option (which product) I choose when buying, this should be assigned to the post as post meta. Screen "featured-pot.jpg".
I hope you asked this.
Well - first of all, what is the reason to add the value to post meta key?
Have you added "Inhome", "Featured", "intop" as taxonomy terms?
Produkt 1 -> inhome
Product 2 -> featured
Product 3 -> intop
So,
Produkt 1 -> attached to taxonomy term inhome
Product 2 -> attached to taxonomy term featured
Product 3 -> attached to taxonomy term intop
Now, my question is as product is already attached to above taxonomy term, do you mean that you want to attach same taxonomy term to which product is attached to with the post ID (order) you created?
I do not understand.
No product is related to the above taxonomic term. I wrote that the "featured-opt" field options are assigned to the products.
My idea was that:
1. I have Custom Field "featured-opt" with options. Product 1 has marked option "inhome", Product 2 has marked option "featured", Product 3 has marked option "intop"
2. By creating a new post via CRED forms, I pay for it and additionally in Cart I can select Product 1 or Product 2 or Product 3.
3. If I select Product 1, then option "inhome" should be assigned to the post, if Product 2 - option "featured", if Product 3 - option "intop".
Post options should be assigned so that I can use a shortcode for example:
[wpv-conditional if = "(wpc-featured-opt) eq 'inhome')"] ..... [/ wpv-conditional]
Your idea for now I do not understand, so I do not know what to do. So far I have created Custom Field "featured-opt" (with options "inhome", "featured" and "intop") and Taxonomy (named "Tax-test") with 3 items (screen "tax-test.jpg").
I still do not know what to do next.
2. By creating a new post via CRED forms, I pay for it and additionally, in Cart I can select Product 1 or Product 2 or Product 3.
=> Have you attached Taxonomy (named "Tax-test") to the post type? If no, please edit your taxonomy from: Toolset => Taxonomies and set the taxonomy to display on your post type.
3. If I select Product 1, then option "inhome" should be assigned to the post, if Product 2 - option "featured", if Product 3 - option "intop".
Post options should be assigned so that I can use a shortcode for example:
[wpv-conditional if = "(wpc-featured-opt) eq 'inhome')"] ..... [/ wpv-conditional]
=> Yes - you can do same thing using the texonomy (named "Tax-test").
What we are doing is we are using Taxonomy instead of the custom field.
Is it possible for you to share problem URL and exact steps I need to follow.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Could you please share link and steps I need to follow to buy any product just to make sure I'm following correct steps.