Skip Navigation

[Resuelto] List all orders related to a product

This support ticket is created hace 3 años, 5 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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: Africa/Casablanca (GMT+01:00)

Este tema contiene 19 respuestas, tiene 2 mensajes.

Última actualización por Jamal hace 3 años, 5 meses.

Asistido por: Jamal.

Autor
Mensajes
#2104723

Hello Pat and my apologies for the late reply, but I do not work on Wednesdays and Thursdays https://toolset.com/forums/users/jamal-b/

Actually what you are looking for now is a different set of data that will need a different approach. The original question was about getting the users that have bought a product. Once you got the IDs, you can use them in a query filter to display a list of users(user view).

What you are looking for now, is a piece of data that is stored on orders(custom post type registered by WooCommerce). So, this will need a different approach.

Because WooCommerce stores order items data in separate tables, that will also require a custom SQL query. Please reach to the WooCommerce support for assistance, or to an online support community such as StackOverflow, or StackExchange. This request is out of the scope of Toolset support. I am sure you will understand that.

#2104945

Pat

Hi Jamal,

No issue, I understand that anwsers cannot be given always at "real time" !

Concerning my request, let me say it differently :
The first request was to get all customers of a specific product. For that, you have proposed to use a user Views + a specific function and that works fine.
Now, if I want to move the other way, the first thing I need is to start to list orders related to a product. Within Views, we have the possibility to manage orders. But what kind of info can I get from the order inside the Views (product bought including variant?, qty, date ...). If I can add the user ID, then, I'm getting everything I need and the only thing is to modify the function in order to list all orders related to a specific product?

I never used a Views with orders until now and would be happy to have your return on this!

Let me know
Regards
Pat

#2105023

Hello Pat,

Well, your first question and your late question are both very WooCommerce specific. Only a part of it can be related to Toolset. And I'll explain how is that below.

First of all, Toolset views(post/user/taxonomy views) can be filtered using query filters. The post views can be filtered using custom fields, taxonomies, and ONE relationship. Taxonomy views can be filtered using term fields. User views can be filtered using user fields.
However, all Toolset views can also be filtered by IDs, and that's the Toolset specific part of my reply. Especially this custom code:

add_filter( 'wpv_filter_user_query', 'include_customers_by_product_id', 99, 3 );
  
function include_customers_by_product_id( $query_args, $view_settings, $view_id){
    global $product;
    if ( $view_id == 123 ){
        $query_args['include'] = get_customers_by_product_id( $product->ID );
    }
    return $query_args;
}

Please note, that we may not need this custom code at all, if we filter the view using a shortcode argument. Something like this:

[wpv-view name="the view to display a product buyers" customers="[a-custom-shortcode-that-will-return-customers-ids]"]

I suggested using a user view because you initially asked to display "firstname, lastname, mail and some other userfields".

However, your question is actually WooCommerce specific, for the simple reason that WooCommerce uses its own tables to store an order's items data. Especially "{prefix}woocommerce_order_items " and "{prefix}woocommerce_order_itemmeta" tables as you can see in lines 4-5 of my initial suggested code.

       INNER JOIN {$wpdb->prefix}woocommerce_order_items AS i ON p.ID = i.order_id
       INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS im ON i.order_item_id = im.order_item_id

WooCommerce registers some custom post types, that are stored in regular WordPress tables("{prefix}posts" and "{prefix}postmeta"). These post types are "product", "product_variation", "order", and "coupons". So, these can be displayed using Toolset. The data that links an order to a product is stored in "{prefix}woocommerce_order_items " and "{prefix}woocommerce_order_itemmeta" tables. And Toolset has no access to this information.

So, your last question is to get the following data, right?
1. Date of the purchase
2. Quantity of purchased product.
3. Product variant chosen (I'm working here with variable products)
Which we can rephrase as "Get the information of a product in all orders made by a specific user", right?
I am sorry to tell you, that this is a WooCommerce specific question. And it CANNOT be done without custom code.

This brings us to our support policy https://toolset.com/toolset-support-policy/

We will not provide a custom code that does not use the API of our plugins or is not related to it. The code snippets we provide also depend on the amount of custom code required to resolve a specific client issue.

And I am afraid, that what you are trying to achieve will need complex custom code that needs a wide knowledge of the WooCommerce internals.

Please reach out to the WooCommerce support, an online support community, or hire a developer to achieve that. Check the list of our partners here https://toolset.com/contractors/

All the best,
Jamal

#2105089

Pat

Hi Jamal,

I can understand your point.
Now, I would like to better understand what is feasible within a Views managing WC orders (which is currently a possibility offered by Toolset !).
Can you provide me with a link to a page where I can have all needed info on this?

Regards
Pat

Los hilos nuevos creados por Jamal y vinculados a este se encuentran a continuación:

https://toolset.com/es/forums/topic/managing-woocommerce-orders/

#2105431

Hello Pat,

I'll do my best to explain what can be done through Toolset regarding WooCommerce orders. However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason, I have created another ticket to answer your question. I'll be posting my reply there.

I'll kindly ask you to mark this ticket as resolved.

All the best,
Jamal