Skip to content

Instantly share code, notes, and snippets.

@croosen
Last active February 5, 2018 14:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save croosen/24a2845f91ce91a2819b to your computer and use it in GitHub Desktop.
Save croosen/24a2845f91ce91a2819b to your computer and use it in GitHub Desktop.
WooCommerce - Display custom attributes on shop page - the official way ;-)
// Paste this in your file, somewhere in the loop, around the h3
<?php echo $product->sku; ?> <?php echo $product->omschrijving; ?> <?php the_title(); ?>
<?php
// Get the attributes
$attributes = $product->get_attributes();
// Start the loop
foreach ( $attributes as $attribute ) : ?>
<?php
// Check and output, adopted from /templates/single-product/product-attributes.php
if ( $attribute['is_taxonomy'] ) {
$values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
} else {
// Convert pipes to commas and display values
$values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
}
?>
<?php endforeach; ?>
@pegasus6464
Copy link

Can i show only desired attributes like "TOWN" and "TYPE"? THANKS!

@VasylKyryliuk
Copy link

Thank you )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment