Dequeue a plugin from all in-stock products
-
I am trying to dequeue the JS and CSS of a plugin from all in-stock products because these assets are only used on out-of-stock products.
I have been working towards a solution but after a couple of days, I’m hoping someone can help.
What is strange is that I was able to create a custom widget space and display it conditionally (in stock vs. out of stock) but on this one I am stumped.
Here is the code I have so far:
function conditionally_load_back_in_stock_notifier_assets() { $product_id = get_the_ID(); $product = wc_get_product($product_id); if (!empty($product)) { if ( $product->get_stock_status() == 'instock') { ## Dequeue scripts. wp_dequeue_script('cwginstock_jquery_validation'); wp_dequeue_script('cwginstock_js'); ## Dequeue styles. wp_dequeue_style('cwginstock_bootstrap'); wp_dequeue_style('cwginstock_frontend_css'); } } } add_action( 'wp_enqueue_scripts', 'conditionally_load_back_in_stock_notifier_assets' );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Dequeue a plugin from all in-stock products’ is closed to new replies.