Home › Toolset Professional Support › [Closed] How to pass order ID and use it on a page
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.
This topic contains 6 replies, has 3 voices.
Last updated by Christopher Amirian 1 year, 6 months ago.
Assisted by: Christopher Amirian.
I am trying to pass the order details after clicking "Place Order" on woocommerce. This is done successfully and the order ID is passed to the new page that I have created. Now, I need to start working with the order ID so that I can display relevant forms and deata. How can I do that
The use-case is reported to the second-tier support.
I will inform you here if there is another solution from what I already mentioned in the chat.
Thanks.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Hi there
Let me ask you directly here rather than going through Christopher, as I want to understand exactly what the aim is.
I understand you have users placing orders. These must be for products, so I take it that you are placing an order involves ordering one or more program products.
You then redirect to some other page, passing the order ID to that page.
How? Via a URL parameter?
Now, on this page for each program product ordered you want the user to be able to "assign" these to a post (a post which would be the profile of a child).
So you would be connecting a product to a post.
Presumably at some point you then want to be able to refer to a child and see what program the child is signed up for (or, possibly, you want to look at a program and see which children are signed up for the program).
Does this all sound correct?
Yes. This is waht I want to do.
In my case, a product is a program. When a parent register as a user, he can add one or more kid to his profile using a custom post.
The parent can select one or more program to buy for his/her kids. So, after comleting the purchase, he should specify whcih kid will be eneolled for each program, sp as an example, the kid Mark, can be registerd for Enhlish Language and Robotics, while Alex is for Art, Robotics and Music.
You said it right, the parent should be able to kknow which programs where registered for their kids in his dashnoard. I should also know who is registered for each program.
Regards,
Azuz
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
OK. So it sounds like you need to create a many-to-many relationship between products and the profile post type for the children, so that you can connect the children to the programs.
(At some point you will want to familiarise yourself with Toolset relationships to understand how you will be able to display programs a child is signed up to, or children that are a signed up to a specific program.)
For this particular scenario we are discussing, your users have arrived at some page after placing an order, and the order ID is available on the page (you didn't say how you are doing that, but it sounds like you have it working).
On this page you need to display all of the products from the order, with a form to connect child posts to the products.
The UI for this may be a little clunky—it's not exactly an anticipated use-case—and it may be that it could be improved by the judicious use of a little custom code and the relationship API.
But working with the Toolset UI elements, you would add a View to this page which retrieves the products for the specified order, and then in the loop output of the View, for each product you show a relationship form where you can connect children posts to the product.
The relationship form would be to connect the current product from the View loop to a children post specified in the form dropdown.
To have a View output the products from an order you can use the shortcode wpv-ordered-product-ids (https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-555686) to generate a comma-separated list of product ids, so you can pass that to your View as a shortcode attribute (https://toolset.com/course-lesson/passing-arguments-to-views/).
The problem here is that passing shortcode attributes in this way is a feature of legacy Views and isn't directly supported by the block editor for Views.
Unless you are familiar with and happy using the legacy editor, here's how you get round that limitation.
Create a Content Template and then add your View block to show products to that template. It will need a Query Filter for the product ids with values passed by a shortcode attribute you specify (as explained in the documentation I linked to above). Design the output of your View as required.
The Content Template is just a block-editor-based container to hold the View. Make a note of the name of the View, you will need that.
On the page where you want to display the View you must insert the View using a wpv-view shortcode (https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view), to which you can add shortcode attributes as described in that documentation.
But, we've run into a limitation of the wpv-ordered-product-ids shortcode. It can only be used in the context of an order, i.e. when displaying a single order post, or in the output of a View which queries and loops over orders.
So, you have 2 choices. The first is to persist with your current solution, where placing an order redirects to some page, passing the order id. You would add a View to that page to query orders, and use a Query Filter to only return the order specified by the passed order ID. Then the output of this View has that order post for context, and you can add your View to display products of the order here (via shorcode so that you can pass the product ids output by the wpv-ordered-product-ids shortcode as a wpv-view shortcode attribute.)
Alternatively, instead of redirecting from placing the order to some page, you could redirect to the order post itself, and create a Content Template for single order posts. That way you could dispense with the extra View created in the previous step to provide the order context, because you already have it.
I didn't mention much about the relationship forms to connect children and programs, but they are described here: https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/
There is quite a lot to digest above, it's a fairly complex topic.
Please take the time to go through it and the relevant links, and I'll hand you back to Christopher who should be able to help you with any specific part of this overall plan.
Thank you so much for the detailed answer and information. They opened up many topics that I shall consider and understand but it help me understand the way forward.
I am not limited to redirecting to a new page that holds the order ID but it was the only way I was able to think of at that point of tume, hence I can consider the alternative solution that was suggested by the end of the previous response.
Please allow few more days so that I can go into the solution in details and try implementing it or come back with questions if any.
Thanking you i again for all tehe details.
Regards,
Aziz
Hi sure thing. Thanks.
The topic ‘[Closed] How to pass order ID and use it on a page’ is closed to new replies.