Create new product attribute programmatically in Woocommerce

To create a term you can use wp_insert_term() like so: wp_insert_term( ‘red’, ‘pa_colors’ ); where colors is the name of your attribute. The taxonomy name of an attribute is always prepended by pa_. Edit Attributes are merely custom taxonomies. Or you could say they are dynamic taxonomies that are manually created by the user in … Read more

Get custom product attributes in Woocommerce

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’));