Blog /

WooCommerce: How to show in-stock quantity in the order detail

Would you like to check remaining in-stock quantity when working with orders? This snippet could help.

Last time I was answering my client’s email about whether it’s possible to show the remaining in-stock quantity of product. And, yes, it’s possible to do so. If you need to display in-stock quantity on the order detail page in your admin area, you can use the following snippet (all credit to Roman Pamula):

deail produkt a stav na sklade


<?php
/**
* Adds product's stock quantity on admin order detail page in WooCommerce
*
* Snippet updated on 18/9/2021 for compatibility with PHP 8
*
* @since 3.0.0
* @see https://pamula.sk/woocommerce-ako-zobrazit-pocet-produktov-na-sklade-v-detaile-objednavky/
*
* Please REMOVE the opening <?php tag before placing into functions.php
* Prosim ODSTRANTE otvaraciu <?php znacku pred umiestnenim do functions.php
*/
add_action('woocommerce_admin_order_item_headers', 'add_stock_status_header_on_order_item_view');
function add_stock_status_header_on_order_item_view()
{ ?>
<th class="quantity sortable" data-sort="string-ins"><?php
_e('Stock Qty', 'woocommerce'); ?></th><?php
}
add_action('woocommerce_admin_order_item_values', 'add_stock_status_value_on_order_item_view');
function add_stock_status_value_on_order_item_view($_product)
{ ?>
<td class="quantity" width="1%">
<div class="view"><?php
if (is_callable(array($_product, 'get_manage_stock')) &&
method_exists($_product, 'get_manage_stock')) {
echo $_product->get_stock_quantity();
} ?>
</div>
</td><?php
}

view raw

functions.php

hosted with ❤ by GitHub