Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce: Get item info from refunds
<?php
// Get items from all refunds
$refunds = array();
$refund_items = get_posts( array(
'post_type' => 'shop_order_refund',
'posts_per_page' => -1,
'post_status' => 'any',
'fields' => 'ids'
) );
foreach ( $refund_items as $refund_id ) {
$refund = new WC_Order_Refund( $refund_id );
// All items for the order are returned in the Refund object
// but you can pull each out based on quantity
//error_log( print_r ( $refund->get_items(), 1 ) );
}
// Get all items from a specific refund
$refund_items = get_posts( array(
'post_type' => 'shop_order_refund',
'post_parent' => 513, // order ID
'post_status' => 'any',
) );
foreach ( $refund_items as $refund_id ) {
$refund = new WC_Order_Refund( $refund_id );
error_log( print_r ( $refund->get_items(), 1 ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment