Features Request: Total Number in Store
-
@niyht I wanted to see if you will be able to add the total number of all products within the woocommerce store next to the sellable for your next release. This worked on my end. Thank you as always.
$total_stock = (int) $wpdb->get_var(
“SELECT SUM(CAST(pm.meta_value AS SIGNED))
FROM {$wpdb->postmeta} pm
INNER JOIN {$wpdb->postmeta} ms
ON pm.post_id = ms.post_id
INNER JOIN {$wpdb->posts} p
ON pm.post_id = p.ID
WHERE pm.meta_key = ‘_stock’
AND ms.meta_key = ‘_manage_stock’
AND ms.meta_value = ‘yes’
AND p.post_status = ‘publish’
AND p.post_type IN (‘product’, ‘product_variation’)
AND pm.meta_value REGEXP ‘^-?[0-9]+$'”
);
You must be logged in to reply to this topic.