WOO相关产品如何覆盖插件脚本?

时间:2018-04-29 作者:Sylon

插件Woo相关产品目录:wp-content\\plugins\\woo-related-products-refresh-on-reloadwp-content\\plugins\\woo-related-products-refresh-on-reload\\public\\js\\woo-related-products-public.jswp-content\\plugins\\woo-related-products-refresh-on-reload\\public\\class-woo-related-products-public.php代码:

if (esc_attr(get_option(\'woorelated_slider\')) == \'Enabled\') {
        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . \'js/woo-related-products-public.js\', array( \'jquery\' ), $this->version, false );
将js文件复制到:wp-content/themes/child-storefront-theme/woo-related-products-refresh-on-reload/js/woo-related-products-public.js

向添加代码functions.php add_action(\'wp_enqueue_scripts\', \'custom_woo_related_products\'); function custom_woo_related_products() { wp_dequeue_script(\'woo-related-products\'); wp_enqueue_script(\'woo-related-products\', get_stylesheet_directory_uri().\'/woo-related-products-refresh-on-reload/js/woo-related-products-public.js\', array(\'jquery\')); } 但它不起作用。哪里出了错?

1 个回复
最合适的回答,由SO网友:Sylon 整理而成

将js文件复制到:wp-content/themes/child-storefront-theme/assets/js/woo-related-products-refresh-on-reload/woo-related-products-public.js

function custom_woo_related_products() {
    wp_dequeue_script(\'woo-related-products\');
    wp_enqueue_script(\'custom-woo-related-products\', get_stylesheet_directory_uri().\'/assets/js/woo-related-products-refresh-on-reload/woo-related-products-public.js\', array(\'jquery\'));
}
add_action(\'wp_enqueue_scripts\', \'custom_woo_related_products\', 100);
为什么是100?要退出队列,脚本必须已进入队列。在脚本排队之前尝试将脚本出列将不会产生任何效果。

结束

相关推荐