Open wppunk opened 4 years ago
Good idea! In my old plugin I use some variant of sql code above. But it is not usable...
Hi @wppunk,
Thank you for taking the time to share this idea, we really appreciate your help.
While this is clearly a great improvement/idea we won’t be able to tackle it in the upcoming weeks. We’re going to add it to our backlog where it will be considered for future releases.
Stay tuned for updates.
@ObliviousHarmony I did it using default WP_Query hooks. This can somewhere help for you.
add_filter( 'posts_join', function ( $join, $query ) {
if ( ! $query->get( 'shipping_method' ) ) {
return $join;
}
global $wpdb;
$join .= ' LEFT JOIN ' . $wpdb->prefix . 'woocommerce_order_items as woi ON wp_posts.ID = woi.order_id';
$join .= ' LEFT JOIN ' . $wpdb->order_itemmeta . ' as woim ON woi.order_item_id = woim.order_item_id';
return $join;
}, 10, 2 );
add_filter( 'posts_where', function ( $where, WP_Query $query ) {
if ( ! $query->get( 'shipping_method' ) ) {
return $where;
}
global $wpdb;
$where .= ' AND woi.order_item_type = "shipping"';
$where .= ' AND woim.meta_key = "method_id"';
$where .= $wpdb->prepare( ' AND woim.meta_value = %s', $query->get( 'shipping_method' ) );
return $where;
}, 10, 2 );
P.S. Also I don't understand why you have $wpdb->order_itemmeta
, but don't have a $wpdb->order_items
Is your feature request related to a problem? Please describe. I need to get all orders with the something shipping method.
Describe the solution you'd like I want to use
WC_Order_Query
to get an order with the something shipping method.So in
WP_Order_Query
we can get by payment method but can't by shipping method.Describe alternatives you've considered I'm using a SQL query for this. But its not better solution.