How to list all products with total sales?

后端 未结 2 1558
礼貌的吻别
礼貌的吻别 2021-02-06 18:57

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.



        
2条回答
  •  太阳男子
    2021-02-06 20:03

    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 "";
        echo "";
        echo "";
    }
    ?>
    
    " . $result['product'] . "" . $result['total_sales'] . "

    " . $result['product'] . ' - ' . $result['total_sales'] . "

    "; } ?>

    Hope this will be helpful

提交回复
热议问题