【问题标题】:How to get best selling products by period in WooCommerce如何在 WooCommerce 中按时期获得畅销产品
【发布时间】:2015-03-17 10:29:14
【问题描述】:

我想展示过去 30 天内 WooCommerce 中最畅销的产品。只是为了展示总体上最畅销的商品,提供的代码没有问题。

代码缺少的是您在特定时间段内获得销售的部分。 meta_query 应该是做到这一点的关键,但我不确定如何。任何帮助表示赞赏!

<?php
$args = array(
    'post_type' => 'product',
    'posts_per_page' => 4,
    'meta_key' => 'total_sales',
    'orderby' => 'meta_value_num',
);

$loop = new WP_Query( $args );

if ( $loop->have_posts() ) {
    while ( $loop->have_posts() ) : $loop->the_post();
        woocommerce_get_template_part( 'content', 'product' );
    endwhile;
} else {
    echo __( 'No products found' );
}
wp_reset_postdata();

【问题讨论】:

    标签: php woocommerce wordpress


    【解决方案1】:

    您可以将此短代码用于 Woo Commerce 中的畅销产品。 [best_sales_products] 在页面编辑中。

    还可以在你想要的地方添加 php 文件 do_shortcode('[best_sales_products per_page="12"]');

    【讨论】:

    • 感谢您的回答,但在这里我们仍然缺少购买产品的时间/期限,例如过去 30 天或过去 7 天。
    • 我们正在寻找显示产品与时间段的解决方案。例如畅销产品基于过去 30 天或 7 天而不是所有时间的销售额
    【解决方案2】:

    只需像下面这样更改您的代码

    $args = array(
            'post_type' => 'product',
            'posts_per_page' => 4,
            'meta_key' => 'total_sales',
            'orderby'   => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' )
    );
    

    希望它的工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多