has_term
must be used inside the loop. If you use it outside the loop you have to pass the post ID or post object you want to check.
In the single.php file put your code inside the loop to check the current post:
<?php get_header();
while(have_post) {
the_post();
?>
<div class="non-home-parallax product-listing-parallax" style="
<?php if( has_term ('fama-advance', 'product-cat') ) { ?>
background-image:url('<?php echo get_template_directory_uri(); ?>/img/parallax/advance.jpg');
<?php } elseif ( has_term ('fama-confectionary-solutions', 'product-cat') ) { ?>
background-image:url('<?php echo get_template_directory_uri(); ?>/img/parallax/premium.jpg');
<?php } elseif ( has_term ('fama-premium', 'product-cat') ) { ?>
background-image:url('<?php echo get_template_directory_uri(); ?>/img/parallax/confectionary.jpg');
<?php } else { ?> <?php } ?> ">
The rest of you code
<?pphp } //end while
get_footer(); ?>
Also, I recommend to you to add a different class
instead of a different style
attribute and put the style in you CSS file. Also, it would be better to define a function that return the class instead of that ugly set of if else statements in the template file. Even better, use the post_class function in the container of your post. This function returns a string of class that you can filter to include classes based on your custom taxonomy.
In the single.php template file:
<?php get_header();
while(have_post) {
the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
The rest of you code
</div>
<?pphp } //end while
get_footer(); ?>
In the functions.php file:
// add product-cat in post class
add_filter( 'post_class', 'product_cat_class' );
function product_cat_class( $classes ) {
global $post;
$product_cats = get_the_terms( $post->ID, 'product-cat' );
foreach ( $product_cats as $product_cat ) {
$classes[] = $product_cat->slug;
}
return $classes;
}
In your CSS, for example:
.fama-advance {
background-image: url('img/parallax/advance.jpg');
}