    

           

// Your existing code might end before this.Change "Add to Cart" to "Buy Now"

add_filter('woocommerce_product_single_add_to_cart_text', 'custom_buy_now_button_text');
function custom_buy_now_button_text() {
    return 'Buy Now';
}

// Redirect to Checkout after adding to cart
add_filter('woocommerce_add_to_cart_redirect', 'redirect_to_checkout_page');
function redirect_to_checkout_page() {
    return wc_get_checkout_url();
}

// Style the Buy Now button with theme color and hover effect
add_action('wp_head', 'custom_buy_now_button_style');
function custom_buy_now_button_style() {
    ?>
    <style>
        .single-product .single_add_to_cart_button {
            background-color: #7e22ce; /* Your theme purple */
            color: #fff !important;
            border: none;
            border-radius: 8px;
            padding: 12px 28px;
            font-size: 16px;
            font-weight: 600;
            text-transform: uppercase;
            transition: all 0.3s ease-in-out;
            box-shadow: 0 4px 12px rgba(126, 34, 206, 0.3);
        }
        .single-product .single_add_to_cart_button:hover {
            background-color: #6b21a8; /* Slightly darker purple */
            transform: scale(1.04);
            box-shadow: 0 6px 18px rgba(126, 34, 206, 0.5);
        }
    </style>
    <?php>
}

// ------------------------------------------
//here estimated logic section
// ------------------------------------------
add_action('woocommerce_single_product_summary', 'custom_estimated_delivery_ui', 25);
function custom_estimated_delivery_ui() {
    ?>
    <style>
        .delivery-box {
            display: flex;
            align-items: center;
            gap: 12px;
            margin: 20px 0;
            max-width: 500px;
        }
        #pincode-input {
            padding: 12px 16px;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            outline: none;
            font-size: 15px;
            flex: 1;
            height: 48px;
            box-sizing: border-box;
            transition: all 0.3s ease;
            box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        }
        #pincode-input:focus {
            border-color: #a93bc8;
            box-shadow: 0 0 0 3px rgba(169,59,200,0.1);
        }
        #pincode-input::placeholder {
            color: #999;
        }
        #check-button {
            padding: 0 20px;
            background-color: #a93bc8;
            background: linear-gradient(to right, #a93bc8, #a93bc8);
            color: #fff;
            border: none;
            border-radius: 8px;
            font-size: 15px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            height: 48px;
            box-sizing: border-box;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        #check-button:hover {
            opacity: 0.9;
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.15);
        }
        #delivery-result {
            margin-top: 12px;
            font-size: 15px;
            color: #444;
            padding: 12px 16px;
            background: #f8f9fa;
            border-radius: 8px;
            max-width: 500px;
            line-height: 1.5;
        }
        .delivery-date {
            font-weight: 700;
            color: #2c3e50;
        }
    </style>

    <div class="delivery-box">
        <input type="text" id="pincode-input" placeholder="Enter your 6-digit pincode" maxlength="6">
        <button id="check-button">Check</button>
    </div>
    <div id="delivery-result"></div>

    <script>
        document.getElementById("check-button").addEventListener("click", function () {
            const input = document.getElementById("pincode-input");
            const pin = input.value.trim();
            const resultDiv = document.getElementById("delivery-result");

            if (pin.length !== 6 || isNaN(pin)) {
                resultDiv.innerHTML = '<span style="color:#e74c3c;">Please enter a valid 6-digit pincode</span>';
                input.focus();
                return;
            }

            resultDiv.innerHTML = '<span style="color:#a93bc8;">Checking delivery time...</span>';

            setTimeout(() => {
                const deliveryDate = new Date();
                deliveryDate.setDate(deliveryDate.getDate() + 4); // Add 4 days

                const dayOfWeek = deliveryDate.toLocaleDateString('en-US', { weekday: 'long' });
                const formatted = `${deliveryDate.getDate()}${getOrdinalSuffix(deliveryDate.getDate())} ${deliveryDate.toLocaleDateString('en-US', { month: 'short' })}, <span class="delivery-date">${dayOfWeek}</span>`;

                resultDiv.innerHTML = `Estimated delivery: <span class="delivery-date">${formatted}</span>`;
            }, 1000);
        });

        // Helper function to add ordinal suffix (st, nd, rd, th)
        function getOrdinalSuffix(day) {
            const j = day % 10,
                  k = day % 100;
            if (j === 1 && k !== 11) {
                return "st";
            }
            if (j === 2 && k !== 12) {
                return "nd";
            }
            if (j === 3 && k !== 13) {
                return "rd";
            }
            return "th";
        }

        // Add input validation to allow only numbers
        document.getElementById("pincode-input").addEventListener("input", function(e) {
            this.value = this.value.replace(/[^0-9]/g, '');
        });
    </script>
    <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://gemsprime.in/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://gemsprime.in/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-posts-product-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-taxonomies-post_tag-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-taxonomies-product_cat-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-taxonomies-product_tag-1.xml</loc></sitemap><sitemap><loc>https://gemsprime.in/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
