WooCommerce提供documentation有关如何更改产品页面上显示的相关产品数量的信息。有没有办法改变 他们的关系?目前它们似乎是按类别相关的。有没有办法根据单个属性显示相关产品?
以下过滤器:
<?php
/**
* WooCommerce Extra Feature
* --------------------------
*
* Change number of related products on product page
* Set your own value for 'posts_per_page'
*
*/
function woo_related_products_limit() {
global $product;
$args = array(
'post_type' => 'product',
'no_found_rows' => 1,
'posts_per_page' => 6,
'ignore_sticky_posts' => 1,
'orderby' => $orderby,
'post__in' => $related,
'post__not_in' => array($product->id)
);
return $args;
}
add_filter( 'woocommerce_related_products_args', 'woo_related_products_limit' );
答案 0 :(得分:1)
您应该可以通过wp_query中的分类功能来完成... link
您要定位的属性是'woocommerce_attributes',未经过测试,但这应该有效:
$args = array(
'post_type' => 'product',
'no_found_rows' => 1,
'posts_per_page' => 6,
'ignore_sticky_posts' => 1,
'orderby' => $orderby,
'post__in' => $related,
'post__not_in' => array($product->id),
'woocommerce_attributes' => 'attribute_slug',
);
return $args;