<?php
defined( 'ABSPATH' ) || exit;
global $product;

$title       = get_the_title();
$description = get_the_content();
$sku         = $product->get_sku();

$attributes = $product->get_attributes();
?>

<div class="single-product">

  <div class="single-product__top">
    <div class="single-product__gallery">
      <div class="single-product__thumbnails">
      </div>
      <div class="single-product__images">
      </div>

      <div class="product-info-card">
        <header class="product-info-card__header">
          <h2><strong><?php echo esc_html( $title ); ?></strong></h2>
          <p><?php echo wp_kses_post( wpautop( $description ) ); ?></p>
        </header>

        <section class="product-info-card__details">
          <h3>Informacje o produkcie</h3>
          <table class="product-info-table">
            <tbody>
              <?php if ( $sku ) : ?>
              <tr>
                <td>SKU</td>
                <td><?php echo esc_html( $sku ); ?></td>
              </tr>
              <?php endif; ?>
              <?php
              foreach ( $attributes as $attribute ) :

                if ( ! $attribute->get_visible() ) {
                  continue;
                }

                $label = wc_attribute_label( $attribute->get_name() );

                if ( $attribute->is_taxonomy() ) {
                  $terms = wp_get_post_terms( $product->get_id(), $attribute->get_name(), array( 'fields' => 'names' ) );
                  $value = implode( ', ', $terms );
                } else {
                  $value = implode( ', ', $attribute->get_options() );
                }
              ?>
              <tr>
                <td><?php echo esc_html( $label ); ?></td>
                <td><?php echo esc_html( $value ); ?></td>
              </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
      </section>
    </div>
    </div>

    <div class="single-product__calculator">
      <?php do_action('woocommerce_single_product_summary'); ?>
    </div>
</div>

<section class="bestseller">
    <p class="hero__heading bestseller__heading">
        PODOBNE PRODUKTY
    </p>

    <?php echo do_shortcode( '[related_products_slider limit="4"]' ); ?>
</section>