Skip to content

Instantly share code, notes, and snippets.

@romanpamula
Last active August 8, 2022 07:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanpamula/1cdafc392881b6fbf7e65a0638719318 to your computer and use it in GitHub Desktop.
Save romanpamula/1cdafc392881b6fbf7e65a0638719318 to your computer and use it in GitHub Desktop.
Adds product's stock quantity on admin order detail page
<?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
}
@justusss88
Copy link

Hi
How do I make this stock quantity appear at the end of the list and not at the beginning?

thank you in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment