【发布时间】:2016-12-05 10:54:48
【问题描述】:
使用 WooCommerce,我有这段代码可以输出产品列表报告:
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'total_sales',
'value' => 0,
'compare' => '>'
)
)
);
$output = array_reduce( get_posts( $args ), function( $result, $post ) {
return $result .= '<tr><td>' . $post->post_title . '</td><td>' . get_post_meta( $post->ID, 'total_sales', true ) . '</td></tr>';
} );
echo '<table><thead><tr><th>' . __( 'Product', 'woocommerce' ) . '</th><th>' . __( 'Units Sold', 'woocommerce' ) . '</th></tr></thead>' . $output . '</table>';
使用该代码,我想在 Wordpress 页面上列出销售额。
我的问题:如何将 SKU 添加到表中?
谢谢
【问题讨论】:
-
我已经稍微更新了我的代码……有一个语法错误……让我知道它是否适合你,谢谢……
标签: php wordpress woocommerce product sku