Last active
March 6, 2025 04:33
-
-
Save webtoffee-git/840271b839ed82f64dbb0195126b26f6 to your computer and use it in GitHub Desktop.
Retrieve Order ID Using _order_number Metadata via WooCommerce REST API - By WebToffee (Sequential Order Number for 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 //Do not copy this line of code | |
/*You can fetch the Order ID based on the _order_number metadata using WooCommerce's REST API. To do this, use the following API endpoint: | |
wp-json/wc/v3/orders?meta_key=_order_number&meta_value=123 | |
Simply replace 123 with the desired order number to retrieve the corresponding Order ID.*/ | |
add_filter( 'woocommerce_rest_shop_order_object_query', function( $args, $request ) { | |
if (! empty($request['meta_key'] ) &&! empty( $request['meta_value'] ) ) { | |
$args ['meta_query'] = array( | |
array ( | |
'key' => sanitize_text_field( $request ['meta_key'] ), | |
'value' => sanitize_text_field( $request ['meta_value'] ), | |
'compare' => '=' | |
), | |
); | |
return $args; | |
} | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can fetch the Order ID based on the _order_number metadata using WooCommerce's REST API. To do this, use the following API endpoint:
wp-json/wc/v3/orders?meta_key=_order_number&meta_value=123
Simply replace 123 with the desired order number to retrieve the corresponding Order ID.