2013-11-20 93 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; 
相關問題