【发布时间】:2021-07-30 23:01:06
【问题描述】:
我想根据自定义分类显示相关产品。有人知道有没有办法根据自定义分类强制显示相关产品。
【问题讨论】:
标签: wordpress woocommerce custom-taxonomy related-products
我想根据自定义分类显示相关产品。有人知道有没有办法根据自定义分类强制显示相关产品。
【问题讨论】:
标签: wordpress woocommerce custom-taxonomy related-products
add_filter( 'woocommerce_output_related_products_args', 'prfx_change_related_products_count' );
function prfx_change_related_products_count( $args ) {
// Current post as global
global $post;
$terms = get_the_terms( $post->ID, 'your_custom_taxonomy' );
// Empty array
$ids = array();
foreach ( $terms as $term ) {
array_push($ids, $term->term_id);
}
$args['tax_query'] = array(
array(
'taxonomy' => 'your_custom_taxonomy',
'terms' => $ids,
'field' => 'term_id',
'include_children' => true,
'operator' => 'IN'
)
);
return $args;
}
【讨论】: