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.
<?php
$product = "13";
$units_sold = get_post_meta( $product, 'total_sales', true );
echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
?>
I want on output, format will be like this:
[PRODUCT_NAME] - [TOTAL_SALES]
Anyone know how to do this? Thank you. :)
Try this code. It'll give you output in 2 format
Hope this will be helpful
For that you can use standard get_posts() function with custom field parameters. The example below will take all posts with sales greater than zero in a descending order, if you want to get all products remove the meta query part from the arguments array. The result is formatted in a HTML table.