Open btribouillet opened 6 years ago
I ended up using posts_where filter as a quick fix to change the post_status string.
function shop_order_where_statement( $where ) {
$post_status_needle = "(wp_posts.post_status = 'publish' OR wp_posts.post_status = 'aw-disabled' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private')";
if( strpos( $where, "wp_posts.post_type = 'shop_order'" ) !== false && strpos( $where, $post_status_needle ) ) {
$order_post_status = "(wp_posts.post_status = 'wc-pending' OR wp_posts.post_status = 'wc-processing' OR wp_posts.post_status = 'wc-on-hold' OR wp_posts.post_status = 'wc-completed' OR wp_posts.post_status = 'wc-cancelled' OR wp_posts.post_status = 'wc-refunded' OR wp_posts.post_status = 'wc-failed')";
$where = str_replace( $post_status_needle, $order_post_status, $where );
}
//removes the actions hooked on the '__after_loop' (post navigation)
remove_all_actions ( '__after_loop');
return $where;
}
add_filter( 'posts_where' , 'shop_order_where_statement' );
But I think this is still an issue, the quick fix seems a little bit dirty in my opinion.
Any advises for a proper solution or is it really an issue?
Hi,
Since shop_order use different status, the standard post_status is not used, but instead:
'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded' and 'wc-failed'.
The first thing i noticed is that my connection "shop_order_to_warehouse" (warehouse is a cpt) in admin order single page. Does not show my selected warehouse (but i can't select another one since i use a many-to-one cardinality.
Screenshot
Here my connection:
So the second thingi noticed is that i query the connected cpt in admin orders list to add some extra data in the order table.
I managed to have the correct object from get_queried_object() but $connected is empty.
Generated SQL:
I tried passing the wc status in the connected WP_Query
Generated SQL:
As we can see it does not use the correct post_status since shop_order use different status.
The correct SQL (tested) should be :