How to Show Product Stock Remaining Quantity Per Order Item in Column in Admin Orders in WooCommerce

preview_player
Показать описание
In this woocommerce tutorial for beginners you will learn how to display products stock remaining quantities per order items in new custom column using custom php snippet in admin orders list / table in wordpress website. So we will show product name with edit product link with product quantity and in bracket we will show products remaining stocks quantity.

* Find Code in Top Pinned Comment Section.

#woocommerce #product #quantity #stock #myaccount #orders #order #column #products #wordpress #wordpresstutorial #webtaskwithhassan #hassangilani
Рекомендации по теме
Комментарии
Автор

Use this code:

// Add a Header
function $columns ) {
// Add new column
$columns['order_products'] = __( 'Products Stocks', 'woocommerce' );

return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'filter_manage_edit_shop_order_columns', 10, 1 );

// Populate the Column
function $column, $post_id ) {
// Compare
if ( $column == 'order_products' ) {
// Get an instance of the WC_Order object from an Order ID
$order = wc_get_order( $post_id );

// Is a WC_Order
if ( is_a( $order, 'WC_Order' ) ) {
foreach( $order->get_items() as $item ) {
// Product ID
$product_id = $item->get_variation_id() > 0 ? $item->get_variation_id() : $item->get_product_id();

// Get product
$product = wc_get_product( $product_id );

// Get stock quantity
$get_stock_quantity =

// NOT empty
if ( ! empty ( $get_stock_quantity ) ) {
$stock_output = ' (' . $get_stock_quantity . ')';
} else {
$stock_output = '';
}

// Output
echo '▪ <a href="' . admin_url( 'post.php?post=' . $item->get_product_id() . '&action=edit' ) . '">'. $item->get_name() . '</a> × ' . $item->get_quantity() . $stock_output . '<br />';
}
}
}
}
add_action(, 'action_manage_shop_order_posts_custom_column', 10, 2 );

WebTaskWithHassan