Home Forums Front-end Issues Get values from a WooCommerce Attribute Taxonomy


Get values from a WooCommerce Attribute Taxonomy

  • Hi guys,

    I want to extend my WooCommerce Shop-Category view by values from custom WooCommerce attributes. These are edited in an ACF taxonomy field.

    What I want to do is described pretty well in that article:

    However, so far I did not succeed outputting any of my attributes. I think my biggest problem is, that I don’t understand how to get both $taxonomy and $term_id, which are needed as stated by the above article.

    My current try looks like this and outputs…. nothing.
    My attribute is called ‘pa_jahrgang’ and the corresponding ACF field just ‘jahrgang’.

    function km_shop_display_post_meta() {
      global $product;
      $terms = get_the_terms( $product->id, 'pa_jahrgang');
      if( !empty($terms) ) {
        $term = array_pop($terms);
        $jahrgang = get_field('jahrgang', $term );
        if ( ! empty( $jahrgang ) ) {
          echo '<div class="product-meta">' . $jahrgang . '</div>';
    add_action( 'woocommerce_after_shop_loop_item', 'km_shop_display_post_meta', 9 );

    Am I completely wrong here? Any help?
    Thanks in advance!

  • Hi @fngrl

    You’re almost there as you say. Just change this row
    $jahrgang = get_field('jahrgang', $term );
    into this:
    $jahrgang = get_field('jahrgang', $term->taxonomy . '_' . $term->term_id );

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

The topic ‘Get values from a WooCommerce Attribute Taxonomy’ is closed to new replies.