Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acafourek/bd7af622ada13a0bb436a72b0a1e7276 to your computer and use it in GitHub Desktop.
Save acafourek/bd7af622ada13a0bb436a72b0a1e7276 to your computer and use it in GitHub Desktop.
Add modified to list of acceptable options for orderby param for the WooCommerce API
/ *
Add modified to list of acceptable options for orderby param
Allows you to fetch orders at /wp-json/wc/v3/orders/?orderby=modified&order=desc|asc
*/
add_filter( "rest_shop_order_collection_params", 'air_add_modified_to_param_validation',10);
function air_add_modified_to_param_validation($params){
if(isset($params['orderby']) && isset($params['orderby']['enum']) && is_array($params['orderby']['enum']))
$params['orderby']['enum'][] = "modified";
return $params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment