
The wc_get_orders function is the recommended method for fetching orders in WooCommerce due to its flexibility, safety, and adherence to best practices. It offers several advantages over using custom WP_Query or database queries. It’s also HPOS compatible.
You can specify various arguments to filter orders based on properties like status (pending, completed, on-hold, etc.), customer (ID, email), date range, order IDs, payment method, total, custom fields and more.
Today, I’d like to talk about paid orders – at the moment there is no way to filter out free orders with a wc_get_orders parameter, so we need to find a workaround.
My solution uses the “payment_method” parameter, which accepts a payment method ID (cheque, bacs, afterpay, paypal, stripe, woocommerce_payments, ppcp-gateway, klarna_payments, etc. based on the payment gateway plugins you use). Clearly, an order that comes with a specific payment method is a paid order.
Unfortunately you can only select one payment method (as opposed to an array), so we also need to do some array merging. Enjoy!
Continue reading WooCommerce: Retrieve Paid Orders Only