Created
August 31, 2023 18:50
-
-
Save tflight/52bc3760cf19f0db3ee68eee92e5bd06 to your computer and use it in GitHub Desktop.
When ShippingEasy sends API request for all orders, just show them orders in the custom status
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 | |
/** | |
* When ShippingEasy sends API request for all orders, just show them orders in the custom status | |
*/ | |
add_filter('woocommerce_rest_orders_prepare_object_query', 'shippingeasy_woocommerce_rest_orders_prepare_object_query', 10, 2); | |
function shippingeasy_woocommerce_rest_orders_prepare_object_query($args, $request) | |
{ | |
if ($request->get_header('User-Agent') !== 'ShippingEasy') { // if the User-Agent is not Shipping Easy, bail | |
return $args; | |
} | |
if ($request->get_route() !== '/wc/v2/orders') { // if not for this specifc route, bail | |
return $args; | |
} | |
if (isset($request->get_query_params()['status'])) { // if the status parameter is set, bail | |
return $args; | |
} | |
if (isset($request->get_query_params()['include'])) { // if the include parameter is set, bail | |
return $args; | |
} | |
if (!isset($request->get_query_params()['after'])) { // if the after parameter is not set, bail | |
return $args; | |
} | |
if (!isset($request->get_query_params()['per_page'])) { // if the per_page parameter is not set, bail | |
return $args; | |
} | |
if (isset($args['post_status']) && $args['post_status'] === 'any') { // woo will force to any if not specified | |
$args['post_status'] = 'wc-custom_1'; // force Shippingeasy to only see orders in this status | |
return $args; | |
} | |
return $args; // if we didn't bail above, do so now | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment