HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/themes/fitmencook/js/custom-add-to-cart.js
$(document).ready(function($) {
    console.log('Document is ready');

    // Uklonite prethodne click event hendler-e pre nego što dodate novi
    $('.ingredient-add-to-cart').off('click');

    $('.ingredient-add-to-cart').on('click', function(event) {
        event.preventDefault();
        
        var productId = $(this).data('product-id');
        var quantity = 1; // Ovdje smo hard kodirali kvantitet na 1

        console.log('Product ID:', productId); // Provera Product ID-a
        console.log('Quantity:', quantity); // Provera Quantity

        var $this = $(this); // Zadržite referencu na trenutni element
        
        // Flag to prevent multiple submissions
        if ($this.data('clicked')) {
            return;
        }
        
        $this.data('clicked', true);

        $.ajax({
            type: 'POST',
            url: wc_add_to_cart_params.ajax_url,
            data: {
                action: 'woocommerce_add_to_cart',
                product_id: productId,
                quantity: quantity,
            },
            cache: false, 
    success: function(response) {
        console.log('Response:', response); // Provera odgovora
        if (response.error && response.product_url) {
            window.location = response.product_url;
        } else {
                    // Promenite tekst dugmeta na "Added to Cart"
                    $this.html('<span>Added to Cart</span>');

                    // Dodajte klasu za prikazivanje "Added to Cart"
                    $this.removeClass('ingredient-add-to-cart').addClass('ingredient-add-to-cart-view-cart');

                    // Alternativno, možete promeniti URL dugmeta na korpu
                    $this.attr('href', wc_add_to_cart_params.cart_url);
                }
            },
        });
    });
});