[php] Get custom product attributes in Woocommerce

In Woocommerce, I am trying to get product custom attribute values but I fail miserably and I don't get anything.

So I tried:

global $woocommerce, $post, $product;
$res = get_post_meta($product->id);

And I'm getting this raw data:

[pa_koostis] => Array
            [name] => pa_koostis
            [value] => 
            [position] => 0
            [is_visible] => 1
            [is_variation] => 0
            [is_taxonomy] => 1

I know that there is a value because it is shown in the attribute section, but I just can't find a way to get it displayed with my custom code.

This question is related to php wordpress woocommerce product custom-taxonomy

The answer is

Edited: The woocommerce_get_product_terms is deprecated since Woocommerce version 3

Go with the following as @datafeedr wrote in his answer:

global $product;
$koostis = array_shift( wc_get_product_terms( $product->id, 'pa_koostis', array( 'fields' => 'names' ) ) );

or even more compact:

global $product;
$koostis = $product->get_attribute( 'pa_koostis' );

Original answer:

$result = array_shift(woocommerce_get_product_terms($product->id, 'pa_koostis', 'names'));

Similar questions with php tag:

Similar questions with wordpress tag:

Similar questions with woocommerce tag:

Similar questions with product tag:

Similar questions with custom-taxonomy tag: