【发布时间】:2016-09-11 12:23:37
【问题描述】:
Woocommerce 相关产品模板位于:
/wp-content/plugins/woocommerce/templates/single-product/related.php
但它目前按随机排序。
我想通过 'total_sales' + 'sales_count' 订购(这些是 2 个元键保存整数值,'sales_count' 是一个额外的自定义场地)。
这里是查询:
$args = apply_filters( 'woocommerce_related_products_args', array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => 4,
'orderby' => 'total_sales',
'order' => 'DESC',
'post__in' => $related
) );
$products = new WP_Query( $args );
上述查询排序产品购买 total_sales 但我需要使用 total_sales 和 sales_count 的总和对其进行排序?
有没有办法做到这一点?
谢谢
【问题讨论】:
-
对不起,我添加了更多信息,它只需要按两个自定义字段的总和排序,其他参数正常
-
当客户下订单时,wocommerce 的total_sales 值增量也有一个自定义字段,我添加的sales_count 自定义字段也包含一些整数,sales_count 的用法是我们将其用于显示在产品上页 sales_count+total_sales 。因此产品之前没有任何实际销售额,该产品使用 sales_count 字段显示一些销售额
-
$units_sold = get_post_meta($product->id, 'total_sales', true ); $soldty= get_post_meta($product->id, 'sales_count', true ); echo '销售额:'.($units_sold+$soldty);
-
所以我们需要订购相关产品$units_sold+$soldty,我们目前使用total_sales进行排序
-
不只是使用 WordPress 自定义字段
标签: php wordpress woocommerce custom-fields product