• Resolved daphnetalbot

    (@daphnetalbot)


    Hi,

    This site has been up for almost 20 years. We created a custom attribute named Brands.

    To the theme > child theme > woocommerce > content-product.php file this was added:
    <div style=”float:left;width:32%;”><b>BRAND:</b> <?php
    $subheadingvalues = get_the_terms( $product->id, ‘pa_brand’);

    foreach ( $subheadingvalues as $subheadingvalue ) {
    echo $subheadingvalue->name;
    }
    ?></div>

    When logged into WordPress and viewing the products, I can see the Product > Attribute > Brand and see the items selected. On the website, they are no longer showing.

    I have tried things suggested in other support threads but none have worked:
    – clearing the cache
    – turning plugins off
    – adding a new attribute with items and assigning it to a product

    All plugins are up-to-date. WordPress is up-to-date.

    Any suggestions on how to fix this are appreciated.

    Thanks,
    Daphne

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support nicw.a11n

    (@nicw)

    Hi there

    get_the_terms takes two arguments, the post_id of the post you wish to query, and the taxonomy name.

    The product id can get called with $product->get_id(). The current post object ID can be called with $post->ID, or the $post object can be used as-is, in this way get_the_terms( $product, $taxonomy_name );

    Documentation for get_the_terms is here: https://developer.wordpress.org/reference/functions/get_the_terms/

    I hope this is of some help.

    • This reply was modified 5 years ago by nicw.a11n.
    Thread Starter daphnetalbot

    (@daphnetalbot)

    nicw.a11n,

    Thanks for the reply.

    To be honest I copied and pasted that code from a website. I am not a programmer. I kind of understand what you are saying but it is a bit over my head. I have some programmers I’m talking to so this may help them.

    Again thank you for your reply and the link.

    Plugin Support nicw.a11n

    (@nicw)

    Hi @daphnetalbot

    It’s a pleasure. The final snippet should read:

    $subheadingvalues = get_the_terms($product->get_id(), 'pa_brand');
    if ( $subheadingvalues ) {
        foreach ( $subheadingvalues as $subheadingvalue ) {
            echo $subheadingvalue->name;
        }
    }

    Good luck with your site

    Thread Starter daphnetalbot

    (@daphnetalbot)

    Wow that is so cool! I plugged it in and the world is still in balance 🙂

    Works like a charm.

    Thank you!!!!!!

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

The topic ‘Product Attributes Disappeared’ is closed to new replies.