@lcm404 sometimes, it’s not enough to dequeue and you also have to deregister it. Moreover, consider increasing the priority to a higher number to be sure it’s triggered after the initial enqueueing is done. Here’s a new code that could work:
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') {
// Clear scripts.
wp_deregister_script('cwginstock_jquery_validation');
wp_dequeue_script('cwginstock_jquery_validation');
wp_deregister_script('cwginstock_js');
wp_dequeue_script('cwginstock_js');
// Clear styles.
wp_deregister_style('cwginstock_bootstrap');
wp_dequeue_style('cwginstock_bootstrap');
wp_deregister_style('cwginstock_frontend_css');
wp_dequeue_style('cwginstock_frontend_css');
}
}
}
add_action( 'wp_enqueue_scripts', 'conditionally_load_back_in_stock_notifier_assets', PHP_INT_MAX );
For some reason, the code is not nicely indented here when it prints, but you can beautify/format it how you wish.