archetyped / simple-lightbox-extensions

Feedback & Support for Simple Lightbox Extensions
https://archetyped.com/tools/simple-lightbox/
2 stars 3 forks source link

Product Image Doesn't Open In SLB but Product Gallery Images Do #100

Closed PaulTarver closed 2 years ago

PaulTarver commented 2 years ago

I just got the WooCommerce Extension and installed it along with SLB. Images on regular pages seem to open in the lightbox exactly as expected and Product Gallery Images on a Single Product Page open in the lightbox as well. However, when I click on the Product Image on the Single Product Page, the image is opened as an image in the same page. I would have expected that the Product Image would open in the lightbox, but that's not what is happening.

Details

Thanks In Advance! Paul Tarver

archetyped commented 2 years ago

Hi, SLB's WooCommerce extension supports WooCommerce's built-in product image templates, but it appears that your site is using a different template for the product images.

Can you please provide the theme's template used for displaying WooCommerce products to determine if anything is missing? See GitHub's documentation on formatting code blocks to ensure that the inserted template code is properly formatted.

Thank you.

PaulTarver commented 2 years ago

The template includes a php file for the single-product post but within that is a sub-folder which contains a product-image.php which I think is specifically the section you are interested in.

Let me know if you need something other than this:

...

<?php
    if ( has_post_thumbnail() ) {

        $image              = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
        $image_title        = esc_attr( get_the_title( get_post_thumbnail_id() ) );
        $image_link         = wp_get_attachment_url( get_post_thumbnail_id() );
        $attachment_count   = count( $product->get_gallery_image_ids() );

        if ( $attachment_count > 0 ) {
            $gallery = '[product-gallery]';
        } else {
            $gallery = '';
        }

        echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s"  rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image ), $post->ID );

    } else {

        echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );

    }
?>

<?php do_action( 'woocommerce_product_thumbnails' ); ?>

...

archetyped commented 2 years ago

Thank you for the template code.

Your template uses the filter woocommerce_single_product_image_html for the product image. This filter was removed from WooCommerce in 2017 (v3.0.0).

Per WooCommerce's v3.0.0 migration notes, the filter woocommerce_single_product_image_thumbnail_html should be used instead.

SLB's WooCommerce extension fully supports the woocommerce_single_product_image_thumbnail_html filter, so replacing the removed filter hook with woocommerce_single_product_image_thumbnail_html in your template should allow SLB to display the product image in a lightbox.

Please post an updated link if you are still experiencing this issue after updating the template, and I would be glad to reopen this ticket and take another look.

Thanks.

PaulTarver commented 2 years ago

That worked! Thanks!