• Resolved melvisnap

    (@melvisnap)


    Hi, I’ve tried to find a way to change the default related products to show only related products based on one attribute. I found some code examples such as this:

    function custom_related_product_args ( $args ){
        global $product;
      
        $diseno= wc_get_product_terms( $product->id, 'pa_diseno', array( 'fields' => 'slugs' ) );
    
        unset( $args['post__in'] );
    
        $args['tax_query'] = array(
            array(
                'taxonomy' => 'pa_diseno',
                'field'    => 'slug',
                'term'    => $diseno,
            )
        );
    
        return $args;
    }
    add_filter('woocommerce_related_products_args', 'custom_related_product_args');

    But I can’t make it work and I don’t want to use a plugin to get this done. Any idea how to make it work?

    I’m failing miserably

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Related products only by Attribute’ is closed to new replies.