title: Get a sidebar widget that show products of the same categories in Woocommerce
body: <p>I’m trying to set a sidebar in the single product page that show all products of the same categories as the product displayed.</p>
  
  <p>That's how I proceed:</p>
  
  <p>1) First I’ve created a sidebar called “Products_of_same_Category” to put in there a widget to show what I needed, then in <em>function.php</em> of my child theme I added the following snippet to execute php code in text widget:</p>
  
  <pre><code>// Enable PHP in widgets
  add_filter('widget_text','execute_php',100);
  function execute_php($html){
       if(strpos($html,"&lt;"."?php")!==false){
            ob_start();
            eval("?"."&gt;".$html);
            $html=ob_get_contents();
            ob_end_clean();
       }
       return $html;
  }
  </code></pre>
  
  <p>2) Then when I saw that the snippet runs ok I added that code to test it:</p>
  
  <pre><code>&lt;?php 
  $prod=get_the_term_list( $post-&gt;ID, 'product_cat');
  echo $prod; 
  ?&gt;
  </code></pre>
  
  <p>And all worked fine, it gave me the exact name of the current category of the product displayed in the single product page.</p>
  
  <p>3) So I've tried another test, deleting the previous code, to view if a shortcode translated in php should works in a widget too (writing at this time the exact category name requested, in this case "towels" - in the code below I substitute it with <code>THE-CATEGORY-I-LIKE</code>):</p>
  
  <pre><code>&lt;?php echo do_shortcode('[product_category category=“THE-CATEGORY-I-LIKE” per_page="20" columns="1" orderby="title" order="desc"]'); ?&gt;`
  </code></pre>
  
  <p>And all was again well done!</p>
  
  <p>4) Finally I mixed all in this code to show the list of products of same categories but something goes wrong:</p>
  
  <pre><code>&lt;?php $prod=get_the_term_list( $post-&gt;ID, 'product_cat', '', '', '' );
  echo do_shortcode('[product_category category="'.$prod.'" per_page="20" columns="1" orderby="title" order="desc"]'); ?&gt;
  </code></pre>
  
  <p>In last case the code doesn't display anything. I don't understand where I made mistakes, the syntax is wrong or the solving approach is illogical?</p>
  
  <p>I really appreciate any help about this.</p>