I have a straightforward question:
How do I change the links (base URL) of the JS and CSS assets provided by WooCommerce (or any other plugin) in order to use a CDN?
The only requirements I have:
- I do not want to use any plugin.
- I do not want to change any code in
wp-content/plugins
as this will be overwritten by the next updates. - I do not want to change
WP_PLUGIN_DIR
orWP_PLUGIN_URL
, because other plugins and plugin components rely on this path and I don't want / can not upload the whole plugin code to the CDN (correct me please if I'm wrong in any way).
To be precise, I'm talking about the following assets:
example.com/wp-content/plugins/woocommerce/assets/js/jquery-blockui/jquery.blockUI.min.js
example.com/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js'
example.com/wp-content/plugins/woocommerce/assets/js/js-cookie/js.cookie.min.js'
example.com/wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js
example.com/wp-content/plugins/woocommerce/assets/js/jquery-cookie/jquery.cookie.min.js
example.com/wp-content/plugins/woo-poly-integration/public/js/Cart.min.js
I checked the plugin code and they register the assets like this:
wp_register_script( 'jquery-blockui', WC()->plugin_url() .
'/assets/js/jquery-blockui/jquery.blockUI' . $suffix .
'.js', array( 'jquery' ), '2.70', true );
Sure, I could change the plugin_url()
function, but that would have two disadvantages: First other components rely on the plugin_url
(I would brake other functionality) and second, I would loose the changes with every new update.
Any help would be appreciated.