Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created March 16, 2026 14:45
Show Gist options
  • Select an option

  • Save plugin-republic/01dd4501796e5334660db5941abd1dec to your computer and use it in GitHub Desktop.

Select an option

Save plugin-republic/01dd4501796e5334660db5941abd1dec to your computer and use it in GitHub Desktop.
Go to the last carousel image when a file is updloaded
<?php
add_action( 'wp_footer', function () { ?>
<script>
jQuery(document).ready(function($) {
setTimeout(function() {
$('.woocommerce-product-gallery .wd-carousel-item:not( :last-child ) img').click(function() {
$('.aipaou-image-layer').hide();
});
$('.woocommerce-product-gallery .wd-carousel-item:last-child img').click(function() {
$('.aipaou-image-layer').show();
});
$( 'body' ).on( 'pewc_image_uploaded', function() {
// $('.woocommerce-product-gallery .wd-carousel-item:last-child img').trigger( 'click' );
var mainEl = document.querySelector(
'.woocommerce-product-gallery__wrapper:not(.quick-view-gallery)'
);
if ( ! mainEl || ! mainEl.swiper ) return false;
var s = mainEl.swiper;
s.slideTo( s.slides.length - 1 );
// Sync the thumb strip if present
var thumbEl = document.querySelector( '.wd-gallery-thumb .wd-carousel' );
if ( thumbEl && thumbEl.swiper ) {
thumbEl.swiper.slideTo( thumbEl.swiper.slides.length - 1 );
}
$('.aipaou-image-layer').show();
});
$('.aipaou-image-layer').hide();
}, 250);
});
</script>
<?php } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment