The code is correct. It displays product type records of 12 per page, sorting them by the total_sales meta-field. While there are no sales, for all products this field is 0.
The value of the total_sales meta-field can be total_sales in a loop after wc_get_template_parts , for example:
echo get_post_meta(get_the_ID(), 'total_sales')[0];
To display products that have more than the specified number of sales (in the example> 0), you can use meta_query . Two loop options below.
echo '<h2>Π‘Π°ΠΌΡΠ΅ ΠΏΡΠΎΠ΄Π°Π²Π°Π΅ΠΌΡΠ΅ ΡΠΈΠΊΠ»ΠΎΠΌ woocommerce</h2>'; $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 12, 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num', ); $wc_query = new WP_Query($args); if ($wc_query->have_posts()) { while ($wc_query->have_posts()) { $wc_query->the_post(); woocommerce_product_loop_start(); wc_get_template_part( 'content', 'product' ); echo 'ΠΠΎΠ»-Π²ΠΎ ΠΏΡΠΎΠ΄Π°ΠΆ: ' . get_post_meta(get_the_ID(), 'total_sales')[0]; woocommerce_product_loop_end(); } } wp_reset_postdata(); echo '<h2>Π‘Π°ΠΌΡΠ΅ ΠΏΡΠΎΠ΄Π°Π²Π°Π΅ΠΌΡΠ΅ ΡΠΈΠΊΠ»ΠΎΠΌ woocommerce Ρ ΠΎΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΠ΅ΠΌ</h2>'; $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 12, 'orderby' => 'meta_value_num', 'meta_query' => array( array( // Simple products type 'key' => 'total_sales', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ), ), ); $wc_query = new WP_Query($args); if ($wc_query->have_posts()) { while ($wc_query->have_posts()) { $wc_query->the_post(); woocommerce_product_loop_start(); wc_get_template_part( 'content', 'product' ); echo 'ΠΠΎΠ»-Π²ΠΎ ΠΏΡΠΎΠ΄Π°ΠΆ: ' . get_post_meta(get_the_ID(), 'total_sales')[0]; woocommerce_product_loop_end(); } } wp_reset_postdata();
The test result is here .