Last active
February 21, 2017 18:56
-
-
Save justinshreve/570e7086ae0e4d29dc39 to your computer and use it in GitHub Desktop.
WooCommerce: Get item info from refunds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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