Отобразить у пользователя в архиве товаров количество каждого купленного товара

Как в архиве товаров отобразить в карточке количество купленного товара?

Пробовал так

function custom_quantity_field_archive() {
    $customer_orders = get_posts(array(
        'numberposts' => -1,
        'meta_key'    => '_customer_user',
        'meta_value'  => $current_user->ID,
        'post_type'   => wc_get_order_types(),
        'post_status' => array_keys(wc_get_is_paid_statuses()),
        ));
    foreach ($customer_orders as $customer_order) {
        $order = wc_get_order($customer_order->ID);
        $items = $order->get_items();
        foreach ($order->get_items() as $item_id => $item) {
            $product_id = $item->get_product_id();
            global $product;
            $qty = $item->get_quantity();
            if ($refunded_qty) {
                $qty_display = '<del>' . esc_html($qty) . '</del> <ins>' . esc_html($qty - ( $refunded_qty * -1 )) . '</ins>';
            } else {
                $qty_display = esc_html($qty);
            } 
            
        } echo 'Available: ' . $qty_display . ' ';
    } 
}
add_action( 'woocommerce_after_shop_loop_item', 'custom_quantity_field_archive', 9 );

но у каждой карточки выводится количество каждого купленного товара, а не только его одного.


Ответы (0 шт):