Skip Navigation

[Resolved] Orders Views Query Values

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 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)

This topic contains 2 replies, has 2 voices.

Last updated by abdullahA-6 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#911480
Orders view.JPG

Hi,

I want to create a view that shows the recent orders made by a user and displays it to the currently logged-in-user in their account page, I followed the steps in the link below :

https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-woocommerce-orders-on-the-front-end/

and I ended up having a view that shows the orders for each vendor, this is actually great tool and shows how great and powerful toolset plugins are, and I will use it for vendors to manage and have a quick visualisation of the orders made at their stores from the front end, but this not what I was looking for.

now I have two questions, first is how do I create a view that shows the recent orders made by the currently logged in users and the nested view should be the products in that order, and can display the status of the order.

and the second question, the view in the picture below is a view of users with role vendors, and a nested view of orders, and another nested view of products in the orders view, three nested views and it working great except for a minor issue, when displaying the billing addresses and the shipping addresses of that order it shows the addresses of the vendor not the customer who made the order (as shown in the picture, the addresses are for that vendor and not for the customer who made the order), even if remove the attribute { user_is_author='true' } from the shortcode.

it looks like the author of an order is the vendor who is selling that product, not the customer who made the order.
I know how to create nested views all I need is how should I build them to get these results.

#911653

Hello,

Q1) how do I create a view that shows the recent orders made by the currently logged in users and the nested view should be the products in that order, and can display the status of the order.

First, Views plugin does not support to query Woocommerce order posts.
Second, the Woocommerce plugins is using a custom field "_customer_user" to store the custom's user ID, for example, in a single order post, there is a custom field "_customer_user", the filed value is customer's user ID, so you can setup your query by the custom field value, see our document:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

You can also use PHP codes to setup your query:
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Q2) I know how to create nested views all I need is how should I build them to get these results.

Same as above, there isn't such a built-in feature within Views plugin, Wocommerce plugin is using a custom database table "wp_woocommerce_order_items" to store the product items of order, you might need to try with some custom PHP codes, for example this thread:
https://stackoverflow.com/questions/45706007/get-order-items-and-wc-order-item-product-in-woocommerce-3

For your reference.

#919645

Thank you Luo,

sorry for late replying, This has solved it "_customer_user",

and I can wrap the template with the conditional display as :

 [wpv-conditional if="( '[wpv-post-field name='_customer_user']' eq '[wpv-current-user info='id']' )"]

   // content : shows orders for the current user 

[/wpv-conditional]

the issue tho is when using the code :

first code : [wpv-post-field name='_customer_user']

will sometimes printout 0 for the id instead of the customer id.

where when using :

second code : [wpv-user field="ID" id="[wpv-post-field name='_customer_user']"]

will always return the right id ,
and I am trying to use the second code in the "users" attribute of this views short-code :

[wpv-view name="users-orders-view-nested-management-only" users="<!--ADDING THE CODE HERE-->"]

but I'm running into the quotation error, what's the right way of adding it. and what is rule of the quotations.

I tried this but doesn't work :

[wpv-view name="users-orders-view-nested-management-only" users="[wpv-user field="ID" id="[wpv-post-field name='_customer_user']"]"]

thanks!