How can I get a WooCommerce order by its number (instead of its ID)?
I tried using wc_get_orders with custom args, like:
wc_get_orders( array( 'number' => '1000' ) );
But it doesn't seem to work.
Thanks!
How can I get a WooCommerce order by its number (instead of its ID)?
I tried using wc_get_orders with custom args, like:
wc_get_orders( array( 'number' => '1000' ) );
But it doesn't seem to work.
Thanks!
Order numbers functionality is really enabled through a third party plugin in WooCommerce… Then in this case a new
meta_key
exist inwp_postmeta
database table forshop_order
WooCommerce post type which is_order_number
.So this parameter doesn't exist by default when using
wc_get_orders()
(in aWC_Order_Query
).But you can add/enable the "
number
" parameter using the following code:Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Now you can use
number
parameter to get an order from it's order number via aWC_Order_Query
:See in the documentation: Adding Custom Parameter Support in a WC_Order_Query.