Skip Navigation

[Gelöst] filter orders in view

This support ticket is created vor 5 Jahren, 10 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Nigel vor 5 Jahren, 10 Monaten.

Assistiert von: Nigel.

Author
Artikel
#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

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: 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

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: 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.