function checkCartAbandonment() { fetch('/wp-admin/admin-ajax.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'action=check_cart_items' }) .then(response => { if (!response.ok) { throw new Error('AJAX request failed: ' + response.statusText); } return response.json(); }) .then(data => { const hasItems = data && data.hasItems; // Check if data exists const hasShown = sessionStorage.getItem('cartAbandonmentShown'); if (hasItems && !window.location.pathname.includes('/cart') && !window.location.pathname.includes('/checkout') && !hasShown) { showPopup('cart-abandonment-popup'); sessionStorage.setItem('cartAbandonmentShown', 'true'); } }) .catch(error => { console.error('Error in checkCartAbandonment:', error); // Prevent the error from breaking the page }); }