Change related products query by attribute
-
We have a WooCommerce shop for a client and we are trying to use the filter woocommerce_output_related_products_args to change the selection of related products.
The function is as follows, but it’s not working.
It only uses the category (default) for the filter. It just ignores the pa_model.Am I doing something wrong, missing something or using the wrong filter?
Hope someone can help with this.
function woocommerce_aantal_related( $args ) { global $product; $cats = wc_get_product_terms( $product->id, 'product_cat', array( 'fields' => 'slugs' ) ); $types = wc_get_product_terms( $product->id, 'pa_model', array( 'fields' => 'slugs' ) ); $args['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $cats, 'operator' => 'AND' ), array( 'taxonomy' => 'pa_model', 'field' => 'slug', 'terms' => $types, 'operator' => 'AND' ), ); $args['posts_per_page'] = 8; $args['columns'] = 4; return $args; } add_filter( 'woocommerce_output_related_products_args', 'woocommerce_aantal_related' );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Change related products query by attribute’ is closed to new replies.