繁体   English   中英

WooCommerce加载错误的资产路径

[英]WooCommerce loads wrong path to assets

我在WC上有一个WP网站,据我所知,该网站运行良好。 我最近注意到,很多功能在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 );

我遇到了这个确切的问题,它似乎是由Root Relative URLs插件引起的。 禁用此有问题的插件(似乎也对WP Mail产生不利影响)似乎可以解决我的问题。

定义路径时最好使用CONSTANTS。 至少它们不能被覆盖。

例如

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 );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM