我有一个带WC的可湿性粉剂网站,据我所知,它工作得很好。我最近注意到很多函数在WooCommerce中都不起作用(比如查询函数、显示/隐藏框等)。
我把它归结为:
需要从正确的路径加载文件。看起来WC在路径中添加了两次url。
文件的正确路径:
http://my-web-site.com/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js
正在被称为:
http://my-web-site.com/my-web-site.com/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js
我确定了源文件,但我找不到任何会导致此路径与其他调用不同的内容。我肯定我漏掉了什么。代码如下:
public function load_scripts() {
global $post, $wp;
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$lightbox_en = get_option( 'woocommerce_enable_lightbox' ) == 'yes' ? true : false;
$ajax_cart_en = get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' ? true : false;
$assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/';
$frontend_script_path = $assets_path . 'js/frontend/';
// Register any scripts for later use, or used as dependencies
wp_register_script( 'chosen', $assets_path . 'js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.0.0', true );
wp_register_script( 'jquery-blockui', $assets_path . 'js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.60', true );
wp_register_script( 'jquery-payment', $assets_path . 'js/jquery-payment/jquery.payment' . $suffix . '.js', array( 'jquery' ), '1.0.2', true );
wp_register_script( 'wc-credit-card-form', $assets_path . 'js/frontend/credit-card-form' . $suffix . '.js', array( 'jquery', 'jquery-payment' ), WC_VERSION, true );
wp_register_script( 'wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'wc-address-i18n', $frontend_script_path . 'address-i18n' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true );发布于 2014-10-04 02:24:22
我遇到了这个问题,它似乎是由Root Relative URLs插件引起的。禁用这个有问题的插件(这似乎也会对WP Mail产生负面影响)似乎解决了我的问题。
发布于 2014-07-24 16:22:19
在定义路径时最好使用常量。至少这样它们就不会被覆盖。
例如:
define('AD_PATH', WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__)));你可以随时随地使用它:
wp_register_script( 'chosen', AD_PATH . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.0.0', true );https://stackoverflow.com/questions/24925778
复制相似问题