Skip to content

Commit efe21ae

Browse files
Merge pull request #37 from amirhmoradi/patch-1
Add order number filter to Woocommerce API
2 parents 63f16a4 + c93e2c1 commit efe21ae

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

woocommerce-sequential-order-numbers.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ public function initialize() : void {
218218
if ( is_admin() && ! wp_doing_ajax() ) {
219219
add_action( 'admin_init', [ $this, 'install' ] );
220220
}
221+
222+
// Register REST API custom order number filter
223+
add_filter( 'woocommerce_rest_orders_collection_params', [ $this, 'add_rest_custom_order_number_query_param' ] );
221224
}
222225

223226

@@ -473,6 +476,25 @@ public function custom_search_fields( array $search_fields ) : array {
473476
}
474477

475478

479+
/**
480+
* Register a custom query parameter for WooCommerce orders REST API to filter by custom order number.
481+
*/
482+
public function add_rest_custom_order_number_query_param( array $args ) : array {
483+
484+
if ( array_key_exists( 'number', $args ) ) {
485+
return $args;
486+
}
487+
488+
$args['number'] = [
489+
'description' => __( 'Allows filtering of orders by custom order number. Example: /wp-json/wc/v3/orders/?number=240222-45', 'woocommerce-sequential-order-numbers' ),
490+
'sanitize_callback' => 'rest_sanitize_request_arg',
491+
'type' => 'string',
492+
'validate_callback' => 'rest_validate_request_arg',
493+
];
494+
495+
return $args;
496+
}
497+
476498
/** 3rd Party Plugin Support ******************************************************/
477499

478500

0 commit comments

Comments
 (0)