How to list all products from WooCommerce with total sales? This code is just for 1 product only. It\'s not work if put an array on $product.
Try this code. It'll give you output in 2 format
get_results("SELECT p.post_title as product, pm.meta_value as total_sales FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON (p.ID = pm.post_id AND pm.meta_key LIKE 'total_sales') WHERE p.post_type LIKE 'product' AND p.post_status LIKE 'publish'", 'ARRAY_A');
?>
";
echo "" . $result['product'] . " ";
echo "" . $result['total_sales'] . " ";
echo "";
}
?>
" . $result['product'] . ' - ' . $result['total_sales'] . "";
}
?>
Hope this will be helpful