{"id":13973078,"date":"2021-01-29T00:31:49","date_gmt":"2021-01-29T00:31:49","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/dequeue-a-plugin-from-all-in-stock-products\/"},"modified":"2021-01-29T00:31:49","modified_gmt":"2021-01-29T00:31:49","slug":"dequeue-a-plugin-from-all-in-stock-products","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/dequeue-a-plugin-from-all-in-stock-products\/","title":{"rendered":"Dequeue a plugin from all in-stock products"},"content":{"rendered":"<p>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. <\/p>\n<p>I have been working towards a solution but after a couple of days, I&#8217;m hoping someone can help. <\/p>\n<p>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. <\/p>\n<p>Here is the code I have so far: <\/p>\n<pre><code>function conditionally_load_back_in_stock_notifier_assets() {\n    $product_id = get_the_ID();\n    $product = wc_get_product($product_id);\n\tif (!empty($product)) {\n\t\tif ( $product-&gt;get_stock_status() == &#039;instock&#039;) {\n\t\t\t## Dequeue scripts.\n\t\t\twp_dequeue_script(&#039;cwginstock_jquery_validation&#039;); \n\t\t\twp_dequeue_script(&#039;cwginstock_js&#039;); \n\t\t\t## Dequeue styles.        \n\t\t\twp_dequeue_style(&#039;cwginstock_bootstrap&#039;); \n\t\t\twp_dequeue_style(&#039;cwginstock_frontend_css&#039;);\n\t\t}\n\t}\n}\nadd_action( &#039;wp_enqueue_scripts&#039;, &#039;conditionally_load_back_in_stock_notifier_assets&#039; );<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13973078","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13973078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13973078\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13973078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}