• Resolved inkform

    (@inkform)


    I have a few custom attributes like “age” and “level” on for my simple products. These display just fine with the following code. However, I would like to include the description as well. For instance, if the Level is “Starter” then the it might show as LEVEL: Starter (description here). Any help? Thank you.

    <?php foreach ( $attributes as $attribute ) : ?>

    <div class=”ts-attribute”>
    <?php echo wc_attribute_label( $attribute->get_name() ); ?>:
    <?php
    $values = array();

    if ( $attribute->is_taxonomy() ) {
    $attribute_taxonomy = $attribute->get_taxonomy_object();
    $attribute_values = wc_get_product_terms( $product->get_id(), $attribute->get_name(), array( ‘fields’ => ‘all’ ) );

    foreach ( $attribute_values as $attribute_value ) {
    $value_name = esc_html( $attribute_value->name );

    if ( $attribute_taxonomy->attribute_public ) {
    $values[] = ‘term_id, $attribute->get_name() ) ) . ‘” rel=”tag”>’ . $value_name . ‘‘;
    } else {
    $values[] = $value_name;
    }
    }
    } else {
    $values = $attribute->get_options();

    foreach ( $values as &$value ) {
    $value = make_clickable( esc_html( $value ) );
    }
    }

    echo apply_filters( ‘woocommerce_attribute’, wptexturize( implode( ‘, ‘, $values ) ), $attribute, $values );
    ?>
    </div>

    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor James Koster

    (@jameskoster)

    Hi there,

    You’re assigning the attribute name to a variable here;

    $value_name = esc_html( $attribute_value->name );

    You can do the same with the description;

    $value_description = esc_html( $attribute_value->description );

    You can then use that variable to display the description as required.

    Also see the answer over here for an alternative solution.

    James
    Designer @ Automattic

    Thread Starter inkform

    (@inkform)

    That is fantastic! Works great. Thank you so much for the help.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Simple Product Attribute Description’ is closed to new replies.