Last active
July 17, 2021 04:06
-
-
Save frankschrijvers/4346dfac23d5d09bd9add736a8a620b3 to your computer and use it in GitHub Desktop.
Add gallery thumbs to woocommerce shop page
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
//* Add gallery thumbs to woocommerce shop page | |
add_action('woocommerce_shop_loop_item_title','wps_add_extra_product_thumbs', 5); | |
function wps_add_extra_product_thumbs() { | |
if ( is_shop() ) { | |
global $product; | |
$attachment_ids = $product->get_gallery_attachment_ids(); | |
echo '<div class="product-thumbs">'; | |
foreach( array_slice( $attachment_ids, 0,3 ) as $attachment_id ) { | |
$thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' )[0]; | |
echo '<img class="thumb" src="' . $thumbnail_url . '">'; | |
} | |
echo '</div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment