3

使用 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 添加到表中?

谢谢

4

1 回答 1

1
于 2016-12-05T12:09:27.357 回答