WooCoomerce shipped with current product also in the related products tab.

 

I was using the product slider carousel:

default code is:

$products = wc_get_products( $args );

 

Then below iterate all the products:

<div class="swiper-container">
  <div class="swiper-wrapper">
  <?php
  //Modified below line for exclude current product

  foreach ( $products as $product ) {
  echo '<div class="swiper-slide">
      <div class="gpsc--product-image">
      <a href="' . esc_url( get_permalink( $product->get_id() ) ) . '">
      <img src="' . esc_url( wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'medium' )[0] ) . '" alt="' . esc_html( $product->get_title() ) . '">
      <h2>' . esc_html( $product->get_title() ) . '</h2>

      </a>
      <br>' . do_shortcode( '[add_to_cart id="' . $product->get_id() . '"]' ) .
      '</div>
      </div>';
      }
  ?>
  </div>
</div>

We can add a variable called $current_product, and use below code to get it:

$current_product = wc_get_product();

Then we create a empty <div> when the $current_product equals $product:

<div class="swiper-container">
  <div class="swiper-wrapper">
  <?php
  //Modified below line for exclude current product

  foreach ( $products as $product ) {
    if ($product == $current_product){
      echo '<div class="current"></div>';
    }else{
        echo '<div class="swiper-slide">
        <div class="gpsc--product-image">
        <a href="' . esc_url( get_permalink( $product->get_id() ) ) . '">
        <img src="' . esc_url( wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'medium' )[0] ) . '" alt="' . esc_html( $product->get_title() ) . '">
        <h2>' . esc_html( $product->get_title() ) . '</h2>

        </a>
        <br>' . do_shortcode( '[add_to_cart id="' . $product->get_id() . '"]' ) .
        '</div>
         </div>';
        }
    }
  ?>
  </div>
</div>