Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tflight/52bc3760cf19f0db3ee68eee92e5bd06 to your computer and use it in GitHub Desktop.
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
<?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