HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/school/wp-content/themes/school/single-product.php
<?php
/**
 * The Template for displaying all single products
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/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://woocommerce.com/document/template-structure/
 * @package     WooCommerce\Templates
 * @version     1.6.4
 */

if (!defined('ABSPATH')) {
	exit; // Exit if accessed directly
}

get_header('shop'); ?>

<?php
/**
 * woocommerce_before_main_content hook.
 *
 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
 * @hooked woocommerce_breadcrumb - 20
 */
// do_action( 'woocommerce_before_main_content' );
?>

<?php while (have_posts()): ?>
	<?php the_post();
	$product = wc_get_product(get_the_ID());
	$terms = get_the_terms(get_the_ID(), 'product_cat');
	$product_cat_slugs = array_column($terms, 'slug');
	$instructor = get_field('instructor');

	?>
	</div>
	<section class="">
		<div class="container">
			<div class="row py-5 text-center">
				<!-- Left/Main Content -->
				<div class="col mx-auto">
					<!-- Hero Header -->
					<div class="text-center">
						<div>
							<h1 class="display-4 fw-bold"><?php the_title(); ?></h1>
							<?php
							// Get product categories
							$terms = get_the_terms(get_the_ID(), 'product_cat');
							$category = !empty($terms) ? $terms[0] : false;

							if ($category):
								?>
								<nav aria-label="breadcrumb">
									<ol class="breadcrumb justify-content-center mt-3 mx-1">
										<li class="breadcrumb-item">
											<a href="<?php echo esc_url(home_url('/')); ?>">مدرسه نوروزگان</a>
										</li>
										<li class="breadcrumb-item">
											<a href="<?php echo esc_url(get_term_link($category)); ?>">
												<?php echo esc_html($category->name); ?>
											</a>
										</li>
										<li class="breadcrumb-item active" aria-current="page">
											<?php the_title(); ?>
										</li>
									</ol>
								</nav>
							<?php endif; ?>

						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
	<section>
		<div class="container bg-white p-5" id="course-header">
			<div class="row">
				<!-- Left/Main Content -->
				<div class="col-lg-8">
					<!-- Hero Header -->
					<div class="d-flex align-items-center mb-4">
						<div>
							<p class="lead mb-0"><?php the_excerpt(); ?></p>
						</div>
					</div>
					<?php do_action('my_custom_purchase_info_box'); ?>

					<div class="course-wrapper position-lg-relative">
						<!-- Tabbed Sections -->
						<ul class="nav nav-tabs pt-2 m-0 stick bg-white" id="courseTab" role="tablist">
							<li class="nav-item"><a class="nav-link active" data-bs-toggle="tab"
									href="#description">توضیحات</a>
							</li>
							<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#curriculum">برنامه</a></li>
							<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#reviews">نظرات</a></li>
							<!-- Add more tabs as needed -->
						</ul>
						<div class="tab-content p-4 border border-top-0" id="courseTabContent">
							<div class="tab-pane fade show active" id="description">
								<?php the_content(); ?>
							</div>
							<div class="tab-pane fade" id="curriculum">
								<?php
								global $product;
								$attributes = $product->get_attributes();
								if (!empty($attributes)) {
									echo '<ul class="list-group list-group-flush m-0">';
									foreach ($attributes as $attribute) {
										// check if it's taxonomy-based attribute (e.g. pa_module)
										if ($attribute->is_taxonomy()) {
											$values = wc_get_product_terms($product->get_id(), $attribute->get_name(), array('fields' => 'names'));
											if (!empty($values)) {
												echo '<li class="list-group-item d-flex justify-content-between align-items-center">';
												echo wc_attribute_label($attribute->get_name()) . ':';
												echo '<span class="fw-bold">' . implode(', ', $values) . '</span>';
												echo '</li>';
											}
										} else {
											// Custom attribute (not taxonomy)
											$value = $attribute->get_options();
											if (!empty($value)) {
												echo '<li class="list-group-item d-flex justify-content-between align-items-center">';
												echo esc_html(wc_attribute_label($attribute->get_name())) . ':';
												echo '<span class="fw-bold">' . esc_html(implode(', ', $value)) . '</span>';
												echo '</li>';
											}
										}
									}
									echo '</ul>';
								} else {
									echo '<p class="text-muted">هیچ ویژگی‌ای برای این محصول ثبت نشده است.</p>';
								}
								?>
							</div>

							<div class="tab-pane fade" id="reviews">
								<?php
								// Output Woo reviews/comments and form
								comments_template('/woocommerce/single-product-reviews.php');
								?>
							</div>
						</div>
					</div>
				</div>
				<!-- Right/Sidebar -->
				<div class="col-lg-4 mt-4 mt-lg-0">
					<aside class="sidebar stick">

						<!-- Product Image Card -->
						<div class="card shadow-sm border-0 mb-4">
							<div class="card-body text-center">
								<?php woocommerce_show_product_images(); ?>
							</div>
						</div>

						<!-- Instructor Info -->
						<?php
						$instructors = get_field('instructor');
						$field_obj = get_field_object('instructor');

						if ($instructors && is_array($instructors)): ?>
							<div class="card border-0 shadow-sm mb-4">
								<div class="card-header bg-light fw-bold">
									<?php echo esc_html($field_obj['label']); ?>(ها)
								</div>
								<ul class="list-group list-group-flush m-0">
									<?php foreach ($instructors as $instructor): ?>
										<li class="list-group-item d-flex align-items-center">
											<?php echo get_avatar($instructor['ID'], 48, '', '', ['class' => 'rounded-circle']); ?>
											<div class="ms-3">
												<h6 class="mb-1"><?php echo esc_html($instructor['display_name']); ?></h6>
												<small
													class="text-muted"><?php echo wp_trim_words($instructor['user_description'], 15, '…'); ?></small>
											</div>
										</li>
									<?php endforeach; ?>
								</ul>
							</div>
						<?php endif; ?>

						<!-- Product Info -->
						<div class="card border-0 shadow-sm mb-4">
							<div class="card-header bg-light fw-bold">جزئیات دوره</div>
							<ul class="list-group list-group-flush m-0 fd">
								<?php
								$field_group_keys = ['group_68cbe2d15daeb', 'group_68cbdd3cac2c3', 'group_68cbd74d059d6', 'group_68cbd33085b87', 'group_68cbdea1365ff']; // Your multiple field group keys or IDs
							
								$fields = [];
								foreach ($field_group_keys as $group_key) {
									$fields_in_group = acf_get_fields($group_key);
									if (!$fields_in_group)
										continue;

									foreach ($fields_in_group as $field) {
										$value = get_field($field['name'], get_the_ID());
										if (empty($value))
											continue;
										$fields[$field['name']] = $value;
									}
								}

								if ($fields) {
									foreach ($fields as $field_key => $field_value) {
										if ($field_key === 'instructor')
											continue;
										$field_obj = get_field_object($field_key);
										$label = $field_obj['label'] ?? ucfirst($field_key);

										// Check if field is ACF datepicker type
										if ($field_obj && $field_obj['type'] === 'date_picker' && !empty($field_value)) {
											$value_html = "<span class='persianDate' data-timestamp='{$field_value}'></span>";
										} elseif ($field_obj && $field_obj['type'] === 'date_time_picker' && !empty($field_value)) {
											$value_html = "<span class='small persianTime' data-timestamp='{$field_value}'></span>";
										} elseif (is_array($field_value)) {
											$value_html = implode(', ', array_map('esc_html', $field_value));
										} else {
											$value_html = esc_html($field_value);
										}

										echo "<li class='list-group-item d-flex justify-content-between align-items-center'>
                <span>{$label}</span>
                <strong>{$value_html}</strong>
              </li>";
									}
								}

								?>
							</ul>
						</div>

						<!-- Price & CTA -->
						<div class="card border-0 shadow-sm text-center fd">
							<div class="card-body">
								<h4 class="fw-bold mb-3 text-success">
									<?php woocommerce_template_single_price(); ?>
								</h4>
								<?php
								$product_id = get_the_ID();
								$user_id = get_current_user_id();
								if (!is_user_logged_in() || !user_purchased_product_this_user($product_id, $user_id)) {
									woocommerce_template_single_add_to_cart();
								} 
								?>

							</div>
						</div>

					</aside>
				</div>

			</div>
			<!-- Add progress bar, benefit checklist, links, etc. as needed -->
		</div>
	</section>

<?php endwhile; // end of the loop. ?>

<?php
/**
 * woocommerce_after_main_content hook.
 *
 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
 */
?>

<?php
/**
 * woocommerce_sidebar hook.
 *
 * @hooked woocommerce_get_sidebar - 10
 */
?>
<script>
	jQuery(document).ready(function ($) {
		$('.persianDate').each(function () {
			var pDate = persianDate($(this).attr('data-timestamp'))
			$(this).text(pDate);
		});
		$('.persianMonth').each(function () {
			var pDate = persianMonth($(this).attr('data-timestamp'))
			$(this).text(pDate);
		});
		$('.persianTime').each(function () {
			var pDate = persianTime($(this).attr('data-timestamp'));
			$(this).text(pDate);
		});
	});
	function persianDate(timestamp) {
		var stampDate = new Date(timestamp * 1000);
		var faDate = stampDate.toLocaleDateString('fa-IR', { year: 'numeric', month: 'long', day: 'numeric' });
		return faDate;
	}
	function persianMonth(timestamp) {
		var stampDate = new Date(timestamp * 1000);
		var faMonth = stampDate.toLocaleDateString('fa-IR', { month: 'long' });
		var faYear = stampDate.toLocaleDateString('fa-IR', { year: 'numeric' });
		var faDate = faMonth + ' ' + faYear
		return faDate;
	}
	function persianTime(timestamp) {
		var stampDate = new Date(timestamp * 1000);
		var faDate = stampDate.toLocaleDateString('fa-IR', { year: 'numeric', month: 'long', day: 'numeric' });
		var faTime = stampDate.toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit', hour12: true });
		return faDate + ' - ' + faTime;
	}

	document.addEventListener('DOMContentLoaded', function () {
		document.querySelectorAll('.nav-link[data-bs-toggle="tab"]').forEach(function (tabLink) {
			tabLink.addEventListener('click', function (e) {
				// Small delay ensures tab switches visually before scroll
				setTimeout(function () {
					window.scrollTo({
						top: 0,
						behavior: 'smooth'
					});
				}, 50);
			});
		});
	});

</script>

<?php
get_footer('shop');

/* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */