add_filter( 'elementor/query/get_query_args', function( $query_args ) {
    if ( ! is_product() ) {
        return $query_args;
    }

    global $post;
    $product_id = $post->ID;

    $categories = wp_get_post_terms( $product_id, 'product_cat', array( 'fields' => 'ids' ) );
    $tags = wp_get_post_terms( $product_id, 'product_tag', array( 'fields' => 'ids' ) );

    $query_args['post_type'] = 'product';
    $query_args['posts_per_page'] = 3;
    $query_args['post__not_in'] = array( $product_id );
    $query_args['orderby'] = 'rand';
    $query_args['tax_query'] = array(
        'relation' => 'OR',
        array(
            'taxonomy' => 'product_cat',
            'field'    => 'term_id',
            'terms'    => $categories,
            'operator' => 'IN',
        ),
        array(
            'taxonomy' => 'product_tag',
            'field'    => 'term_id',
            'terms'    => $tags,
            'operator' => 'IN',
        ),
    );

    return $query_args;
} );