插件Woo相关产品目录:wp-content\\plugins\\woo-related-products-refresh-on-reload
需要重写js文件:wp-content\\plugins\\woo-related-products-refresh-on-reload\\public\\js\\woo-related-products-public.js
包含在文件中的Js:wp-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\'));
}
但它不起作用。哪里出了错?
最合适的回答,由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?要退出队列,脚本必须已进入队列。在脚本排队之前尝试将脚本出列将不会产生任何效果。