【问题标题】:WooCommerce - Sort products by top earnerWooCommerce - 按最高收入者对产品进行排序
【发布时间】:2015-05-20 09:37:44
【问题描述】:

我想列出过去 30 天内最赚钱的前 4 种产品。有一些插件可以显示最受欢迎的商品,但它们是按销售数量而不是收入来排序的。我一直在尝试使用插件中的代码:

$args = array(
    'post_type'             => 'product',
    'post_status'           => 'publish',
    'ignore_sticky_posts'   => 1,
    'posts_per_page'        => $per_page,
    'meta_key'              => 'total_sales',
    'orderby'               => 'meta_value_num',
    'meta_query'            => array(
        array(
            'key'       => '_visibility',
            'value'     => array( 'catalog', 'visible' ),
            'compare'   => 'IN'
        )
    )
);

因为我真的不知道自己在做什么,所以我试图从 WooCommerce 的仪表板中插入代码(替换 orderby 行),希望它能起作用:

'data' => array(
    '_product_id' => array(
        'type'            => 'order_item_meta',
        'order_item_type' => 'line_item',
        'function'        => '',
        'name'            => 'product_id'
    ),
    '_line_total' => array(
        'type'            => 'order_item_meta',
        'order_item_type' => 'line_item',
        'function'        => 'SUM',
        'name'            => 'order_item_total'
    )
),
'order_by'     => 'order_item_total DESC',
'group_by'     => 'product_id',

它向我展示了一些产品,但不是最高收入者。非常感谢任何帮助!

提前致谢。

使用 WP 4.1.5

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    使用 API:

    1. http://docs.woothemes.com/document/woocommerce-rest-api/
    2. http://woothemes.github.io/woocommerce-rest-api-docs/

    那样是数据库发生了变化,你总是会得到相同的数据。

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 2020-10-16
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多