Last active
February 5, 2018 14:42
-
-
Save croosen/24a2845f91ce91a2819b to your computer and use it in GitHub Desktop.
WooCommerce - Display custom attributes on shop page - the official way ;-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can i show only desired attributes like "TOWN" and "TYPE"? THANKS!