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,
The answer to "Any idea for getting all attributes at once?" question is just to call function with only product id:
$array=get_post_meta($product->id);
key is optional, see http://codex.wordpress.org/Function_Reference/get_post_meta
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'));
Most updated:
$product->get_attribute( 'your_attr' );
You will need to define $product
if it's not on the page.