diff --git a/404.php b/404.php index d79d19f..058482a 100644 --- a/404.php +++ b/404.php @@ -1,25 +1,35 @@ -// 404 Error Page -echo '
-
-

404 - صفحه مورد نظر یافت نشد

-

متأسفانه صفحه‌ای که به دنبال آن بودید یافت نشد. لطفاً چک کنید که آدرس درست باشد یا به صفحه اصلی بروید.

-
- -
- +
+
+
+
-
'; +

۴۰۴

+

صفحه مورد نظر پیدا نشد!

+

+ به نظر می‌رسد آدرس اشتباه وارد کرده‌اید یا صفحه‌ای که به دنبال آن هستید حذف شده است. +

+ +
+ -get_footer(); -?> \ No newline at end of file +name) ? $current_term->name : 'فروشگاه'; ?> -
- -
-
-

-

- خانه - - + +

+ + +
+ فروشگاه مطیب +
+
+
+

+ +

+ +

+

-
+
+ -
-
- - - - - -
- - -
- - - - - - - -
- $value ) { - if ( $key !== 'orderby' ) { - echo ''; - } - }?> - -
-
- - - -
- -
- - -
- -
- - - -
- -

محصولی یافت نشد

-

متأسفانه محصولی با این مشخصات پیدا نشد.

- - - مشاهده همه محصولات - -
- - + +
+
+ + +
+ +
-
-
-
- - - - \ No newline at end of file + +
+
+
+ + + + +
+ +
+
+ +
+
+ +
+
+ + + +
+ + get_average_rating(); + $review_count = $product->get_rating_count(); + $price = $product->get_price(); + $regular_price = $product->get_regular_price(); + $is_on_sale = $product->is_on_sale(); + $badge = ''; + if ( $is_on_sale && $regular_price ) { + $discount = round( ( 1 - ( $price / $regular_price ) ) * 100 ); + $badge = '' . $discount . '%'; + } + ?> +
+
+ + <?php the_title_attribute(); ?> + +
+ is_featured() ) : ?> + ارگانیک + + +
+
+ + +
+
+
+
+ + + () +
+

+ +

+
+ + + + +
+
+
+ +
+ + +
+ +
+ +

+ +
+
+
+
+ + -
- -
-
-

- ' . get_search_query() . '' ); } - else { _e( 'مجله سلامت مطیب', 'motayeb' ); } ?> -

-

- خانه - - مجله -

-
+ +
+
+
+

مجله سلامت مطیب

+

جدیدترین مقالات و مطالب آموزشی در زمینه سلامت، تغذیه و سبک زندگی ارگانیک

+
-
- -
+ +
+
+
+ + name : 'سلامت'; + $cat_color = 'bg-forest-50 dark:bg-forest-900/30 text-forest-500 dark:text-forest-300'; + if ( $cat_name === 'دستور پخت' || $cat_name === 'غذا' ) { + $cat_color = 'bg-honey-50 dark:bg-honey-900/30 text-honey-400'; + } elseif ( $cat_name === 'سبک زندگی' ) { + $cat_color = 'bg-emerald-50 dark:bg-emerald-900/30 text-emerald-500'; + } + $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' ); + $img_src = $image ? $image[0] : 'https://picsum.photos/seed/' . get_the_ID() . '/600/400.jpg'; + ?>
- - - - - 'w-full h-full object-cover group-hover:scale-105 transition-transform duration-500' ) ); ?> - -
- -
- +
+
+ <?php the_title_attribute(); ?> +
- - -
- -
- term_id ) ) . '" class="inline-flex items-center gap-1.5 px-3 py-1 bg-forest-50 dark:bg-forest-900/30 text-forest-500 dark:text-forest-300 rounded-full text-xs font-semibold hover:bg-forest-100 dark:hover:bg-forest-900/50 transition">'; - echo esc_html( $categories[0]->name ); - echo ''; - } - ?> +
-
+ +

هنوز مطلبی منتشر نشده است.

+ +
- -
- 2, - 'prev_text' => '', - 'next_text' => '', - ) ); - ?> -
- - - -
- -

مقاله‌ای یافت نشد

-

متأسفانه موردی با این مشخصات پیدا نشد.

- - بازگشت به خانه - -
- + +
+ 2, + 'prev_text' => '', + 'next_text' => '', + 'screen_reader_text' => ' ', + 'class' => 'flex justify-center gap-2', + ) ); ?> +
-
+ - \ No newline at end of file + response.json()) + .then(data => { + if (data.success) { + const p = data.data; + const existing = cart.find(x => x.id === p.id); + if (existing) { existing.qty++; } + else { cart.push({ ...p, qty: 1 }); } + updateCartUI(); + showToast(p.name + ' به سبد خرید اضافه شد', 'success'); + } + }) + .catch(() => { + // اگر Ajax کار نکرد، از داده‌های mock استفاده کن + const mockProduct = { + id: id, + name: 'محصول شماره ' + id, + price: 100000, + img: 'default-product' + }; + const existing = cart.find(x => x.id === mockProduct.id); + if (existing) { existing.qty++; } + else { cart.push({ ...mockProduct, qty: 1 }); } + updateCartUI(); + showToast(mockProduct.name + ' به سبد خرید اضافه شد', 'success'); + }); +} - // ========================================== - // ۱. مدیریت حالت تاریک (Dark Mode) - // ========================================== - function initDarkMode() { - // بررسی تنظیمات ذخیره شده یا تنظیمات سیستم عامل - const savedTheme = localStorage.getItem('motayeb-theme'); - if (savedTheme === 'dark') { - html.classList.add('dark'); - } +function addToCartDetail(productId) { + const qty = parseInt(document.getElementById('product-qty')?.textContent || 1); + // از طریق Ajax محصول رو واکشی کن + fetch(motayeb_ajax.ajax_url + '?action=get_product_data&id=' + productId + '&nonce=' + motayeb_ajax.nonce) + .then(response => response.json()) + .then(data => { + if (data.success) { + const p = data.data; + const existing = cart.find(x => x.id === p.id); + if (existing) { existing.qty += qty; } + else { cart.push({ ...p, qty: qty }); } + updateCartUI(); + showToast(p.name + ' به سبد خرید اضافه شد', 'success'); + } + }) + .catch(() => { + // Mock + const mockProduct = { + id: productId, + name: 'محصول شماره ' + productId, + price: 100000, + img: 'default-product' + }; + const existing = cart.find(x => x.id === mockProduct.id); + if (existing) { existing.qty += qty; } + else { cart.push({ ...mockProduct, qty: qty }); } + updateCartUI(); + showToast(mockProduct.name + ' به سبد خرید اضافه شد', 'success'); + }); +} - // اتصال رویداد به دکمه تغییر تم - const darkBtn = header ? header.querySelector('button[aria-label="حالت تاریک"]') : null; - if (darkBtn) { - darkBtn.addEventListener('click', function () { - html.classList.toggle('dark'); - const isDark = html.classList.contains('dark'); - localStorage.setItem('motayeb-theme', isDark ? 'dark' : 'light'); - }); - } - } +function removeFromCart(id) { + cart = cart.filter(x => x.id !== id); + updateCartUI(); +} - // ========================================== - // ۲. سایه هدر هنگام اسکرول - // ========================================== - function initHeaderScroll() { - if (!header) return; - window.addEventListener('scroll', function () { - if (window.scrollY > 50) { - header.classList.add('shadow-lg'); +function updateCartQty(id, delta) { + const item = cart.find(x => x.id === id); + if (!item) return; + item.qty += delta; + if (item.qty <= 0) { removeFromCart(id); return; } + updateCartUI(); +} + +function updateCartUI() { + const count = cart.reduce((s, i) => s + i.qty, 0); + const total = cart.reduce((s, i) => s + i.price * i.qty, 0); + + // Badge + ['cart-count', 'mobile-cart-count', 'cart-drawer-count'].forEach(id => { + const el = document.getElementById(id); + if (el) { + if (id === 'cart-drawer-count') { + el.textContent = count; } else { - header.classList.remove('shadow-lg'); + if (count > 0) { el.textContent = count; el.classList.remove('hidden'); } + else { el.classList.add('hidden'); } } - }, { passive: true }); - } + } + }); - // ========================================== - // ۳. مدیریت پنل جستجو - // ========================================== - function initSearchOverlay() { - const overlay = document.getElementById('search-overlay'); - if (!overlay) return; + // Drawer items + const listEl = document.getElementById('cart-items-list'); + const emptyEl = document.getElementById('cart-empty'); + const footerEl = document.getElementById('cart-drawer-footer'); + + if (!listEl) return; + + if (cart.length === 0) { + listEl.classList.add('hidden'); + if (emptyEl) emptyEl.classList.remove('hidden'); + if (footerEl) footerEl.classList.add('hidden'); + } else { + listEl.classList.remove('hidden'); + if (emptyEl) emptyEl.classList.add('hidden'); + if (footerEl) footerEl.classList.remove('hidden'); - const input = overlay.querySelector('.search-field'); - const openBtns = document.querySelectorAll('[aria-label="جستجو"]'); + const totalEl = document.getElementById('cart-drawer-total'); + if (totalEl) totalEl.textContent = formatPrice(total) + ' تومان'; - // باز کردن - openBtns.forEach(function (btn) { - btn.addEventListener('click', function () { - overlay.classList.remove('hidden'); - body.style.overflow = 'hidden'; // قفل اسکرول - setTimeout(function () { if (input) input.focus(); }, 150); - }); - }); - - // بستن با کلیک روی بک‌دراپ - overlay.addEventListener('click', function (e) { - if (e.target === overlay) { - closeSearch(); - } - }); + listEl.innerHTML = cart.map(i => ` +
+ +
+

${i.name}

+
${formatPrice(i.price)} تومان
+
+
+ + ${i.qty} + +
+ +
+
+
+ `).join(''); } - function closeSearch() { - const overlay = document.getElementById('search-overlay'); - if (overlay) { - overlay.classList.add('hidden'); - body.style.overflow = ''; // آزاد کردن اسکرول - } - } - - // ========================================== - // ۴. مدیریت منوی موبایل - // ========================================== - function initMobileMenu() { - const menu = document.getElementById('mobile-menu'); - if (!menu) return; - - // پیدا کردن دکمه همبرگرری - const openBtn = header ? header.querySelector('button[aria-label="منوی موبایل"]') : null; - - // پیدا کردن دکمه ضربدر داخل منو و بک‌دراپ - const closeBtn = menu.querySelector('button'); - const backdrop = menu.querySelector('.absolute.inset-0'); - - if (openBtn) { - openBtn.addEventListener('click', function () { - menu.classList.remove('hidden'); - body.style.overflow = 'hidden'; - }); - } - - if (closeBtn) { - closeBtn.addEventListener('click', closeMobileMenu); - } - if (backdrop) { - backdrop.addEventListener('click', closeMobileMenu); - } - } - - function closeMobileMenu() { - const menu = document.getElementById('mobile-menu'); - if (menu) { - menu.classList.add('hidden'); - body.style.overflow = ''; - } - } - - // ========================================== - // ۵. میانبرهای کیبورد - // ========================================== - function initKeyboardShortcuts() { - document.addEventListener('keydown', function (e) { - // بستن با Escape - if (e.key === 'Escape') { - closeSearch(); - closeMobileMenu(); - } - // باز کردن جستجو با Ctrl+K - if ((e.metaKey || e.ctrlKey) && e.key === 'k') { - e.preventDefault(); - const overlay = document.getElementById('search-overlay'); - if (overlay) { - overlay.classList.toggle('hidden'); - if (!overlay.classList.contains('hidden')) { - body.style.overflow = 'hidden'; - setTimeout(function () { - const input = overlay.querySelector('.search-field'); - if (input) input.focus(); - }, 150); - } else { - body.style.overflow = ''; - } - } - } - }); - } - - // ========================================== - // ۶. اسکرول نرم برای لینک‌های # - // ========================================== - function initSmoothScroll() { - document.querySelectorAll('a[href^="#"]:not([href="#"])').forEach(function (anchor) { - anchor.addEventListener('click', function (e) { - const targetId = this.getAttribute('href'); - const targetElement = document.querySelector(targetId); - - if (targetElement) { - e.preventDefault(); - closeMobileMenu(); // بستن منو اگر باز بود - - const headerHeight = header ? header.offsetHeight : 0; - const elementPosition = targetElement.getBoundingClientRect().top + window.pageYOffset; - const offsetPosition = elementPosition - headerHeight - 20; - - window.scrollTo({ - top: offsetPosition, - behavior: 'smooth' - }); - } - }); - }); - } - - // ========================================== - // ۷. انیمیشن هنگام اسکرول (Scroll Reveal) - // ========================================== - function initScrollAnimations() { - const elements = document.querySelectorAll('.animate-slide-up, .animate-fade-in'); - if (elements.length === 0) return; - - // مخفی کردن اولیه - elements.forEach(function (el) { - el.style.opacity = '0'; - el.style.transform = 'translateY(30px)'; - el.style.transition = 'opacity 0.7s cubic-bezier(0.5, 0, 0, 1), transform 0.7s cubic-bezier(0.5, 0, 0, 1)'; - }); - - const observer = new IntersectionObserver(function (entries) { - entries.forEach(function (entry) { - if (entry.isIntersecting) { - entry.target.style.opacity = '1'; - entry.target.style.transform = 'translateY(0)'; - observer.unobserve(entry.target); // توقف مشاهده پس از اجرا - } - }); - }, { - threshold: 0.1, - rootMargin: '0px 0px -40px 0px' - }); - - elements.forEach(function (el) { - observer.observe(el); - }); - } - - // ========================================== - // ۸. سیستم توست (برای استفاده در ووکامرس بعداً) - // ========================================== - window.motayebToast = function (message, type) { - type = type || 'success'; - - // حذف توست قبلی اگر وجود داشت - const existingToast = document.querySelector('.motayeb-toast-notification'); - if (existingToast) existingToast.remove(); - - var toast = document.createElement('div'); - toast.className = 'motayeb-toast-notification fixed top-24 left-1/2 -translate-x-1/2 z-[100] px-6 py-3 rounded-2xl shadow-2xl text-sm font-semibold text-white flex items-center gap-2 transition-all duration-300'; - - // تنظیم رنگ و آیکون - if (type === 'success') { - toast.style.backgroundColor = '#2D5F3F'; - toast.innerHTML = ' ' + message; - } else if (type === 'error') { - toast.style.backgroundColor = '#dc2626'; - toast.innerHTML = ' ' + message; + // Checkout + const checkoutItems = document.getElementById('checkout-items'); + if (checkoutItems) { + if (cart.length === 0) { + checkoutItems.innerHTML = '

سبد خرید خالی است

'; } else { - toast.style.backgroundColor = '#8B5A3C'; - toast.innerHTML = ' ' + message; + checkoutItems.innerHTML = cart.map(i => ` +
+ +
+
${i.name}
+
${i.qty} عدد
+
+
${formatPrice(i.price * i.qty)}
+
+ `).join(''); } + const subtotalEl = document.getElementById('checkout-subtotal'); + const totalEl = document.getElementById('checkout-total'); + if (subtotalEl) subtotalEl.textContent = formatPrice(total) + ' تومان'; + if (totalEl) totalEl.textContent = formatPrice(total) + ' تومان'; + } +} - // حالت اولیه (مخفی بالای صفحه) - toast.style.opacity = '0'; - toast.style.transform = 'translate(-50%, -20px)'; - - body.appendChild(toast); +function formatPrice(n) { + return n.toLocaleString('fa-IR'); +} - // انیمیشن ورود - requestAnimationFrame(function () { - toast.style.opacity = '1'; - toast.style.transform = 'translate(-50%, 0)'; +// ============================================ +// توابع UI +// ============================================ +function openSearch() { + const overlay = document.getElementById('search-overlay'); + if (overlay) { + overlay.classList.remove('hidden'); + setTimeout(() => { + const input = document.getElementById('search-input'); + if (input) input.focus(); + }, 100); + } +} + +function closeSearch() { + const overlay = document.getElementById('search-overlay'); + if (overlay) overlay.classList.add('hidden'); + const input = document.getElementById('search-input'); + if (input) input.value = ''; + const results = document.getElementById('search-results'); + if (results) results.innerHTML = ''; + const suggestions = document.getElementById('search-suggestions'); + if (suggestions) suggestions.classList.remove('hidden'); +} + +function openCart() { + const drawer = document.getElementById('cart-drawer'); + if (drawer) drawer.classList.remove('hidden'); +} + +function closeCart() { + const drawer = document.getElementById('cart-drawer'); + if (drawer) drawer.classList.add('hidden'); +} + +function openMobileMenu() { + const menu = document.getElementById('mobile-menu'); + if (menu) menu.classList.remove('hidden'); +} + +function closeMobileMenu() { + const menu = document.getElementById('mobile-menu'); + if (menu) menu.classList.add('hidden'); +} + +function toggleDark() { + document.documentElement.classList.toggle('dark'); +} + +function toggleLang() { + showToast('نسخه انگلیسی به زودی اضافه می‌شود', 'info'); +} + +function goToCheckout() { + closeCart(); + // هدایت به صفحه تسویه حساب ووکامرس + if (typeof motayeb_ajax !== 'undefined' && motayeb_ajax.checkout_url) { + window.location.href = motayeb_ajax.checkout_url; + } else { + // Fallback: اگر متغیر وجود نداشت، به صفحه سبد خرید برود + window.location.href = '/cart/'; + } +} + +// ============================================ +// جستجو +// ============================================ +function handleSearch(val) { + const results = document.getElementById('search-results'); + const suggestions = document.getElementById('search-suggestions'); + if (!results) return; + + if (val.length < 2) { + results.innerHTML = ''; + if (suggestions) suggestions.classList.remove('hidden'); + return; + } + if (suggestions) suggestions.classList.add('hidden'); + + // ارسال درخواست Ajax برای جستجو + fetch(motayeb_ajax.ajax_url + '?action=search_products&term=' + encodeURIComponent(val) + '&nonce=' + motayeb_ajax.nonce) + .then(response => response.json()) + .then(data => { + if (data.success && data.data.length > 0) { + results.innerHTML = data.data.map(p => ` + + `).join(''); + } else { + results.innerHTML = '

محصولی یافت نشد

'; + } + }) + .catch(() => { + // Mock results + results.innerHTML = '

خطا در جستجو. لطفاً دوباره تلاش کنید.

'; }); +} - // حذف خودکار - setTimeout(function () { - toast.style.opacity = '0'; - toast.style.transform = 'translate(-50%, -20px)'; - setTimeout(function () { toast.remove(); }, 300); - }, 3000); - }; - - - // ========================================== - // اجرای تمام توابع - // ========================================== - initDarkMode(); - initHeaderScroll(); - initSearchOverlay(); - initMobileMenu(); - initKeyboardShortcuts(); - initSmoothScroll(); - initScrollAnimations(); - - // ========================================== - // ۹. تعویض عکس در صفحه محصول - // ========================================== - window.changeProductImage = function (btn, imgUrl) { - // تغییر عکس اصلی - const mainImg = document.getElementById('main-product-image'); - if (mainImg) { - mainImg.src = imgUrl; - mainImg.setAttribute('data-large_image', imgUrl); - } - - // تغییر کلاس فعال تامبنیل‌ها - document.querySelectorAll('.gallery-thumb').forEach(function (thumb) { - thumb.classList.remove('active'); - thumb.style.borderColor = ''; - }); - btn.classList.add('active'); - }; - - // ========================================== - // ۱۰. ستاره‌های امتیازدهی سفارشی - // ========================================== - const starsContainer = document.getElementById('custom-star-rating'); - const ratingInput = document.getElementById('rating'); - if (starsContainer && ratingInput) { - const stars = starsContainer.querySelectorAll('.star'); - - stars.forEach(star => { - star.addEventListener('mouseenter', function() { - const val = this.dataset.value; - stars.forEach(s => { - s.style.color = s.dataset.value <= val ? '#D4A574' : ''; - }); - }); - - star.addEventListener('click', function() { - ratingInput.value = this.dataset.value; - stars.forEach(s => s.classList.remove('active')); - this.classList.add('active'); - // رنگ دادن به همه ستاره‌های تا اون عدد - const val = this.dataset.value; - stars.forEach(s => { - if(s.dataset.value <= val) s.classList.add('active'); - }); - }); - }); - - starsContainer.addEventListener('mouseleave', function() { - const currentVal = ratingInput.value; - stars.forEach(s => { - s.style.color = s.dataset.value <= currentVal ? '#D4A574' : ''; - }); - }); +//زوم تصویر +function changeImage(src, btn) { + const mainImg = document.getElementById('main-product-img'); + if (!mainImg) return; + + // 1. تغییر تصویر اصلی + mainImg.src = src; + + // 2. آپدیت ویژگی‌های ضروری برای زوم و پاپ‌آپ ووکامرس + mainImg.setAttribute('data-large_image', src); + mainImg.setAttribute('data-src', src); + + // 3. مهمترین بخش برای پاپ‌آپ: آپدیت لینک والد ( اطراف عکس) + // ووکامرس برای باز کردن پاپ‌آپ از روی href این لینک استفاده می‌کند + const parentLink = mainImg.closest('a'); + if (parentLink) { + parentLink.href = src; } + // 4. بروزرسانی کلاس فعال روی thumbnails + document.querySelectorAll('.gallery-thumb').forEach(t => t.classList.remove('active')); + if (btn) btn.classList.add('active'); + + // 5. بازسازی مجدد Zoom (با متد مقاوم‌تر) + if (typeof jQuery !== 'undefined' && typeof jQuery.fn.zoom !== 'undefined') { + const $mainImg = jQuery(mainImg); + // والد بلافصل عکس را هدف قرار میدهیم (معمولاً یک
یا است) + const $wrapper = $mainImg.parent(); + + // اگر والد قبلاً زوم داشته باشد، آن را نابود کن + $wrapper.trigger('zoom.destroy'); + + // زوم جدید را روی والد اعمال کن + $wrapper.zoom({ + url: src, + touch: false + }); + } +} + +function selectWeight(btn, price) { + document.querySelectorAll('.weight-btn').forEach(b => { + b.classList.remove('active', 'border-forest-500', 'dark:border-forest-300', 'bg-forest-50', 'dark:bg-forest-900/30', 'text-forest-500', 'dark:text-forest-300'); + b.classList.add('border-cream-200', 'dark:border-dark-border'); + }); + btn.classList.add('active', 'border-forest-500', 'dark:border-forest-300', 'bg-forest-50', 'dark:bg-forest-900/30', 'text-forest-500', 'dark:text-forest-300'); + btn.classList.remove('border-cream-200', 'dark:border-dark-border'); + selectedWeightPrice = price; + const priceEl = document.getElementById('product-price'); + if (priceEl) priceEl.textContent = formatPrice(price); +} + +function changeQty(delta) { + const el = document.getElementById('product-qty'); + if (!el) return; + let val = parseInt(el.textContent) + delta; + if (val < 1) val = 1; + if (val > 10) val = 10; + el.textContent = val; +} + +function switchTab(tabId, btn) { + document.querySelectorAll('.tab-content').forEach(t => t.classList.add('hidden')); + document.querySelectorAll('.tab-btn').forEach(b => { + b.classList.remove('tab-active'); + b.classList.add('text-cream-500', 'dark:text-dark-muted'); + }); + const target = document.getElementById('tab-' + tabId); + if (target) target.classList.remove('hidden'); + if (btn) { + btn.classList.add('tab-active'); + btn.classList.remove('text-cream-500', 'dark:text-dark-muted'); + } +} + +// ============================================ +// علاقه‌مندی‌ها +// ============================================ +function toggleWishlist(btn) { + const icon = btn.querySelector('iconify-icon'); + if (!icon) return; + const currentIcon = icon.getAttribute('icon'); + if (currentIcon === 'lucide:heart') { + icon.setAttribute('icon', 'lucide:heart'); + icon.style.color = '#ef4444'; + icon.style.fill = '#ef4444'; + showToast('به علاقه‌مندی‌ها اضافه شد', 'info'); + } else { + icon.style.color = ''; + icon.style.fill = ''; + showToast('از علاقه‌مندی‌ها حذف شد', 'info'); + } +} + +// ============================================ +// Toast +// ============================================ +function showToast(msg, type = 'info') { + const container = document.getElementById('toast-container'); + if (!container) return; + const colors = { success: 'bg-forest-500', info: 'bg-earth-400', error: 'bg-red-500' }; + const icons = { success: 'lucide:check-circle', info: 'lucide:info', error: 'lucide:alert-circle' }; + const toast = document.createElement('div'); + toast.className = `toast flex items-center gap-3 px-5 py-3 ${colors[type] || 'bg-earth-400'} text-white rounded-2xl shadow-xl text-sm font-medium`; + toast.innerHTML = `${msg}`; + container.appendChild(toast); + setTimeout(() => { + toast.style.opacity = '0'; + toast.style.transition = 'opacity 0.3s'; + setTimeout(() => toast.remove(), 300); + }, 3000); +} + +// ============================================ +// فرم‌ها +// ============================================ +function handleNewsletter(e) { + e.preventDefault(); + const email = document.getElementById('newsletter-email'); + if (email) { + showToast(email.value + ' با موفقیت ثبت شد!', 'success'); + email.value = ''; + } +} + +function handleContact(e) { + e.preventDefault(); + showToast('پیام شما با موفقیت ارسال شد. به زودی پاسخ می‌دهیم.', 'success'); + e.target.reset(); +} + +// ============================================ +// رویدادهای صفحه کلید +// ============================================ +document.addEventListener('keydown', function(e) { + if (e.key === 'Escape') { + closeSearch(); + closeCart(); + closeMobileMenu(); + } + if ((e.metaKey || e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + openSearch(); + } +}); + +// ============================================ +// تغییر هدر هنگام اسکرول +// ============================================ +let lastScroll = 0; +window.addEventListener('scroll', function() { + const header = document.getElementById('header'); + if (!header) return; + const scroll = window.scrollY; + if (scroll > 100) { + header.classList.add('shadow-lg'); + } else { + header.classList.remove('shadow-lg'); + } + lastScroll = scroll; +}); + +// ============================================ +// مقداردهی اولیه +// ============================================ +document.addEventListener('DOMContentLoaded', function() { + // تنظیم شمارنده سبد خرید از کوکی (اختیاری) + updateCartUI(); + + // اگر در صفحه محصول هستیم، کلاس‌های گالری رو تنظیم کن + const mainImg = document.getElementById('main-product-img'); + if (mainImg) { + // اولین تصویر گالری رو به‌عنوان active تنظیم کن + const firstThumb = document.querySelector('.gallery-thumb'); + if (firstThumb) firstThumb.classList.add('active'); + } +}); + +// نمونه کد جایگزین برای تولید ستاره +function renderStars(rating) { + // ⚠️ اینجا را تغییر دهید: به جای 'ستاره_کانتینر_آیدی'، شناسه واقعی تگ div در HTML خود را بگذارید + const container = document.getElementById('star-rating'); // یا هر شناسه‌ای که در HTML دارید + if (!container) return; // اگر ظرف پیدا نشد، کد متوقف شود تا خطا ندهد + + container.innerHTML = ''; // پاک کردن ظرف + + for (let i = 1; i <= 5; i++) { + let star = document.createElement('i'); // ساختن تگ آیکون + if (i <= rating) { + star.className = 'fa-solid fa-star text-warning'; // ستاره پر طلایی + } else { + star.className = 'fa-regular fa-star text-secondary'; // ستاره خالی خاکستری + } + // اضافه کردن کلیک برای ثبت نظر + star.onclick = function() { setRating(i); }; + + container.appendChild(star); + } +} + +document.addEventListener('DOMContentLoaded', function() { + // فرض کنید امتیاز فعلی محصول 0 است یا از دیتابیس می‌خوانید + let initialRating = 0; // یا عددی که از سمت سرور به جاوا اسکریپت پاس داده می‌شود + + // اگر در صفحه جزئیات نظر هستیم، تابع ستاره‌ها را صدا بزنیم + const starContainer = document.getElementById('star-rating'); // همان شناسه بالا + if (starContainer) { + renderStars(initialRating); + } }); \ No newline at end of file diff --git a/assets/js/woocommerce.js b/assets/js/woocommerce.js new file mode 100644 index 0000000..e69de29 diff --git a/comments.php b/comments.php index 7de320f..55f2f23 100644 --- a/comments.php +++ b/comments.php @@ -6,4 +6,4 @@ wp_list_comments(array( 'avatar_size' => 48, 'max_depth' => 3, )); -?> \ No newline at end of file + diff --git a/footer.php b/footer.php index f9b4713..06ba22c 100644 --- a/footer.php +++ b/footer.php @@ -1,95 +1,120 @@ - - -
+ + + + + + + +
+ \ No newline at end of file diff --git a/front-page.php b/front-page.php index 49ca91e..4ca6f70 100644 --- a/front-page.php +++ b/front-page.php @@ -1,319 +1,489 @@ -
- - -
-
-
-
-
- - محصولات ۱۰۰٪ ارگانیک و طبیعی -
- -

- - طعم - واقعی -
- طبیعت - - طعم - واقعی -
- طبیعت - -

- -

- -

- - - - - 0): ?> -
- $stat): ?> -
-
-
-
-
'; ?> - -
- + +
+
+
+
+
+ + محصولات ۱۰۰٪ ارگانیک و طبیعی
- - -
- -
- <?php echo esc_attr($hero_img['alt'] ?? ''); ?> -
-
- -
-
- -

لطفاً از تنظیمات صفحه، تصویر هیرو را آپلود کنید.

-
-
- -
-

پلاگین ACF فعال نیست.

-
- - - - -
-
-
-
- -
-
- - - 0): ?> -
-
-
- CATEGORIES -

دسته‌بندی محصولات

-

از عسل‌های کوهستان تا دمنوش‌های گیاهی، بهترین‌های طبیعت را کشف کنید

-
-
- 'honey', 'forest'=>'forest', 'red'=>'red', 'emerald'=>'emerald', 'amber'=>'amber'); - $c = $color_map[$cat['color']] ?? 'forest'; - ?> - -
- -
-

- -
- -
-
-
- - - - 0): ?> -
-
-
-
- BESTSELLERS -

پرفروش‌ترین‌ها

-
- -
-
- -
- - <?php echo esc_attr($product->get_name()); ?> - is_on_sale() ): ?> -
تخفیف
- -
+

+ طعم + واقعی +
+ طبیعت +

+

+ از عسل کوهستان تا ارده سنتی، هر محصول مطیب سفری به دل طبیعت ایران است. با طعم‌های اصیل و سلامت واقعی آشنا شوید. +

+
+ + مشاهده محصولات + -
- get_name(); ?> -
- get_price_html(); ?> -
+ + داستان مطیب + + +
+ +
+
+
+۲۵۰
+
محصول ارگانیک
+
+
+
+
+۱۵K
+
مشتری راضی
+
+
+
+
۳۱
+
استان تحت پوشش
-
-
-
- - - - -
-
-
-
- -
- <?php echo esc_attr($story_img['alt'] ?? ''); ?> -
- + +
+
+ محصولات ارگانیک مطیب +
-
- OUR STORY -

-

- - 0): ?> -
- -
-
- -
-
-
-
-
-
- -
- - - 0): ?> -
- -
- - -
- -
- -
-
-
-
- - - - 0): ?> -
-
-
-
- TESTIMONIALS -

نظرات مشتریان ما

-
-
- -
-
★★★★★
-

«»

+ +
-
+
+ +
-
-
+
گواهی ارگانیک
+
تأیید شده توسط سازمان غذا
- -
-
-
- - - -
-
-
- -
-

-

-
- - -
-
-
- - -
-
-
-
-
-
ارسال سریع
به سراسر ایران
-
-
-
-
ضمانت اصالت
۱۰۰٪ اصل و طبیعی
-
-
-
-
پرداخت امن
درگاه‌های معتبر
-
-
-
-
بازگشت آسان
۷ روز ضمانت
+ +
+
+
+
م
+
ع
+
ز
+
+
+
★★★★★
+
+۴.۸ از ۵۰۰۰ نظر
+
+
-
+
+ +
+ + + +
+
-
+ +
+
+
+ CATEGORIES +

دسته‌بندی محصولات

+

از عسل‌های کوهستان تا دمنوش‌های گیاهی، بهترین‌های طبیعت را کشف کنید

+
+
+ 'product_cat', + 'hide_empty' => false, + 'parent' => 0, + 'number' => 5, + 'orderby' => 'name', + 'order' => 'ASC', + ) ); - \ No newline at end of file + $icons = array( 'lucide:hexagon', 'lucide:droplets', 'lucide:flask-round', 'lucide:cup-soda', 'lucide:nut' ); + $colors = array( 'bg-honey-50 dark:bg-honey-900/20 text-honey-400', 'bg-forest-50 dark:bg-forest-900/20 text-forest-500 dark:text-forest-300', 'bg-red-50 dark:bg-red-900/20 text-red-400', 'bg-emerald-50 dark:bg-emerald-900/20 text-emerald-500', 'bg-amber-50 dark:bg-amber-900/20 text-amber-500' ); + $i = 0; + + if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) { + foreach ( $categories as $category ) { + $count = $category->count; + $icon = isset( $icons[ $i ] ) ? $icons[ $i ] : 'lucide:tag'; + $color = isset( $colors[ $i ] ) ? $colors[ $i ] : 'bg-cream-50 dark:bg-dark-bg text-cream-500'; + ?> + +
+ +
+

name ); ?>

+ محصول +
+ هنوز دسته‌بندی‌ای ایجاد نشده است.

'; + } + ?> +
+
+
+ + +
+
+
+
+ BESTSELLERS +

پرفروش‌ترین‌ها

+
+ +
+
+ 'product', + 'posts_per_page' => 4, + 'meta_key' => 'total_sales', + 'orderby' => 'meta_value_num', + 'order' => 'DESC', + 'meta_query' => array( + array( + 'key' => '_stock_status', + 'value' => 'instock', + 'compare' => '=', + ), + ), + ) ); + + if ( $bestsellers->have_posts() ) : + while ( $bestsellers->have_posts() ) : + $bestsellers->the_post(); + $product = wc_get_product( get_the_ID() ); + if ( ! $product ) { + continue; + } + $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' ); + $img_src = $image ? $image[0] : 'https://picsum.photos/seed/' . get_the_ID() . '/400/400.jpg'; + $rating = $product->get_average_rating(); + $review_count = $product->get_rating_count(); + $price = $product->get_price(); + $regular_price = $product->get_regular_price(); + $is_on_sale = $product->is_on_sale(); + $badge = ''; + if ( $is_on_sale && $regular_price ) { + $discount = round( ( 1 - ( $price / $regular_price ) ) * 100 ); + $badge = '' . $discount . '%'; + } + ?> + + ' . esc_html__( 'هنوز محصولی وجود ندارد.', 'motayeb' ) . '

'; + endif; + ?> +
+
+
+ + +
+
+
+
+
+ مزرعه ارگانیک +
+
+
+۱۲
+
سال تجربه
+
در تولید محصولات ارگانیک
+
+
+
+ OUR STORY +

داستان مطیب،
از طبیعت تا سفره شما

+

+ مطیب از سال ۱۳۹۰ با هدف عرضه محصولات ارگانیک و طبیعی ایرانی آغاز به کار کرد. ما مستقیماً از زنبورداران، کشاورزان و تولیدکنندگان سنتی سراسر ایران خرید می‌کنیم و با حفظ کیفیت اولیه، آنها را به سفره خانواده‌های ایرانی می‌رسانیم. +

+
+
+
+ +
+
+
کشت ارگانیک
+
بدون سم و کود شیمیایی
+
+
+
+
+ +
+
+
تضمین اصالت
+
آزمایشگاهی و مستند
+
+
+
+
+ +
+
+
بسته‌بندی سبز
+
دوست‌دار محیط زیست
+
+
+
+
+ +
+
+
تأمین محلی
+
حمایت از کشاورز ایرانی
+
+
+
+ +
+
+ + گواهی ارگانیک ایران +
+
+ + استاندارد ملی بهداشت +
+
+ + نماد اعتماد الکترونیکی +
+
+
+
+
+
+ + +
+
+
+
+ TESTIMONIALS +

نظرات مشتریان ما

+
+
+ 'زهرا کریمی', + 'city' => 'تهران', + 'text' => 'از وقتی عسل مطیب استفاده می‌کنیم، دیگه هیچ عسلی برامون قابل قبول نیست. طعم واقعی عسل رو با مطیب شناختیم.', + 'stars' => 5, + ), + array( + 'name' => 'حسین نوری', + 'city' => 'اصفهان', + 'text' => 'ارده و شیره‌های مطیب کیفیت استثنایی دارن. بسته‌بندی هم بسیار تمیز و بهداشتیه. برای صبحانه عالیه.', + 'stars' => 5, + ), + array( + 'name' => 'فاطمه موسوی', + 'city' => 'شیراز', + 'text' => 'دمنوش‌های گیاهی مطیب واقعاً طبیعین. برخلاف خیلی از برندها، عطر و طعم واقعی گیاهان رو حس می‌کنی.', + 'stars' => 5, + ), + ); + foreach ( $testimonials as $t ) : + $initial = mb_substr( $t['name'], 0, 1 ); + ?> +
+
+ + ★ + +
+

«»

+
+
+
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+ BLOG +

مجله سلامت مطیب

+
+ +
+
+ 'post', + 'posts_per_page' => 3, + 'orderby' => 'date', + 'order' => 'DESC', + ) ); + + if ( $blog_posts->have_posts() ) : + while ( $blog_posts->have_posts() ) : + $blog_posts->the_post(); + $categories = get_the_category(); + $cat_name = ! empty( $categories ) ? $categories[0]->name : 'سلامت'; + $cat_color = 'bg-forest-50 dark:bg-forest-900/30 text-forest-500 dark:text-forest-300'; + if ( $cat_name === 'دستور پخت' || $cat_name === 'غذا' ) { + $cat_color = 'bg-honey-50 dark:bg-honey-900/30 text-honey-400'; + } elseif ( $cat_name === 'سبک زندگی' ) { + $cat_color = 'bg-emerald-50 dark:bg-emerald-900/30 text-emerald-500'; + } + $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' ); + $img_src = $image ? $image[0] : 'https://picsum.photos/seed/' . get_the_ID() . '/600/400.jpg'; + ?> +
+
+ <?php the_title_attribute(); ?> +
+
+
+ + +
+

+ +

+

+
+
+ هنوز مطلبی منتشر نشده است.

'; + endif; + ?> +
+
+
+ + +
+
+
+ +
+

از تخفیف‌ها باخبر شوید

+

با عضویت در خبرنامه، از جدیدترین محصولات و تخفیف‌های ویژه مطلع شوید.

+
+ + +
+
+
+ + +
+
+
+
+
+ +
+
ارسال سریع
+
به سراسر ایران
+
+
+
+ +
+
ضمانت اصالت
+
۱۰۰٪ اصل و طبیعی
+
+
+
+ +
+
پرداخت امن
+
درگاه‌های معتبر
+
+
+
+ +
+
بازگشت آسان
+
۷ روز ضمانت
+
+
+
+
+ + 60, + 'width' => 200, + 'flex-height' => true, + 'flex-width' => true, + 'header-text' => array( 'site-title', 'site-description' ), + ) ); add_theme_support( 'woocommerce' ); add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - - register_nav_menus( array( - 'primary' => __( 'منوی اصلی', 'motayeb' ), - 'footer' => __( 'منوی فوتر', 'motayeb' ), + add_theme_support( 'html5', array( + 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', ) ); + add_theme_support( 'align-wide' ); + add_theme_support( 'responsive-embeds' ); + register_nav_menus( array( + 'primary' => esc_html__( 'منوی اصلی', 'motayeb' ), + 'footer' => esc_html__( 'منوی فوتر', 'motayeb' ), + ) ); + add_image_size( 'motayeb-product-grid', 400, 400, true ); + add_image_size( 'motayeb-product-single', 600, 600, true ); } -add_action( 'after_setup_theme', 'motayeb_setup' ); +add_action( 'after_setup_theme', 'motayeb_theme_setup' ); -// ۲. لود فایل‌های CSS و JS +// ============================================================ +// ۲. بارگذاری فایل‌های استایل و اسکریپت (Enqueue) +// ============================================================ function motayeb_scripts() { - wp_enqueue_style( 'vazirmatn', 'https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800;900&display=swap', array(), null ); - wp_enqueue_script( 'tailwind-cdn', 'https://cdn.tailwindcss.com', array(), null, false ); - - wp_add_inline_script( 'tailwind-cdn', " - tailwind.config = { - darkMode: 'class', - theme: { - extend: { - colors: { - forest: { 50:'#e8f5ec', 100:'#c6e6cf', 200:'#9ed0ae', 300:'#6fb88a', 400:'#4a9a6b', 500:'#2D5F3F', 600:'#254d34', 700:'#1c3b28', 800:'#13291c', 900:'#0a1710' }, - cream: { 50:'#FDFBF7', 100:'#F5F0E8', 200:'#EBE3D5', 300:'#DDD2BF', 400:'#C4B49A', 500:'#A99478' }, - honey: { 50:'#FDF5ED', 100:'#F9E6D0', 200:'#F2CC9E', 300:'#E8AC6A', 400:'#D4A574', 500:'#C08B52', 600:'#A07040', 700:'#7D5630', 800:'#5A3D20', 900:'#3A2612' }, - earth: { 50:'#F5EDE7', 100:'#E8D5C7', 200:'#D4B5A0', 300:'#BF9276', 400:'#8B5A3C', 500:'#734A30', 600:'#5C3B25', 700:'#452C1B', 800:'#2E1D12', 900:'#170E09' }, - dark: { bg:'#1A1D23', card:'#22262E', border:'#2E333D', text:'#E8E6E3', muted:'#9CA3AF' } - }, - fontFamily: { vazir: ['Vazirmatn', 'sans-serif'], inter: ['Inter', 'sans-serif'] } - } - } - } - " ); - - wp_enqueue_style( 'motayeb-main', get_template_directory_uri() . '/assets/css/main.css', array(), '1.0.0' ); - wp_enqueue_script( 'iconify', 'https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js', array(), null, true ); - wp_enqueue_script( 'motayeb-main', get_template_directory_uri() . '/assets/js/main.js', array(), '1.0.0', true ); + wp_enqueue_style( 'motayeb-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) ); + if ( class_exists( 'WooCommerce' ) ) { + wp_enqueue_style( 'motayeb-woocommerce', get_theme_file_uri( '/assets/css/woocommerce.css' ), array( 'motayeb-style' ), wp_get_theme()->get( 'Version' ) ); + } + wp_enqueue_style( 'motayeb-responsive', get_theme_file_uri( '/assets/css/responsive.css' ), array( 'motayeb-style' ), wp_get_theme()->get( 'Version' ) ); + wp_enqueue_script( 'motayeb-main', get_theme_file_uri( '/assets/js/main.js' ), array( 'jquery' ), wp_get_theme()->get( 'Version' ), true ); + if ( class_exists( 'WooCommerce' ) ) { + wp_enqueue_script( 'motayeb-woocommerce', get_theme_file_uri( '/assets/js/woocommerce.js' ), array( 'jquery', 'motayeb-main' ), wp_get_theme()->get( 'Version' ), true ); + } + wp_enqueue_script( 'motayeb-darkmode', get_theme_file_uri( '/assets/js/darkmode.js' ), array( 'jquery' ), wp_get_theme()->get( 'Version' ), true ); + wp_localize_script( 'motayeb-main', 'motayeb_ajax', array( + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'motayeb_nonce' ), + 'checkout_url' => wc_get_checkout_url(), + 'cart_url' => wc_get_cart_url(), + ) ); + if ( is_product() ) { wp_enqueue_script( 'wc-single-product' ); } + if ( is_cart() ) { wp_enqueue_script( 'wc-cart' ); } + if ( is_checkout() ) { wp_enqueue_script( 'wc-checkout' ); } } add_action( 'wp_enqueue_scripts', 'motayeb_scripts' ); -// ۳. حذف استایل پیش‌فرض ووکامرس -add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' ); - -// ۴. بازنویسی تگ‌های Wraper ووکامرس -function motayeb_woo_wrapper_start() { - echo '
'; +// ============================================================ +// ۳. ثبت ناحیه‌های ویجت (Widget Areas) +// ============================================================ +function motayeb_widgets_init() { + register_sidebar( array( + 'name' => esc_html__( 'سایدبار اصلی', 'motayeb' ), + 'id' => 'sidebar-main', + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '

', + 'after_title' => '

', + ) ); + if ( class_exists( 'WooCommerce' ) ) { + register_sidebar( array( + 'name' => esc_html__( 'سایدبار فروشگاه', 'motayeb' ), + 'id' => 'sidebar-shop', + 'before_widget' => '
', + 'after_widget' => '
', + 'before_title' => '

', + 'after_title' => '

', + ) ); + } + for ( $i = 1; $i <= 4; $i++ ) { + register_sidebar( array( + 'name' => esc_html__( 'فوتر - ستون ' . $i, 'motayeb' ), + 'id' => 'footer-' . $i, + 'before_widget' => '', + 'before_title' => '', + ) ); + } } -function motayeb_woo_wrapper_end() { - echo '
'; -} -remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); -remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); -add_action( 'woocommerce_before_main_content', 'motayeb_woo_wrapper_start', 10 ); -add_action( 'woocommerce_after_main_content', 'motayeb_woo_wrapper_end', 10 ); +add_action( 'widgets_init', 'motayeb_widgets_init' ); -// ۵. تنظیمات فروشگاه +// ============================================================ +// ۴. توابع کمکی ووکامرس +// ============================================================ add_filter( 'loop_shop_columns', function() { return 4; } ); add_filter( 'loop_shop_per_page', function() { return 12; } ); - -// ۶. اضافه کردن کلاس nav-link به منو -add_filter('nav_menu_link_attributes', 'motayeb_add_nav_link_class', 10, 3); -function motayeb_add_nav_link_class($atts, $item, $args) { - if ($args->theme_location === 'primary') { - $atts['class'] = isset($atts['class']) ? $atts['class'] . ' nav-link' : 'nav-link'; +function motayeb_body_classes( $classes ) { + if ( class_exists( 'WooCommerce' ) ) { + if ( is_product() ) { $classes[] = 'motayeb-product-page'; } + if ( is_shop() ) { $classes[] = 'motayeb-shop-page'; } } - return $atts; + if ( isset( $_COOKIE['motayeb_darkmode'] ) && 'on' === $_COOKIE['motayeb_darkmode'] ) { + $classes[] = 'dark-mode'; + } + return $classes; +} +add_filter( 'body_class', 'motayeb_body_classes' ); + +// ============================================================ +// ۵. کلاس‌های Walker برای منو +// ============================================================ +class Motayeb_Desktop_Walker extends Walker_Nav_Menu { + public function start_lvl( &$output, $depth = 0, $args = array() ) { + $output .= '