2

I've got a wordpress website running with Woocommerce and WPML plugin for multilingual. On the checkout page, I'm have a javascript error (and I'm no good with js).

Error is :

Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'removeCookie'

Here what calls the error :

jQuery(document).ready(function(){
if(jQuery.cookie != undefined) {
    // Check if cookie are enabled
    jQuery.cookie('wpml_browser_redirect_test', '1');
    var cookie_enabled = jQuery.cookie('wpml_browser_redirect_test') == 1;
    jQuery.removeCookie('wpml_browser_redirect_test');
    ...

And here's the file with the function :

(function ($, document, undefined) {

var pluses = /\+/g;

function raw(s) {
    return s;
}

function decoded(s) {
    return decodeURIComponent(s.replace(pluses, ' '));
}

$.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) {
        options = $.extend({}, $.cookie.defaults, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path    ? '; path=' + options.path : '',
            options.domain  ? '; domain=' + options.domain : '',
            options.secure  ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || $.cookie.defaults || {};
    var decode = options.raw ? raw : decoded;
    var cookies = document.cookie.split('; ');
    for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
        if (decode(parts.shift()) === key) {
            return decode(parts.join('='));
        }
    }

    return null;
};

$.cookie.defaults = {};

$.removeCookie = function (key, options) {
    if ($.cookie(key, options) !== null) {
        $.cookie(key, null, options);
        return true;
    }
    return false;
};

})(jQuery, document);

As I don't know javascript, I really don't know what to think about it. I know that "Object function has no method" is a common problem, I've looked at others posts but I can't figure it.

So guys (and girls), I need help on this one.

Thanks

Bruno

2 Answers 2

0

This would happen if you didn't include any jQuery.cookie plugin.

7
  • Hi and thanks so much for answering. This was the first thing I checked, and it's included in the <head>. No 404 or similar issue, it's ok. I checked with firebug and chrome console. Commented Jul 10, 2013 at 16:56
  • @BrunoHug: Is it included after jQuery? Are there any other jQuerys? Commented Jul 10, 2013 at 19:50
  • It's after Jquery (jQuery v1.8.3). And yes you are right, there is another one loaded by the theme (jQuery v1.7.1). Could that be the issue ? Commented Jul 10, 2013 at 22:18
  • @BrunoHug: That's exactly the problem. The plugin is attached to the first instance of jQuery, but the second instance replaces it. You should not include multiple copies of jQuery. Commented Jul 11, 2013 at 0:28
  • I solve the issue by withdrawing one of the jquery call, and it still doesn't work. I don't know where to look Commented Jul 12, 2013 at 14:04
0

I agree with the above post, but this should also help: You error means that when you call/use the .removeCookie function your code cannot locate/find a function/method to execute with that name. Make sure the file with the .removeCookie method is in the same folder as the file with the code, and make sure your file 'includes' the file with the .removeCookie method. It is also possible that you might need to write something else before the '.removeCookie' Hope this leads to a solution. Also, you might want to get help with Wordpress if you're using that for all the code. Maybe it's incorrectly installed or something which made the code malfunction...

1
  • and thanks so much for answering. This was the first thing I checked, and it's included in the <head>. No 404 or similar issue, it's ok. I checked with firebug and chrome console. Wordpress is well installed (I re-installed it). Commented Jul 10, 2013 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.