Skip to content

Instantly share code, notes, and snippets.

@raftaar1191
Last active November 15, 2023 04:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raftaar1191/1a352650fc60569243641bab90abc332 to your computer and use it in GitHub Desktop.
Save raftaar1191/1a352650fc60569243641bab90abc332 to your computer and use it in GitHub Desktop.
Woocommerce gallery trigger over full image
<?php
/**
* Check if WC_SCRIPT_in_wp_footer does not exists and is_product function exists.
*/
if( ! function_exists( 'WC_SCRIPT_in_wp_footer' ) && function_exists( 'is_product' ) ) {
/**
* Add script in the WP footer page.
*/
function WC_SCRIPT_in_wp_footer() {
if ( is_product() && ! wp_is_mobile() ) {
?>
<script type="application/javascript">
jQuery( 'div.woocommerce-product-gallery.images' ).on( 'click', 'div.flex-viewport figure' , function(){
jQuery( this ).closest( '.woocommerce-product-gallery' ).find( '.woocommerce-product-gallery__trigger' ).trigger( 'click' );
});
</script>
<?php
}
}
}
add_action( 'wp_footer', 'WC_SCRIPT_in_wp_footer' );
@raftaar1191
Copy link
Author

Copy and past the above gist in your child themes functions.php file

@Ande-GL
Copy link

Ande-GL commented Nov 15, 2023

Thank you!!
.. but in my case

      <script type="application/javascript">
                jQuery( 'div.woocommerce-product-gallery.images' ).on( 'click', 'div.woocommerce-product-gallery__image' , function(){
                    jQuery( this ).closest( '.woocommerce-product-gallery' ).find( '.woocommerce-product-gallery__trigger' ).trigger( 'click' );
                });
            </script>

I changed click target

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