2013-11-20 61 views
0

WooCommerce提供documentation关于如何更改产品页面上显示的相关产品的数量。有没有办法改变他们如何与相关?看来他们目前正在按类别进行关联。有没有基于单一属性显示相关产品的方法?如何按属性显示相关产品 - WooCommerce

筛选下方:

<?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'); 

回答

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; 
相关问题