title: Add related products to shortcode in Elementor
body: <p>I have an <strong>updated woocommerce related products function</strong> in my <code>function.php</code> file. I'd like to <strong>add it to an Elementor <code>shortcode</code></strong> so I can have <strong>multiple related products sections</strong> on the product page template.</p>
  <p>Can anyone advise how to make this work within an <strong>Elementor shortcode</strong>?</p>
  <p><strong>Current <code>functions.php</code> Code</strong></p>
  <pre><code>    add_filter( 'woocommerce_related_products', 'related_products_by_attribute', 10, 3 );
  function related_products_by_attribute( $related_posts, $product_id, $args ) {
      $taxonomy   = 'pa_brand'; // HERE define the targeted product attribute taxonomy
  
      $term_slugs = wp_get_post_terms( $product_id, $taxonomy, ['fields' =&gt; 'slugs'] ); // Get terms for the product
  
      if ( empty($term_slugs) )
          return $related_posts;
  
      $posts_ids = get_posts( array(
          'post_type'            =&gt; 'product',
          'ignore_sticky_posts'  =&gt; 1,
          'posts_per_page'       =&gt; 4,
          'post__not_in'         =&gt; array( $product_id ),
          'tax_query'            =&gt; array( array(
              'taxonomy' =&gt; $taxonomy,
              'field'    =&gt; 'slug',
              'terms'    =&gt; $term_slugs,
          ) ),
          'fields'  =&gt; 'ids',
          'orderby' =&gt; 'rand',
      ) );
  
      return count($posts_ids) &gt; 0 ? $posts_ids : $related_posts;
  }
  add_shortcode( 'my_elementor_php_output', 'related_products_by_attribute');
  </code></pre>