I\'m using woocommerce on wordpress to create a simple shop site and I\'ve added a couple attributes to a product. These are namely, size
and color
. Un
You can use get_terms()
http://codex.wordpress.org/Function_Reference/get_terms
If you pass in pa_size or pa_color you will get back a list of terms in that taxonomy.
This post was written some time ago so I don't know if Woocommerce had this method in its previous incarnations.
For anyone else looking to do this, this line is all you need.
$product->list_attributes();
This allows you to customize the order and toggle whether or not you want to display the variation in the backend,
Hoping this is helpful to someone:
global $product;
// Get product attributes
$attributes = $product->get_attributes();
if ( ! $attributes ) {
echo "No attributes";
}
foreach ( $attributes as $attribute ) {
echo $attribute['name'] . ": ";
$product_attributes = array();
$product_attributes = explode('|',$attribute['value']);
$attributes_dropdown = '<select>';
foreach ( $product_attributes as $pa ) {
$attributes_dropdown .= '<option value="' . $pa . '">' . $pa . '</option>';
}
$attributes_dropdown .= '</select>';
echo $attributes_dropdown;
}
In addition to @user5029040 answer, which outputs html, if you want to get an array you can use the following function.
$product->get_variation_attributes();