• Resolved AaronTe

    (@aaronte)


    Just leaving this here for myself & others. All credit goes to this post here, it’s just a bit more condensed.

    You can use this snippet of code to echo an attribute anywhere within a product’s archive box, or single product page.

    Replace ATTRIBUTE with the attribute’s name
    Replace ATTRIBUTE-SLUG with the attribute’s slug

    <?php
              $ATTRIBUTE = get_the_terms( $product->id, 'pa_ATTRIBUTE-SLUG');
    if ( $ATTRIBUTE && ! is_wp_error( $ATTRIBUTE ) ) :
              foreach ( $ATTRIBUTE as $ATTRIBUTE ) {
              echo $ATTRIBUTE->name;
            }
    endif; ?>

    // if ( $ATTRIBUTE && ! is_wp_error( $ATTRIBUTE ) ) :
    // endif;

    These 2 bits, wrap the attribute call in a conditional, that stops it from displaying an error when the product does not have the attribute.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce – How to call / get attributes to display’ is closed to new replies.