Skip to content

Instantly share code, notes, and snippets.

@croosen
Last active February 5, 2018 14:42
Show Gist options
  • 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; ?>
@VasylKyryliuk
Copy link

Thank you )

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