Returns for WooCommerce exposes two PHP functions that let you query return and exchange data for a given order — useful when building custom integrations, reporting tools, or automations. Add calls to your child theme’s functions.php file or a custom plugin.
1. Retrieve Return Order Details
Use get_data_by_order_id() to retrieve all return requests associated with a WooCommerce order.
Function Overview
- Function:
get_data_by_order_id( $order_id ) - Parameter:
$order_id(int) — The WooCommerce order ID. - Returns: (array) — An array of return request data objects for the order, or an empty array if no return data exists.
2. Retrieve Exchange Order Details
Use get_exchange_data_by_order_id() to retrieve all exchange requests associated with a WooCommerce order.
Function Overview
- Function:
get_exchange_data_by_order_id( $order_id ) - Parameter:
$order_id(int) — The WooCommerce order ID. - Returns: (array) — An array of exchange request data objects for the order, or an empty array if no exchange data exists.