Hello
it’s not custom field 🙁
as WooCommerce adds refunds as suborders.
If you use free version – you should program it.
If you use pro version – visit tab Profiles, select “Order Refund”, press “Add Profile” and use Date Range filter.
thanks, Alex
About free version.
I think you use Date Filter , so add this code to “Misc Settings” .
It should add partial refunds to list of fully refunded orders.
You can modify SQL to export only main orders which have refunds in selected date range.
thanks, Alex
add_filter( "woe_get_order_ids", function($ids) {
global $wpdb;
$from_date = WC_Order_Export_Engine::$current_job_settings["from_date"];
$to_date = WC_Order_Export_Engine::$current_job_settings["to_date"];
$refunds = $wpdb->get_col("SELECT ID AS order_id FROM {$wpdb->prefix}posts AS orders WHERE orders.post_type in ( 'shop_order_refund') AND orders.post_date>='{$from_date} 00:00:00' AND orders.post_date<='{$to_date} 23:59:59'");
return array_merge($ids,$refunds);
});
Hi,
I am using pro version, and used “order refund” with data range filter. And yes it returns me the order ID corresponding to the date of first refund date range that I am looking for.
But it doesn’t export all other fields that I need, which are attached to the main order (like the shipping country).
Also I tried to add the function you suggested, but doesn’t to work (or I miss something).
When I use the debug mode, I don’t see your SQL request being executed.
SELECT ID AS order_id
FROM wp_posts AS orders
WHERE orders.post_type in ( 'shop_order')
AND 1 AND orders.post_date>='2021-10-01 00:00:00'
AND orders.post_date<='2021-10-31 23:59:59'
AND orders.post_status in ('wc-refunded')
AND orders.post_status NOT in ('auto-draft','trash')
AND orders.ID IN
(SELECT DISTINCT order_items.order_id
FROM wp_woocommerce_order_items as order_items
LEFT JOIN wp_woocommerce_order_itemmeta AS orderitemmeta_product
ON orderitemmeta_product.order_item_id = order_items.order_item_id
WHERE order_item_type='line_item'
AND (orderitemmeta_product.meta_key IN ('_variation_id', '_product_id')
AND orderitemmeta_product.meta_value<>'0'
AND (orderitemmeta_product.meta_key = '_product_id')) )
Thanks.
Hello
But it doesn’t export all other fields that I need, which are attached to the main order (like the shipping country).
please, upload your settings as new ticket to https://algolplus.freshdesk.com/
use tab Tools to get them.
This code runs after SQL queries, so you won’t see it in the debug.
thanks, Alex
This code correctly exports orders which were fully/partially refunded in selected date range. Date range filter shouldn’t be empty!
add_filter( "woe_sql_get_order_ids_where", function($where,$settings) {
$from_date = WC_Order_Export_Engine::$current_job_settings["from_date"];
$to_date = WC_Order_Export_Engine::$current_job_settings["to_date"];
global $wpdb;
unset($where[1]);
unset($where[2]);
$where[] = "orders.ID IN (SELECT DISTINCT post_parent FROM {$wpdb->prefix}posts WHERE post_type in ( 'shop_order_refund') AND post_date>='{$from_date} 00:00:00' AND post_date<='{$to_date} 23:59:59')";
return $where;
},10,2);