Last active
November 15, 2023 04:33
-
-
Save raftaar1191/1a352650fc60569243641bab90abc332 to your computer and use it in GitHub Desktop.
Woocommerce gallery trigger over full image
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
<?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' ); |
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
Copy and past the above gist in your child themes functions.php file