Support » Plugin: CoCart - Decoupling WooCommerce Made Easy » add-item end point is throwing rest_no_route 404 error

  • Resolved nareshdevineni

    (@nareshdevineni)


    Hi, we have a Woocommerce website that is integrated with CoCart lite plugin.

    Things were working fine until yesterday. But suddenly, the Add to Cart functionality was broken.

    The following end point is giving us 404 No Route was found error.

    https://www.lehmann-sa.com/wp-json/cocart/v1/add-item

    Here is the error message to be precise:

    {"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}

    The other end points are working fine.

    For example, this end point is working as expected:

    https://www.lehmann-sa.com/wp-json/cocart/v1/get-cart

    All the plugins are up to date including CoCart and Woocommerce. We tried reverting back to an older version of CoCart, but no luck.

    Here is the Javascript Code that used to work till yesterday:

    function rest_api_cart() {
    	jQuery(document).off(
    		"click",
    		".product:not(.product-type-external) .single_add_to_cart_button:not(.add-to-cart-button-reject)"
    	);
    	jQuery(document).on(
    		"click",
    		".product:not(.product-type-external) .single_add_to_cart_button:not(.add-to-cart-button-reject)",
    		function (e) {
    			e.preventDefault();
    			var _this = jQuery(this);
    			var _product_id = _this.val();
    			var _form = _this.closest("form");
    			var _form_data = _form.serialize();
    
    			if (_product_id != "") {
    				var _data = "add-to-cart=" + _product_id + "&" + _form_data;
    			} else {
    				var _data = _form_data;
    			}
    			if (
    				_this.is(".disabled") ||
    				_this.is(".wc-variation-selection-needed")
    			) {
    				return false;
    			}
    
    			_data = "return_cart=false&" + _data;
    
    
    			jQuery("body,html").toggleClass("minicart-canvas-open");
    			jQuery(".nexio-minicart").addClass("is-adding-to-cart");
    			var atcUrl = "https://www.lehmann-sa.com/wp-json/cocart/v1/add-item";
    			jQuery.ajax({
    				type: "POST",
    				url: atcUrl,
    				data: _data,
    				dataType: "html",
    				cache: false,
    				headers: { "cache-control": "no-cache" },
    				success: function () {
    					jQuery(document.body).trigger("wc_fragment_refresh");
    					jQuery(document).on("added_to_cart", function () {
    						jQuery(".nexio-minicart").removeClass(
    							"is-adding-to-cart"
    						);
    					});
    					jQuery(".single_add_to_cart_button-clone")
    						.removeClass("loading")
    						.addClass("added");
    				},
    			});
    		}
    	);
    }

    Please let us know what you think. Any direction to fixing this problem would be helpful.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘add-item end point is throwing rest_no_route 404 error’ is closed to new replies.