Skip to content

Instantly share code, notes, and snippets.

@eliorivero
Last active December 12, 2015 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliorivero/4694709 to your computer and use it in GitHub Desktop.
Save eliorivero/4694709 to your computer and use it in GitHub Desktop.
<?php
/**
* Show Woocommerce custom attributes
*/
global $product;
$custom_attributes = array();
foreach ( $product->get_attributes() as $slug => $attr ) {
$custom_attributes[] = $slug;
}
// This is fine for attributes set in Woocommerce > Attributes
// but not for attributes set in product editing screen
foreach ($custom_attributes as $custom_attribute) {
$many_values = array();
foreach ( get_the_terms( $product->id, $custom_attribute) as $attr ) {
$many_values[] = $attr->name;
}
printf(
'<p>%s: %s</p>',
get_taxonomy($custom_attribute)->labels->name,
implode(', ', $many_values)
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment