woocommerce related products by specific categories [closed]

I think the following procedure will help you get your job done.
When you select a product in spoons category, you should know its ‘id’ (how to find category ID).

Let’s assume for the following that Spoons ID is ’12’ and Bowls ID is ’13’.

You should make a function and pass a parameter. Here the parameter is your current related ID, like ’12’. This function would return your related products based on alter category.

function get_related_posts( $relatedID ) {
    switch ( $relatedID ) {
        case "12":
            $id = 13;
            break;
        default:
            $id = 13;
    }
    $query = new WP_Query ( array (
        'post_type' => 'product',
        'tax_query' => array(
            array(
                'taxonomy' => 'your_taxonomy_name',
                'field'    => 'id',
                'terms'    => $id,
            ),
        ),
    ) );
    if ( $query->have_posts () ) {
        while ( $query->have_posts () ) {
            $query->the_post ();
            // "Do your html..... and return it."
        }
        wp_reset_postdata ();
        return "Your Html";
    } else {
        return "Nothing Found";
    }
}

And in your template file you can call this function, e.g. in category page place this code:

echo get_related_posts( 12 );

I think this is the basics. You can find it at WP_Query Codex.
Hope it works for you. I haven’t tested it for stability.