Created
July 7, 2021 01:58
-
-
Save kingjmaningo/cd970aa4c03b927f36d5882314cab893 to your computer and use it in GitHub Desktop.
Recognise order meta for you to b e able to use it in your args to display specific orders - Woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add this filter to recognise meta key when you do your order query | |
add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', 'my_function', 10, 2 ); | |
function my_function( $query, $query_vars ) { | |
if ( ! empty( $query_vars['_my_custom_order_meta'] ) ) { | |
$query['meta_query'][] = array( | |
'key' => '_my_custom_order_meta', | |
'value' => esc_attr( $query_vars['_my_custom_order_meta'] ), | |
); | |
} | |
return $query; | |
} | |
// Then when you want to get orders under that meta key | |
$args = array( | |
'_my_custom_order_meta' => 'your_meta_value', | |
); | |
$new_order_query = new WC_Order_Query( $args ); | |
$orders = $new_order_query->get_orders(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment