Получите список возвращенных товаров (и общую сумму возврата) из последнего заказа в woocommerce
Я хотел бы указать любые предметы, возвращенные из предыдущего заказа, при оформлении заказа. Я также хотел бы получить общую сумму возмещенных товаров и показать ее.
Пока я могу получить все товары из последнего заказа, но не знаю, как проверить каждый, чтобы узнать, был ли он возвращен.
function last_order_refunds(){
// For logged in users only
if ( is_user_logged_in() ) :
$user_id = get_current_user_id(); // The current user ID
// Get the WC_Customer instance Object for the current user
$customer = new WC_Customer( $user_id );
// Get the last WC_Order Object instance from current customer
$last_order = $customer->get_last_order();
$order_id = $last_order->get_id(); // Get the order id
$order_data = $last_order->get_data(); // Get the order unprotected data in an array
$order_status = $last_order->get_status(); // Get the order status
foreach ( $last_order->get_items() as $item ) : ;
//Need to somehow check if item was refunded!!
echo $item->get_name(); ?><br /><?php
endforeach;
endif;
}
add_action( 'woocommerce_checkout_order_review', 'last_order_refunds', 10 );