HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/themes/fitmencook/woocommerce/content-single-product-wellness.php
<?php
/**
 * The template for displaying product content in the single-product.php template
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-single-product.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 3.6.0
 */
use function WPML\FP\Strings\remove;
defined('ABSPATH') || exit;
global $product;
/**
 * Hook: woocommerce_before_single_product.
 *
 * @hooked woocommerce_output_all_notices - 10
 */
do_action('woocommerce_before_single_product');
if (post_password_required()) {
  echo get_the_password_form(); // WPCS: XSS ok.
  return;
}

?>

<style>
     @import url('https://fonts.cdnfonts.com/css/sunfish-original');
</style>


<div class="product-type-wellness" style="display:none" data-layout="wellness"></div>


<div class="yoast_breadcrumb fmc_container">
<?php if (function_exists('yoast_breadcrumb')) {
        yoast_breadcrumb('<div class="fmc_breadcrumbs spacing_0_2">', '</div>');
      } ?>

      <?php

        $banner_field = get_field('product_banner');

        if( $banner_field ) {
            // Ako je vraćeno kao array (Image Array)
            if( is_array($banner_field) && isset($banner_field['url']) ) {
                $url = $banner_field['url'];
                $alt = isset($banner_field['alt']) ? $banner_field['alt'] : '';
            }
            // Ako je vraćeno kao attachment ID
            elseif( is_numeric($banner_field) ) {
                $url = wp_get_attachment_url( $banner_field );
                // Učitaj alt tekst iz attachment meta
                $alt = get_post_meta( $banner_field, '_wp_attachment_image_alt', true );
            }
            // Ako je vraćeno direktno kao URL string
            else {
                $url = $banner_field;
                $alt = '';
            }

            echo '<div class="product-banner">';
                echo '<img src="' . esc_url( $url ) . '" alt="' . esc_attr( $alt ) . '" style="width:100%; max-width:1220px; margin-bottom:4rem; border-radius:11px;">';
            echo '</div>';
        }
    ?>

</div>



<div class="custom-product-gallery fmc_container">
    <div class="main-image">
    <img
      id="main-product-image"
      src="<?php echo esc_url( wp_get_attachment_url( $product->get_image_id() ) ); ?>"
      alt="<?php echo esc_attr( get_the_title() ); ?>"
    >
  </div>
    <div class="thumbnail-gallery-wrapper">
      <?php
        $attachment_ids = $product->get_gallery_image_ids();
        $main_id = $product->get_image_id();
        if ( $main_id ) {
            array_unshift( $attachment_ids, $main_id );
        }
        $total_images = count( $attachment_ids );
      ?>
      
      <?php if ( $total_images > 6 ) : ?>
        <button class="thumb-nav thumb-nav-prev" aria-label="Previous">
          <svg width="14" height="8" viewBox="0 0 14 8" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M1 7L7 1L13 7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
        </button>
      <?php endif; ?>
      
      <div class="thumbnail-gallery" data-total="<?php echo esc_attr( $total_images ); ?>">
        <?php
          if ( $attachment_ids ) {
            foreach ( $attachment_ids as $attachment_id ) {
              echo '<img
                      class="thumbnail-image"
                      src="' . esc_url( wp_get_attachment_url( $attachment_id ) ) . '"
                      alt="' . esc_attr( get_the_title() ) . '"
                    >';
          }
        }
      ?>
      </div>
      
      <?php if ( $total_images > 6 ) : ?>
        <button class="thumb-nav thumb-nav-next" aria-label="Next">
          <svg width="14" height="8" viewBox="0 0 14 8" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M1 1L7 7L13 1" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
        </button>
      <?php endif; ?>
    </div>

    <div class="product-info-m">
        
        <div class="product-rating">
        <?php
          $average_rating = $product->get_average_rating();
          $review_count = $product->get_review_count();

          if ( $review_count > 0 ) {

             woocommerce_template_single_rating();
            } else {

          echo '<div class="fmc_rating_stars">';
          echo '<div class="rating-stars">';
          for ( $i = 1; $i <= 5; $i++ ) {
            echo '<span class="star">&#9734;</span>';
          }
           echo '</div>';
            echo '<span class="reviews-number">(0 reviews)</span>';
            echo '</div>';
           }
          ?>
        </div>
        <h1 class="product-title"><?php echo esc_html( get_the_title() ); ?></h1>
        <div class="product-description"><?php woocommerce_template_single_excerpt(); ?></div>
        <!-- **************** Start -->
      <?php
// Funkcija za trunciranje naziva, ako i dalje želiš skraćivati prvu stavku na npr. 45 znakova.
// (Možeš je izostaviti ako više ne trebaš skraćivanje.)
function fmc_truncate( $text, $max ) {
    if ( mb_strlen( $text ) > $max ) {
        return mb_substr( $text, 0, $max ) . '…';
    }
    return $text;
}

$terms = wp_get_post_terms( get_the_ID(), 'product_cat' );
if ( ! empty( $terms ) ) {
    $cat_id = intval( $terms[0]->term_id );

   

    $loop = new WP_Query( [
        'post_type'      => 'product',
        'posts_per_page' => -1,
        'tax_query'      => [
            [
                'taxonomy' => 'product_cat',
                'field'    => 'term_id',
                'terms'    => $cat_id,
            ]
        ],
        'orderby'   => 'title',
        'order'     => 'ASC',
    ] );

    
    }
?>

        <!-- **************** -->
        

<div class="no-discount-price-wrapper">
    <p id="total-price"><?php echo wc_price( $product->get_price()); ?></p>
    <!-- test -->
     <div class="stock-status-wrapper">
    <?php if ( $product->is_in_stock() ) : ?>
        <p class="stock in-stock">
            ✅ In stock      
        </p>
    <?php else : ?>
        <p class="stock out-of-stock">❌ Out of stock</p>
    <?php endif; ?>
</div>

    <!-- test -->
  
</div>

<div class="product-price-wrapper">
  <div class="discounted-price-wrapper" style="display: flex; align-items: center; gap: 1rem;">
    <?php
        // WooCommerce cene
        $regular_price = $product->get_regular_price();
        $sale_price    = $product->get_sale_price();
        $is_on_sale    = $product->is_on_sale();
        
        // Base price za kalkulacije - koristi sale ako postoji, inače regular
        $base_price = $product->get_price();
        $currency   = get_woocommerce_currency_symbol();
    ?>
    <?php if ( $is_on_sale && $sale_price && $regular_price ) : ?>
      <!-- Ako je na sale-u: regular precrtana levo, sale desno -->
      <p
        class="regular-price"
        style="text-decoration: line-through; color: #999; margin: 0; font-size: 3rem; font-weight: 600;"
        data-regular-price="<?php echo esc_attr( $regular_price ); ?>"
      >
        <?php echo wc_price( $regular_price ); ?>
      </p>
      <p
        class="discounted-price"
        data-base-price="<?php echo esc_attr( $sale_price ); ?>"
        data-currency="<?php echo esc_attr( $currency ); ?>"
        style="margin: 0; font-size: 3rem; font-weight: 600;"
      >
        <?php echo wc_price( $sale_price ); ?>
      </p>
    <?php else : ?>
      <!-- Ako nije na sale-u: samo regular cena -->
      <p
        class="discounted-price"
        data-base-price="<?php echo esc_attr( $base_price ); ?>"
        data-currency="<?php echo esc_attr( $currency ); ?>"
        style="margin: 0;"
      >
        <?php echo wc_price( $base_price ); ?>
      </p>
    <?php endif; ?>
  </div>
  <div class="quantity-wrapper">
    <button type="button" class="quantity-minus">-</button>
    <input class="input-number" type="number" id="quantity" value="1" min="1" step="1">
    <button type="button" class="quantity-plus">+</button>
  </div>
</div>

<form class="cart-m" method="post" enctype="multipart/form-data">
    <input type="hidden" id="calculated-price" name="calculated-price" value="<?php echo $product->get_price() * 1; ?>">
    <input type="hidden" id="quantity-value" name="quantity" value="1">
    <button class="add-to-cart-btn-m" type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt">
    <svg width="21" height="20" viewBox="0 0 21 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 2.5H4.66667L5 4.16667M6.33333 10.8333H14.6667L18 4.16667H5M6.33333 10.8333L5 4.16667M6.33333 10.8333L4.42259 12.7441C3.89762 13.269 4.26942 14.1667 5.01184 14.1667H14.6667M14.6667 14.1667C13.7462 14.1667 13 14.9129 13 15.8333C13 16.7538 13.7462 17.5 14.6667 17.5C15.5871 17.5 16.3333 16.7538 16.3333 15.8333C16.3333 14.9129 15.5871 14.1667 14.6667 14.1667ZM8 15.8333C8 16.7538 7.25381 17.5 6.33333 17.5C5.41286 17.5 4.66667 16.7538 4.66667 15.8333C4.66667 14.9129 5.41286 14.1667 6.33333 14.1667C7.25381 14.1667 8 14.9129 8 15.8333Z" stroke="#151921" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Add to cart
    </button>
</form>

    </div>
</div>





<!-- PRVA SEKCIJA -->
 <div class="main-container-wrapper product-section-m welness-product-section-m">
    
        <div class="fmc_container product_info_section">
            <!-- Leva strana -->
            <div class="product-image-wrapper-m">
                <?php 
                // Proveri da li proizvod ima POPUNJENE slike (ne samo prazan repeater)
                $has_product_images = false;
                $product_images = get_field('product_content_left_image');
                
                if ($product_images && is_array($product_images)) {
                    foreach ($product_images as $row) {
                        if (!empty($row['big_image']) || !empty($row['small_decoration_image'])) {
                            $has_product_images = true;
                            break;
                        }
                    }
                }
                
                if ($has_product_images): ?>
                    <?php while (have_rows('product_content_left_image')): the_row();
                        $big_image = get_sub_field('big_image');
                        $small_decoration_image = get_sub_field('small_decoration_image');
                    ?>
                        <?php if($big_image): ?>
                            <img class="big-image-m" src="<?php echo esc_url($big_image); ?>" alt="Product Big Image">
                        <?php endif; ?>
                
                        <?php if($small_decoration_image): ?>
                            <img class="decoration-normal-image" src="<?php echo esc_url($small_decoration_image); ?>" alt="Decoration image">
                        <?php endif; ?>   
                    <?php endwhile; ?>
                <?php elseif(have_rows('global_product_content_left_image','option')): ?>
                    <?php // Fallback na globalne slike ?>
                    <?php while (have_rows('global_product_content_left_image', 'option')): the_row();
                        $big_image = get_sub_field('big_image');
                        $small_decoration_image = get_sub_field('small_decoration_image');
                    ?>
                        <?php if($big_image): ?>
                            <img class="big-image-m" src="<?php echo esc_url($big_image); ?>" alt="Product Big Image">
                        <?php endif; ?>
                
                        <?php if($small_decoration_image): ?>
                            <img class="decoration-normal-image" src="<?php echo esc_url($small_decoration_image); ?>" alt="Decoration image">
                        <?php endif; ?>   
                    <?php endwhile; ?>
                <?php endif; ?>
            </div>

            <!-- Desna strana -->
            <div class="product-info-wrapper ">
                

                <div class="product-info-section item open">
                    <div class="product-title-wrapper">
                        <?php 
                         $product_info_title  = get_field('product_info_heading','option');
                        ?>
                        <h3 class="product-info-heading"><?php //echo esc_html($product_info_title)?> Product Description</h3>
                        <ion-icon class="product-icon-plus product-icon" name="remove-outline"></ion-icon>
                    </div>
                    <div class="hidden-box">
                        <p ><?php echo wp_kses_post($product->get_description()); ?></p>
                    </div>
                </div>

                
            </div>
        </div>
        <?php
                // 1) Query svih connection custom postova koji su povezani sa ovim proizvodom
                $connections = get_posts([
                'post_type'      => 'connection',
                'posts_per_page' => -1,
                'meta_query'     => [[
                    'key'     => 'connected_product',
                    'value'   => '"' . get_the_ID() . '"',
                    'compare' => 'LIKE',
                ]],
                ]);

                // 2) Skupi sve recepte iz repeatera 'recipes' u jedan array i upamti poslednji connection URL
                $connection_recipes_all = [];
                $connection_url        = '';
                if ( $connections ) {
                foreach ( $connections as $conn ) {
                    $connection_url = get_permalink( $conn->ID );
                    if ( $recs = get_field( 'recipes', $conn->ID ) ) {
                    foreach ( $recs as $r ) {
                        $connection_recipes_all[ $r->ID ] = $r;
                    }
                    }
                }
                }

                // 3) Ako ima više od 3 recepata, izvuci 4 nasumična
                if ( count( $connection_recipes_all ) > 3 ) {
                $keys = array_rand( $connection_recipes_all, 4 );
                $tmp  = [];
                foreach ( (array) $keys as $k ) {
                    $tmp[ $k ] = $connection_recipes_all[ $k ];
                }
                $connection_recipes_all = $tmp;
                }

                // 4) Ispiši sekciju samo ako ima bar jednog recepta
                if ( $connection_recipes_all ) : ?>
                
                <div class="how-to-use-section fmc_container item open">
                    <div class="product-title-wrapper no-cursor">
                        <?php 
                         $recipes_title= get_field('related_recipes_heading','option');
                        ?>
                        <h3 class="product-info-heading"><?php echo esc_html($recipes_title)?></h3>
                        <!-- <ion-icon class="product-icon-minus product-icon" name="remove-outline"></ion-icon> -->
                    </div>
                <div class="recipes-m "> <!--hidden-box class removed -->
                    <?php 
                    global $post;
                    foreach ( $connection_recipes_all as $connected_recipe ) :
                    $post = $connected_recipe;
                    setup_postdata( $post );
                    // tvoj template part za pojedinačni recept:
                    get_template_part( 'template-parts/recipe/recipe', 'rel' );
                    endforeach;
                    wp_reset_postdata();
                    ?>
                </div>

                    <a href="<?php echo esc_url( $connection_url ); ?>" class="view-link bg-link-m">
                    View All Recipes <span>&#8594;</span>
                <?php endif; ?></a>
                </div>
                
</div>	



<?php if (have_rows('global_product_content_scrolling_banner', 'option')): ?>
    <div class="scrolling-banner scrolling-banner-m">
        <div class="scrolling-content">
            <?php
            // Generiši osnovni set stavki
            while (have_rows('global_product_content_scrolling_banner', 'option')): the_row();
                $text = get_sub_field('global_product_content_banner_text');
                $image = get_sub_field('global_product_content_banner_image');
            ?>
                <div class="scrolling-item">
                    <?php if ($text): ?>
                        <span><?php echo esc_html($text); ?></span>
                    <?php endif; ?>
                    <?php if ($image): ?>
                        <img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr($text); ?>">
                    <?php endif; ?>
                </div>
            <?php endwhile; ?>

            <?php
            // Dupliraj sadržaj za kontinuiranu animaciju
            if (have_rows('global_product_content_scrolling_banner', 'option')):
                while (have_rows('global_product_content_scrolling_banner', 'option')): the_row();
                    $text = get_sub_field('global_product_content_banner_text');
                    $image = get_sub_field('global_product_content_banner_image');
            ?>
                <div class="scrolling-item">
                    <?php if ($text): ?>
                        <span><?php echo esc_html($text); ?></span>
                    <?php endif; ?>
                    <?php if ($image): ?>
                        <img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr($text); ?>">
                    <?php endif; ?>
                </div>
            <?php endwhile; endif; ?>
        </div>
    </div>
<?php endif; ?>



</div>


<div class="fmc_container fmc_m_spacing">

<?php


if (comments_open() || get_comments_number()) {
    comments_template();
}


?>

</div>

<?php
$related_ids = wc_get_related_products( get_the_ID(), 4 );
$related_products = array_map( 'wc_get_product', $related_ids );


if ( $related_products ) : ?>
  <section class="related products spacing_1 fmc_container">
    <?php
      $heading = apply_filters(
        'woocommerce_product_related_products_heading',
        __( 'Related products', 'woocommerce' )
      );
      if ( $heading ) {
        echo '<h2 class="fmc_title_2 title_spacing_2">' . esc_html( $heading ) . '</h2>';
      }

     
      woocommerce_product_loop_start();

      foreach ( $related_products as $related_product ) :
        
        $post_object = get_post( $related_product->get_id() );
        setup_postdata( $GLOBALS['post'] =& $post_object );

        
        get_template_part( 'template-parts/content', 'product' );
      endforeach;

      woocommerce_product_loop_end();
      ?>
      <img class="absolute-image-2" src="/wp-content/uploads/2025/01/AdobeStock_385724393-1.png" alt="Featured Section Background">
     <?php 
      wp_reset_postdata();
    ?>
    
    
</section>
    <?php endif; ?>
    <div class="fmc_container see-all-products-div">
      <a href="/product-category/spices/" class="view-link bg-link-m">
                    Explore All Products <span>&#8594;</span>
    </a>
    </div>