{"id":223952,"date":"2026-02-03T12:53:51","date_gmt":"2026-02-03T09:23:51","guid":{"rendered":"https:\/\/hamtaetebar.com\/stage\/hamta-cart\/"},"modified":"2026-02-03T12:53:51","modified_gmt":"2026-02-03T09:23:51","slug":"hamta-cart","status":"publish","type":"page","link":"https:\/\/hamtaetebar.com\/stage\/hamta-cart\/","title":{"rendered":"\u0633\u0628\u062f \u062e\u0631\u06cc\u062f"},"content":{"rendered":"\n<div class=\"hamta-cart\" id=\"hamta-cart\">\n    <h2 class=\"hamta-cart-title\">\u0633\u0628\u062f \u062e\u0631\u06cc\u062f<\/h2>\n\n            <div class=\"hamta-cart-empty\">\n            <i class=\"fa-light fa-cart-shopping\"><\/i>\n            <p>\u0633\u0628\u062f \u062e\u0631\u06cc\u062f \u0634\u0645\u0627 \u062e\u0627\u0644\u06cc \u0627\u0633\u062a<\/p>\n            <a href=\"https:\/\/hamtaetebar.com\/stage\/shop\/\" class=\"hamta-btn hamta-btn-primary\">\n                \u0645\u0634\u0627\u0647\u062f\u0647 \u0645\u062d\u0635\u0648\u0644\u0627\u062a\n            <\/a>\n        <\/div>\n    <\/div>\n\n<script>\ndocument.addEventListener('DOMContentLoaded', function() {\n    const cart = document.getElementById('hamta-cart');\n    if (!cart) return;\n\n    \/\/ \u062a\u063a\u06cc\u06cc\u0631 \u062a\u0639\u062f\u0627\u062f\n    cart.querySelectorAll('.hamta-qty-btn').forEach(btn => {\n        btn.addEventListener('click', function() {\n            const row = this.closest('.hamta-cart-item');\n            const input = row.querySelector('.hamta-qty-input');\n            const itemId = row.dataset.itemId;\n            let qty = parseInt(input.value) || 1;\n\n            if (this.dataset.action === 'increase') {\n                qty++;\n                input.value = qty;\n                updateCartItem(itemId, qty);\n            } else if (this.dataset.action === 'decrease') {\n                qty--;\n                if (qty <= 0) {\n                    \/\/ \u062d\u0630\u0641 \u0622\u06cc\u062a\u0645 \u0648\u0642\u062a\u06cc \u062a\u0639\u062f\u0627\u062f \u0628\u0647 \u0635\u0641\u0631 \u0645\u06cc\u200c\u0631\u0633\u062f\n                    if (confirm('\u0622\u06cc\u0627 \u0627\u0632 \u062d\u0630\u0641 \u0627\u06cc\u0646 \u0645\u062d\u0635\u0648\u0644 \u0645\u0637\u0645\u0626\u0646 \u0647\u0633\u062a\u06cc\u062f\u061f')) {\n                        removeCartItem(itemId, row);\n                    }\n                } else {\n                    input.value = qty;\n                    updateCartItem(itemId, qty);\n                }\n            }\n        });\n    });\n\n    \/\/ \u062a\u063a\u06cc\u06cc\u0631 \u0645\u0633\u062a\u0642\u06cc\u0645 input\n    cart.querySelectorAll('.hamta-qty-input').forEach(input => {\n        input.addEventListener('change', function() {\n            const row = this.closest('.hamta-cart-item');\n            const itemId = row.dataset.itemId;\n            let qty = parseInt(this.value) || 0;\n\n            if (qty <= 0) {\n                \/\/ \u062d\u0630\u0641 \u0622\u06cc\u062a\u0645 \u0648\u0642\u062a\u06cc \u062a\u0639\u062f\u0627\u062f \u0628\u0647 \u0635\u0641\u0631 \u0645\u06cc\u200c\u0631\u0633\u062f\n                if (confirm('\u0622\u06cc\u0627 \u0627\u0632 \u062d\u0630\u0641 \u0627\u06cc\u0646 \u0645\u062d\u0635\u0648\u0644 \u0645\u0637\u0645\u0626\u0646 \u0647\u0633\u062a\u06cc\u062f\u061f')) {\n                    removeCartItem(itemId, row);\n                } else {\n                    this.value = 1;\n                }\n            } else {\n                this.value = qty;\n                updateCartItem(itemId, qty);\n            }\n        });\n    });\n\n    \/\/ \u062d\u0630\u0641 \u0622\u06cc\u062a\u0645\n    cart.querySelectorAll('.hamta-remove-item').forEach(btn => {\n        btn.addEventListener('click', function() {\n            if (!confirm('\u0622\u06cc\u0627 \u0627\u0632 \u062d\u0630\u0641 \u0627\u06cc\u0646 \u0645\u062d\u0635\u0648\u0644 \u0645\u0637\u0645\u0626\u0646 \u0647\u0633\u062a\u06cc\u062f\u061f')) return;\n\n            const row = this.closest('.hamta-cart-item');\n            const itemId = row.dataset.itemId;\n            removeCartItem(itemId, row);\n        });\n    });\n\n    \/\/ \u062e\u0627\u0644\u06cc \u06a9\u0631\u062f\u0646 \u0633\u0628\u062f\n    const clearBtn = document.getElementById('clear-cart');\n    if (clearBtn) {\n        clearBtn.addEventListener('click', function() {\n            if (!confirm('\u0622\u06cc\u0627 \u0627\u0632 \u062e\u0627\u0644\u06cc \u06a9\u0631\u062f\u0646 \u0633\u0628\u062f \u062e\u0631\u06cc\u062f \u0645\u0637\u0645\u0626\u0646 \u0647\u0633\u062a\u06cc\u062f\u061f')) return;\n            clearCart();\n        });\n    }\n\n    function updateCartItem(itemId, quantity) {\n        fetch(HamtaShop.ajaxUrl, {\n            method: 'POST',\n            headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n            body: new URLSearchParams({\n                action: 'hamta_shop',\n                nonce: HamtaShop.nonce,\n                module: 'cart',\n                action_name: 'update',\n                item_id: itemId,\n                quantity: quantity\n            })\n        })\n        .then(r => r.json())\n        .then(data => {\n            if (data.success) {\n                \/\/ Sync quantity in both views\n                cart.querySelectorAll('.hamta-cart-item[data-item-id=\"' + itemId + '\"]').forEach(el => {\n                    el.querySelector('.hamta-qty-input').value = quantity;\n                    if (data.data.item_total) {\n                        el.querySelector('.line-total').textContent = data.data.item_total;\n                    }\n                });\n                updateTotals(data.data.totals);\n            } else {\n                alert(data.data.message || '\u062e\u0637\u0627');\n            }\n        });\n    }\n\n    function removeCartItem(itemId, row) {\n        fetch(HamtaShop.ajaxUrl, {\n            method: 'POST',\n            headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n            body: new URLSearchParams({\n                action: 'hamta_shop',\n                nonce: HamtaShop.nonce,\n                module: 'cart',\n                action_name: 'remove',\n                item_id: itemId\n            })\n        })\n        .then(r => r.json())\n        .then(data => {\n            if (data.success) {\n                \/\/ Remove from both desktop and mobile views\n                cart.querySelectorAll('.hamta-cart-item[data-item-id=\"' + itemId + '\"]').forEach(el => el.remove());\n                updateTotals(data.data.totals);\n                if (data.data.cart_count === 0) {\n                    location.reload();\n                }\n            } else {\n                alert(data.data.message || '\u062e\u0637\u0627');\n            }\n        });\n    }\n\n    function clearCart() {\n        fetch(HamtaShop.ajaxUrl, {\n            method: 'POST',\n            headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n            body: new URLSearchParams({\n                action: 'hamta_shop',\n                nonce: HamtaShop.nonce,\n                module: 'cart',\n                action_name: 'clear'\n            })\n        })\n        .then(r => r.json())\n        .then(data => {\n            if (data.success) {\n                location.reload();\n            }\n        });\n    }\n\n    function updateTotals(totals) {\n        document.getElementById('cart-subtotal').textContent = totals.subtotal_formatted;\n        document.getElementById('cart-total').textContent = totals.total_formatted;\n\n        const dRow = document.getElementById('cart-discount-row');\n        const dVal = document.getElementById('cart-discount');\n        const dLabel = document.getElementById('cart-discount-label');\n        if (dRow && dVal) {\n            const damount = parseFloat(totals.discount || 0);\n            if (damount > 0) {\n                if (dLabel) {\n                    dLabel.textContent = (totals.discount_label || '\u062a\u062e\u0641\u06cc\u0641') + ':';\n                }\n                dVal.textContent = '-' + (totals.discount_formatted || '');\n                dRow.style.display = 'flex';\n            } else {\n                dRow.style.display = 'none';\n            }\n        }\n    }\n\n    \/\/ \u06a9\u0648\u067e\u0646 \u0633\u0628\u062f\n    const applyCouponBtn = document.getElementById('cart-apply-coupon');\n    if (applyCouponBtn) {\n        applyCouponBtn.addEventListener('click', function() {\n            const code = (document.getElementById('cart-coupon-code')?.value || '').trim();\n            const box = document.getElementById('cart-coupon-result');\n            this.disabled = true;\n            const oldText = this.textContent;\n            this.textContent = '...';\n\n            fetch(HamtaShop.ajaxUrl, {\n                method: 'POST',\n                headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n                body: new URLSearchParams({\n                    action: 'hamta_shop',\n                    nonce: HamtaShop.nonce,\n                    module: 'cart',\n                    action_name: 'set-coupon',\n                    coupon: code\n                })\n            })\n            .then(r => r.json())\n            .then(data => {\n                this.disabled = false;\n                this.textContent = oldText;\n                if (!box) return;\n\n                if (data.success) {\n                    box.style.display = 'block';\n                    box.style.color = '#16a34a';\n                    box.textContent = data.data?.message || '\u062b\u0628\u062a \u0634\u062f';\n                    if (data.data?.totals) {\n                        updateTotals(data.data.totals);\n                    }\n                } else {\n                    box.style.display = 'block';\n                    box.style.color = '#dc2626';\n                    box.textContent = data.data?.message || '\u062e\u0637\u0627';\n                }\n            })\n            .catch(() => {\n                this.disabled = false;\n                this.textContent = oldText;\n                if (!box) return;\n                box.style.display = 'block';\n                box.style.color = '#dc2626';\n                box.textContent = '\u062e\u0637\u0627 \u062f\u0631 \u0627\u0631\u062a\u0628\u0627\u0637 \u0628\u0627 \u0633\u0631\u0648\u0631';\n            });\n        });\n    }\n});\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":743,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-223952","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/pages\/223952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/users\/743"}],"replies":[{"embeddable":true,"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/comments?post=223952"}],"version-history":[{"count":0,"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/pages\/223952\/revisions"}],"wp:attachment":[{"href":"https:\/\/hamtaetebar.com\/stage\/wp-json\/wp\/v2\/media?parent=223952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}