WP provides a number of conditionals. So, instead of this, which adds your JS and CSS to every URL on the site
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
function my_scripts_method(){
wp_enqueue_script( 'calc_fun', '/wp-content/themes/flatsome-child/assets/js/calc.js', array(), '1.6');
wp_enqueue_style( 'calc_css', '/wp-content/themes/flatsome-child/assets/css/calc.css', true , 9.1 );
}
You will want something like this, which only adds your JS and CSS to certain URLs
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
function my_scripts_method(){
// Only enqueue if this is a single product page that's not in product category "example"
// has_term will accept either the name, term ID, or slug of the product category
if(is_singular('product') && !has_term('example', 'product_cat')) {
wp_enqueue_script( 'calc_fun', '/wp-content/themes/flatsome-child/assets/js/calc.js', array(), '1.6');
wp_enqueue_style( 'calc_css', '/wp-content/themes/flatsome-child/assets/css/calc.css', true , 9.1 );
}
}
You can do the same thing inside your other functions – instead of always doing get_template_part()
, wrap that inside of a conditional that checks whether this is the specific product you want to add your code to.