3

Well,

I'm getting JS error "Cookies is not defined", but "js.cookie.min.js" is loaded before "woocommerce.min.js".

I check apache log to see if there's any error, but has none. I don't have caching plugins.

I don't know how to track this error to find the root cause, everything seems OK.

enter image description here

waitForImages is another JS that is loaded but I'm getting a error.

Am I missing something? Tips to find the bug?

EDIT*********

Further investigation

This is the code from js-cookie, for some reason I don't understand js-cookie is setting "registeredInModuleLoader" to true, but the variable "Cookies" is not defined yet.

;(function (factory) {
    var registeredInModuleLoader = false;
    if (typeof define === 'function' && define.amd) {
        define(factory);
        registeredInModuleLoader = true;
    }
    if (typeof exports === 'object') {
        module.exports = factory();
        registeredInModuleLoader = true;
    }
    if (!registeredInModuleLoader) {
        var OldCookies = window.Cookies;
        var api = window.Cookies = factory();
        api.noConflict = function () {
            window.Cookies = OldCookies;
            return api;
        };
    }
} /* ... */

EDIT 2

I think I found the issue, but don't know why yet.

Monday I put a singup form from MailChimp which needs this code. I think that the problem is with "embed.js", because in the condition "define.amd" (above) points to "embed.js". After remove this script the error is gone.

Any thoughts?

<script type="text/javascript" src="//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>

<script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us14.list-manage.com","uuid":"xxxxxxxxxxxxxxxxxxxxxxxxx","lid":"xxxxxxxxxx"}) })</script>

SOLVED

I change the position of Mailchimp script to the last item before , no more issues.

Thanks.

4

4 回答 4

5

我将 Mailchimp 脚本的位置更改为之前的最后一项</body>,没有更多问题。

也许 mailchiump 脚本试图加载尚未加载的内容..

于 2017-08-30T13:43:34.713 回答
2

在我们的 WordPress WooCommerce 网站上实施 MailChimp 弹出窗口之后,问题也影响了我们。我们在将礼券添加到购物车、能够启用或禁用运送到与结帐页面上的账单不同的地址、拖放上传文件等方面遇到问题 - 基本上是在页面下方使用 jQuery/javascript 进行的其他任何事情...

虽然我已经在页脚中加载了这个脚本,但我没有采取措施将它放在页脚的最底部/最后加载它。

因此,对于那些可能需要具体帮助的人我可以建议以下内容:

add_action('wp_footer', 'so45956946_mailchimp_popup', PHP_INT_MAX);

function so45956946_mailchimp_popup(){ ?>
<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.usXX.list-manage.com","uuid":"YOUR_UUID","lid":"YOUR_LID"}) })</script>
<?php }

通过将PHP_INT_MAX(此 PHP 版本中支持的最大整数)作为 add_action() 调用中的优先级,它肯定会最后加载。

于 2018-03-22T13:20:13.210 回答
1

当您的页面上加载了 2 个版本的 jquery 时,通常会发生这种情况,这通常是由于尝试将 google 用于 jquery 或主题而引起的。这需要删除。您无法通过全新安装来重现这个。

检查并确认 jquery 已正确加载后,请参阅https://docs.woocommerce.com/document/jquery-cookie-fails-to-load/

于 2017-08-30T12:39:28.250 回答
0

重命名文件并更新functions.php

wp-content/plugins/woocommerce/assets/js/jquery-cookie/jquery.cookie.js
wp-content/plugins/woocommerce/assets/js/jquery-cookie/jquery.cookie.min.js

至:

wp-content/plugins/woocommerce/assets/js/jquery-cookie/jquery_cookie.js
wp-content/plugins/woocommerce/assets/js/jquery-cookie/jquery_cookie.min.js

并将以下内容添加到主题的 functions.php 文件中:

add_action( 'wp_enqueue_scripts', 'custom_frontend_scripts' );function custom_frontend_scripts() {global $post, $woocommerce;

$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? : '.min';
wp_deregister_script( 'jquery-cookie' );
wp_register_script( 'jquery-cookie', $woocommerce->plugin_url() . '/assets/js/jquery-cookie/jquery_cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true );
}
于 2017-08-30T10:51:21.433 回答