覆盖WooCommerce前端Javascript [英] Override WooCommerce Frontend Javascript
问题描述
有人可以指导一下覆盖WooCommerce核心Javascript文件的正确方法是什么,特别是前端文件。我没有找到任何关于此的文档并查看代码,前端脚本文件的路径是在插件中硬编码所以我怀疑在我的主题中放置资产文件夹将做任何事情。
Can someone guide me as to what is the proper method of overriding WooCommerce core Javascript files, specifically frontend files. I have not found any documentation on this and looking at the code, the path to the frontend script files is hard coded in the plugin so I doubt that placing an assets folder in my theme will do anything.
最简单的方法是什么,以便我可以加载位于我的主题目录中的文件?
What is the cleanest way to to this so that I can load a file located in my theme dir?
谢谢
推荐答案
我遇到了同样的问题,除了add-to-cart.js。简单的解决方案是取消woocommerce脚本并清空您的替代品。在我的情况下,我将以下内容添加到我的functions.php中:
I had the same problem except with add-to-cart.js. Simple solution is to DEQUEUE the woocommerce script and ENQUEUE your replacement. In my case I added the following to my functions.php:
wp_dequeue_script('wc-add-to-cart');
wp_enqueue_script( 'wc-add-to-cart', get_bloginfo( 'stylesheet_directory' ). '/js/add-to-cart-multi.js' , array( 'jquery' ), false, true );
您可能想要删除'wc-add-to-cart-variation'脚本。我不认为你 与ENQUEUE有相同的名字,但我看不出有理由不这样做。
You would want to DEQUEUE the 'wc-add-to-cart-variation' script. I don't think you have to ENQUEUE with the same name, but I couldn't see a reason not to.
希望这会有所帮助。
如果您使用的是WordPress版本4.0.1和WooCommerce版本2.2.10。您可以使用以下脚本:
If you're using WordPress Version 4.0.1 and WooCommerce Version 2.2.10. You can use the following scripts:
wp_deregister_script('wc-add-to-cart');
wp_register_script('wc-add-to-cart', get_bloginfo( 'stylesheet_directory' ). '/js/add-to-cart-multi.js' , array( 'jquery' ), WC_VERSION, TRUE);
wp_enqueue_script('wc-add-to-cart');
这篇关于覆盖WooCommerce前端Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!