Skip to content

Instantly share code, notes, and snippets.

@justinshreve
Last active February 21, 2017 18:56
Show Gist options
  • Save justinshreve/570e7086ae0e4d29dc39 to your computer and use it in GitHub Desktop.
Save justinshreve/570e7086ae0e4d29dc39 to your computer and use it in GitHub Desktop.
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