Hello,
I using Toolset + WC and have this configuration :
Postypes "INS ENSEIGN" and "PRODUCTS" (WC one)
I need to create a form that helps to chose a product inside a list. Then, in the same form, I need to display dynamically a field with the product price. This display should be done before pressing the validation button.
Can you explain me how I can do this with Toolset?
Many thenks
Pat
Hi Pat,
Thank you for contacting us and I'd be happy to assist.
Before I can suggest a solution, I'll need to fully understand the existing setup and the requirement.
When you wrote "chose a product inside a list" did you mean that a product needs to be connected to an "INS ENSEIGN" post?
If yes, can you please share which type of post-relationship exists between the "INS ENSEIGN" and "PRODUCTS" post types?
( i.e. is it one-to-one, one-to-many or many-to-many )
regards,
Waqar
Hi Waqar,
Thanks for your return.
Currently, as the development of this site has been done more than one year, I had not used the Toolset relationship function.
The aim of this site is to propose some courses than could be bought by the members of this association. The courses are defined as products and I have created a postype "INS ENSEIGN" in order to be able to retrieve all info concerning a specific inscription (which course, price, ...).
This is needed because year after year, the course prices could evolve and we need to keep in memory all that have been done.
This being said, I need to find a way to populate dynamically the product price without modifying a big part of the site (as it is into production now !). There are 2 ways to create a "INS ENSEIGN" :
- In frontend by users. In this case, they are using the standard WC way of doing and everything is fine
- In frontend by admin association people. Here, they are able to create a new "INS ENSEIGN" thanks to a form in which they can choose the right product. There is also a field to indicate the product price manually, but it will save time and accuracy if this product price could be display dynamically !
Thanks for your time
Pat
Hi Pat,
Thank you for sharing these details and this all makes sense.
When you mentioned that the admin association people are able to create a new "INS ENSEIGN" from the frontend using a form, I'll assume that it is a Toolset Form.
If that is correct, you can use a hook, like "cred_save_data" to execute a custom function that gets the price value from the selected product and save it as custom field value with the created "INS ENSEIGN" post.
Here are some useful resources on the topic:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://wordpress.stackexchange.com/a/296199
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Hi Waqar,
Thanks for coming back on this topic.
I understand your point but this is not what I need.
I want the product price to be populated automatically inside the form when the admin guy is filling it in the frontend (and allow him to ensure this is the right price and if not, he will be able to change it manually).
The form is located on the product single page, so that should be feasible to retrieve the info?
Is there a way to manage it this way?
Regards
Pat
Hello,
Waqar is on vacation, I will take care this thread.
According to the description you provided above, I assume we are talking about this case:
When user fill above form in front-end, you are going to display different product price before user submit the form.
How do you setup this post form? Is it a Toolset post form for creating new "INS ENSEIGN" post?
Is there any post type relationship between post type "INS ENSEIGN" and "PRODUCTS"? if there is, how do you setup the post type relationship?
Please elaborate the questions with more details, thanks
Hi Luo,
Thanks for taking care.
I have a form to create "INS ENSEIGN" but do not have any relationship right now (the development of this site has been done 1.5 year ago and I was not willing to move to this new feature at that time.
So my current issue is to display inside the form, the product price of the selected product, even if we are not on the product page : as this is a kind of frontend admin, the form is used by admin people to create new "INS ENSEIGN" based on a specific product which is chosen inside a select list.
So, in the first field of the form, we have to chose the needed product and then, I would like the price of this selected product to be displayed in the next field of the form (if possible as a default value with the option to modify it manually).
Regards
Pat
How do you setup this field "specific product which is chosen inside a select list" in Toolset post form for creating new "INS ENSEIGN" post?
With custom codes? or manually HTML codes?
Please provide detail steps to duplicate the same problem, thanks
Hi Luo,
Currently, I'm using a genberic field and a Views as option :
[cred_generic_field type='select' field='wpcf-id-du-produit-achete']
{
"required":0,
"persist":1,
"options":[ [wpv-view name="backoffice-select-enseignement"] ]
}
[/cred_generic_field]
Regards
Pat
Thanks for the details, there isn't such kind of built-in feature within Toolset Forms generic field or other fields, it needs custom codes, for example:
you can edit the post view "backoffice-select-enseignement", in view's loop, display the product value into option title, when administrator view the field "wpcf-id-du-produit-achete" of post form in front-end, he will see the product price too.
And after user choose one of option in field "wpcf-id-du-produit-achete", setup custom JS codes:
versteckter Link
Get the price from option title, and put it into "the next field of the form"
versteckter Link
Hi Luo,
Thanks for the clarification.
I will work on this in the next days, so I propose to let the ticket open and come back to you as soon as I have been able to test the proposed solution.
Regards
Pat
I have marked this thread as "Waiting for feedback" status, please update here when you need more assistance for it, thanks
Hi Luo,
I'm coming back on this topic after some tests. I have tried your solution (ie : modifying the view "backoffice-select-enseignement" by adding the product price into the title.
I'm getting a strange result :
The current view :
<wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]"}
</wpv-loop>
is working well. I can see the list inside the select box in my form.
Now, if I add the product price into the title like this :
<wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-woo-product-price]"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-woo-product-price]"}
</wpv-loop>
then, the selection box is empty in the form!
If I replace the product price by the product ID or another field, that's working !
Is there anything I have to take care to make it work?
Regards
Pat
The shortcode [wpv-woo-product-price] outputs results wrapped in HTML tags, it will break [cred_generic_field] shortcode, and conducts the problem you mentioned above.
Please try the shortcode [wpv-post-field name="wpcf-views_woo_price"], and test again
Hi Luo,
Thanks for the info.
Just tried it and the result is that the Views works, but the price is not displayed !
I've checked in the database and the field views_woo_price is present and valid in the products ! So I have changed the meta key to views_woo_price and it is working fine now.
A last issue : in general, the products are simple products and this is working fine. But I have also some variable products and in this case, this is not working.
Any idea how I can use a select views in order to chose the product and the variation?
Regards
Pat