Skip Navigation

[Résolu] filter orders in view

This support ticket is created Il y a 5 années et 3 mois. 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.

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Marqué : ,

This topic contains 6 réponses, has 2 voix.

Last updated by Nigel Il y a 5 années et 3 mois.

Assisted by: Nigel.

Auteur
Publications
#1167515

Hi, I created a view with all woocommerce order.

I need to filter this order in base of category of the product bought. How can I do?

#1167672

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

That's not possible. It wouldn't be possible if you were writing your own custom WP_Queries by hand, and so it is not possible with Views.

You can only filter posts by properties of those posts.

Product categories belong to products. They are not a property of orders.

You can only filter orders by fields or taxonomies of orders.

What you are aiming for would require a custom solution. You could try consulting the Toolset Contractors page for someone to develop this: https://toolset.com/contractors/

#1167892

If I set a relationship between Product and Orders, could I get category rom the parent (product) and use it as filter?
What do you think? Should be possible?

#1167907

OK Nigel, I find a possible solution. I set a relationship between orders and product.
So in the view I can Get the category of the product as parent, and use it as filter. It works.

I only need your help to hiw to set this relationshio automatically. When a new order is created ,should be automatically set a relationship with the product of the order. Please , can you help me in this issue?

#1167926

With this code I set automatically the relationship.

// Set product-order relationship 
add_action( 'woocommerce_thankyou', 'relate_product_order_func', 999,2 );
function relate_product_order_func( $order_id ){
	
	$order = wc_get_order( $order_id );
	foreach($order->get_items() as $order_key => $order_value)
        {
	     $product_id = $order_value->get_data()['product_id'];
        }   
	
	toolset_connect_posts('prodotto-prenotazione',$product_id, $order_id);
	
}
#1167931

Hi Nigel,

Now for each order I've the relative product category.

How can I filter the view in base of the category of the parent?

#1168538

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, but filtering by fields (or taxonomies) of related posts isn't yet supported. The intention is to add such support, but among the competing demands on the developers' time it hasn't yet made it to the front.

(You can push for it to be developed here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/.)

In the meantime you would need to duplicate the product category taxonomy on orders to be able to filter orders by product category. So you could modify the code you use above to connect an order with a product to instead get the product category from the product and apply it to the order post.

You would then be able to filter orders by product category.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.