• Resolved imanpak

    (@imanpak)


    Hello,

    I want to get a list of product attribute terms.

    I want to know if there is a function similar to the get_the_term_list function that returns attribute terms instead.

    If not, what is the best way to get it?

Viewing 1 replies (of 1 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @imanpak

    WooCommerce doesn’t have a direct function like get_the_term_list for attribute terms. However, you can achieve this by using a combination of WordPress and WooCommerce functions.

    Here’s an example on how to do it:

    $product_id = 123;
    $taxonomy = 'pa_color';
    
    $terms = get_the_terms( $product_id, $taxonomy );
    
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    $term_list = array();
    
    foreach ( $terms as $term ) {
    $term_list[] = $term->name;
    }
    
    echo implode( ', ', $term_list );
    }

    This should give you a list of attribute terms for a specific product. If you want to get a list of all terms for a specific attribute across all products, you might need to do a more complex database query.

    Please note that custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any further questions on development or custom coding, don’t hesitate to reach out to some of our great resources available for support. Our WooCommerce community is brimming with skilled open-source developers who are active on the following channels:

    I hope this helps! If you have any other questions, feel free to ask.

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘get attribute terms’ is closed to new replies.