Support » Fixing WordPress » product_tag as image class

  • Resolved whiterider12

    (@whiterider12)


    I want to style my product images depending on product tags (not only the first tag, but all of them).

    I am using this:

    <img class="<?php echo get_the_term_list( $post->id, 'product_tag'); ?>"

    and it is not working, because Woocommerce/Wordpress is styling the product tags as a link.

    Help appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can ask WooCommerce here:

    EDIT – sorry, wrong link – try this one:
    http://wordpress.org/support/plugin/woocommerce

    Thread Starter whiterider12

    (@whiterider12)

    Thanks, but I figured it out. Here is the code:

    $image_tag = wp_get_object_terms($post->ID, 'product_tag');
    	if(!empty($image_tag)){
    		if(!is_wp_error( $image_tag )){
    			foreach($image_tag as $term){
    			$image_tag_class .= $term->name.' ';
    			}
    		}
    		$image_tag_class = strtolower($image_tag_class);
    	}

    HTML:
    <img class="<?php echo $image_tag_class; ?>">

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘product_tag as image class’ is closed to new replies.