Attributes in Single Product Page - by c_notari

This topic has 4 replies, 3 voices, and was last updated 9 years, 11 months ago ago by Eva Kemp

  • Avatar: c_notari
    c_notari
    Participant
    January 13, 2016 at 21:27

    Hi:

    As a request from a customer, we added a code to display the attributes, just under the categories name.

    The function works, but we cannot format anything in the echo function. Since it works with other themes, does Legenda format this output before displaying it?

    This is the code that we added to the functions.php. The class is formatted as bold. I’ve even tried to add a style=”font-weight:bold;” in the <span>.

    Thanks

    ————– code at functions.php ————————-

    <?php
    define(‘ETHEME_DOMAIN’, ‘legenda’);
    require_once( get_template_directory() . ‘/framework/init.php’ );

    /**
    * Show all product attributes on the product page
    */

    function isa_woocommerce_all_pa(){

    global $product;
    $attributes = $product->get_attributes();

    if ( ! $attributes ) {
    return;
    }

    $out = ”;

    foreach ( $attributes as $attribute ) {

    // skip variations
    if ( $attribute[‘is_variation’] ) {
    continue;
    }

    if ( $attribute[‘is_taxonomy’] ) {

    $terms = wp_get_post_terms( $product->id, $attribute[‘name’], ‘all’ );

    // get the taxonomy
    $tax = $terms[0]->taxonomy;

    // get the tax object
    $tax_object = get_taxonomy($tax);

    // get tax label
    if ( isset ($tax_object->labels->name) ) {
    $tax_label = $tax_object->labels->name;
    } elseif ( isset( $tax_object->label ) ) {
    $tax_label = $tax_object->label;
    }

    foreach ( $terms as $term ) {

    $out .= $tax_label . ‘: ‘;
    $out .= $term->name . ‘<br />’;

    }

    } else {
    $out .= ‘<span class=”attribute-label”>’ . $attribute[‘name’] . ‘: </span> ‘;
    $out .= ‘<span class=”attribute-value”>’ . $attribute[‘value’] . ‘</span><br />’;
    }
    }
    // echo ‘<br /> <br />’;
    echo $out;
    echo ‘<br /> <br/>’;
    }

    add_action(‘woocommerce_single_product_summary’, ‘isa_woocommerce_all_pa’, 3);

    Please, contact administrator
    for this information.
    3 Answers
    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    January 14, 2016 at 14:24

    Hello,

    As you can see in browser inspector there are no any classes for your output, see the screenshot http://prntscr.com/9pze7e so it inherits parent style properties. You need to add class or classes in your code to format the output. For example I’ve changed the line echo $out; to the following echo '<div class="test">' . $out . '</div>'; and added css code in child style.css

    .test {
        font-weight: bold;
        color: #676767;
    }

    Check the product page now.

    Best regards,
    Jack Richardson.

    Avatar: c_notari
    c_notari
    Participant
    January 19, 2016 at 15:10

    Thank you very much Jack.

    Avatar: Eva
    Eva Kemp
    Participant
    January 19, 2016 at 15:19

    Hello,

    You are welcome.

    Regards,
    Eva Kemp.

  • Viewing 4 results - 1 through 4 (of 4 total)

The issue related to '‘attributes in Single Product Page’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.