Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Created April 20, 2020 17:30
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 diggeddy/8aa9833f67e9c122775b5cbcb60498d4 to your computer and use it in GitHub Desktop.
Save diggeddy/8aa9833f67e9c122775b5cbcb60498d4 to your computer and use it in GitHub Desktop.
GeneratePress - WOO Stacked Image Gallery for Single Product
<div class="woo-sumamry-wrap"><!-- open wrap -->
<div class="woo-gallery-stack hide-on-mobile">
<?php
global $product;
// Get post product thumbnail
if ( has_post_thumbnail( $product->get_id() ) ) {
$attachment_ids[0] = get_post_thumbnail_id( $product->get_id() );
$attachment = wp_get_attachment_image_src( $attachment_ids[0], 'full' );
$attachment_alt = get_post_meta( $attachment_ids[0], '_wp_attachment_image_alt', TRUE);
$attachmnent_title = get_the_title( $attachment_ids[0] );
?>
<img src="<?php echo $attachment[0] ; ?>" alt="<?php echo $attachment_alt; ?>" title="<?php echo $attachmnent_title; ?>" />
<?php
}
// Get Product Gallery Images
if ( method_exists( $product, 'get_gallery_image_ids' ) ) {
$product_image_ids = $product->get_gallery_image_ids();
foreach( $product_image_ids as $product_image_id ) {
$image_url = wp_get_attachment_url( $product_image_id, 'full' );
$image_alt = get_post_meta( $product_image_id, '_wp_attachment_image_alt', TRUE);
$image_title = get_the_title( $product_image_id );
echo '<img src="' . $image_url . '" alt="' . $image_alt . '" title="' . $image_title . '">';
}
}
// Closing div found in Close Summary Wrap element
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment