Get custom product attributes in Woocommerce
Solution 1:
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'));
Solution 2:
Update for 2018. You can use:
global $product;
echo wc_display_product_attributes( $product );
To customise the output, copy plugins/woocommerce/templates/single-product/product-attributes.php
to themes/theme-child/woocommerce/single-product/product-attributes.php
and modify that.
Solution 3:
September 2014:
$product->get_attribute( 'your_attr' );
You will need to define $product
if it's not on the page.
Solution 4:
You can get the single value for the attribute with below code:
$pa_koostis_value = get_post_meta($product->id, 'pa_koostis', true);