Get variation product quantity in admin product list page

add_filter(‘woocommerce_admin_stock_html’, ‘admin_product_data’,10,2);
function admin_product_data($stock_html,$product) {
global $wpdb;
if( $product->is_type( ‘variable’ ) ) {
$query = “SELECT sum(meta_value)
FROM $wpdb->posts AS p, $wpdb->postmeta AS s
WHERE p.post_parent = %d
AND p.post_type = ‘product_variation’
AND p.post_status = ‘publish’
AND = s.post_id
AND s.meta_key = ‘_stock'”;

$product_qty = $wpdb->get_var($wpdb->prepare($query,$product->id));
$stock_html = ‘<mark class=”instock”>’. __(‘In stock’, ‘woocommerce’ ) . ‘</mark>’.’ (‘.$product_qty.’)’;
return $stock_html;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s