• Resolved deandid

    (@lcm404)


    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)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there! ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Plugin Support Missy a11n

    (@m155y5)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please feel free to start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dequeue a plugin from all in-stock products’ is closed to new replies.