WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Woocommerce - trouble displaying attribute values (4 posts)

  1. cerstrand_mace
    Member
    Posted 10 months ago #

    I'm using Woocommerce for product display on a website I'm working on. When I'm fetching my custom attribute values I get what seems to be random empty strings between the values. Watch an example here:

    http://tec.macework.se/produkt/premium-short-sleeve-jersey-white/

    Here's my code for fetching the values:

    <?php
    								$atts = get_the_terms( $product->id, 'pa_attribute-1');
    
    								      foreach ( $atts as $att ) { ?>
    								      <li>   <?php echo $att->name; ?> </li>
    
    									  <?php } wp_reset_query();
    
    					?>
    
    					<?php
    								$atts = get_the_terms( $product->id, 'pa_attribute-2');
    
    								      foreach ( $atts as $att ) { ?>
    								      <li>   <?php echo $att->name; ?> </li> 
    
    									 <?php }  wp_reset_query();
    
    					?>
    
    					<?php
    								$atts = get_the_terms( $product->id, 'pa_attribute-3');
    
    								      foreach ( $atts as $att ) { ?>
    
    								      <li>   <?php echo $att->name; ?> </li> 
    
    									 <?php } wp_reset_query();
    
    					?>
    
    					<?php
    								$atts = get_the_terms( $product->id, 'pa_attribute-4');
    
    								      foreach ( $atts as $att ) { ?>
    								      <li>   <?php echo $att->name; ?> </li> 
    
    									 <?php } wp_reset_query();
    
    					?>

    What's up with the empty strings?

  2. cerstrand_mace
    Member
    Posted 10 months ago #

    Sorry for the ugly code spaces. Here:

    <?php
      $atts = get_the_terms( $product->id, 'pa_attribute-1');
    
    	foreach ( $atts as $att ) { ?>
    	 <li>   <?php echo $att->name; ?> </li>
    
    <?php } wp_reset_query(); ?>
    
    <?php $atts = get_the_terms( $product->id, 'pa_attribute-2');
    
    foreach ( $atts as $att ) { ?>
    
    <li>   <?php echo $att->name; ?> </li> 
    
     <?php }  wp_reset_query(); ?>
    
    <?php
    $atts = get_the_terms( $product->id, 'pa_attribute-3');
    
    foreach ( $atts as $att ) { ?>
    
    <li>   <?php echo $att->name; ?> </li> 
    
    <?php } wp_reset_query(); ?>
    
    <?php $atts = get_the_terms( $product->id, 'pa_attribute-4');
    
     foreach ( $atts as $att ) { ?>
    <li>   <?php echo $att->name; ?> </li> 
    
     <?php } wp_reset_query(); ?>
  3. esmi
    Forum Moderator
    Posted 10 months ago #

  4. cerstrand_mace
    Member
    Posted 10 months ago #

    Will do

Topic Closed

This topic has been closed to new replies.

About this Topic