title: Exclude the current product from WooCommerce custom Related Products output
body: <p>The aim is to display 4 products on the product page however remove the current product from the filter. At present I am pulling through products with related brands and categories, however this is also pulling through the current product to the related products...</p>
  
  <p>Current related.php file for Woocommerce contains the following: </p>
  
  <pre><code>if ( ! $related = $product-&gt;get_related( $posts_per_page ) ) {
      return;
  }
  $brands_array = array(0);
  $cats_array = array(0);
  $cur_product_id = $product-&gt;id; 
  
  // get categories
  $terms = wp_get_post_terms( $product-&gt;id, 'product_brand' );
  $category_terms =  wp_get_post_terms( $product-&gt;id, 'product_cat' );
  // select only the category which doesn't have any children
  foreach ( $terms as $term ) {
      $brands_array[] = $term-&gt;term_id;
  }
  foreach ( $category_terms as $category_term ) {
      $cats_array[] = $category_term-&gt;term_id;
  }
  
  $final_array = array_merge($brands_array, $cats_array);
  
  $filtered_array = array_filter($final_array, "test_odd");
  
  function test_odd($var)
  {
      return($var &amp; 1);
  }
  
  var_dump($final_array);
  
  $args = apply_filters( 'woocommerce_related_products_args', array(
      'post_type' =&gt; 'product',
      'ignore_sticky_posts' =&gt; 1,
      'no_found_rows' =&gt; 1,
      'posts_per_page' =&gt; 4,
      'columns' =&gt; 4,
      'orderby' =&gt; $orderby,
      'tax_query' =&gt; array(
          array(
              'taxonomy' =&gt; 'product_brand',
              'field' =&gt; 'id',
              'terms' =&gt; $final_array
          ),
      )
  ));
  
  $products                    = new WP_Query( $args );
  $woocommerce_loop['name']    = 'related';
  $woocommerce_loop['columns'] = apply_filters( 'woocommerce_related_products_columns', $columns );
  
  if ( $products-&gt;have_posts() ) : ?&gt;
  
      &lt;div class="related products"&gt;
  
          &lt;h2&gt;&lt;?php _e( 'Related Products', 'woocommerce' ); ?&gt;&lt;/h2&gt;
          &lt;?php echo $filtered_array ?&gt;
          &lt;?php woocommerce_product_loop_start();
  
               while ( $products-&gt;have_posts() ) : $products-&gt;the_post();
  
                      wc_get_template_part( 'content', 'product' ); ?&gt;
  
              &lt;?php endwhile; // end of the loop. ?&gt;
  
          &lt;?php woocommerce_product_loop_end(); ?&gt;
  
      &lt;/div&gt;
  
  &lt;?php endif;
  
  wp_reset_postdata();
  </code></pre>
  
  <p>How do I go about filtering the current product from the array of products that are shown on the product page? </p>
  
  <p>Thanks</p>