I have this code in my child theme functions.php file:
// add hover image to woo category page
    add_action( 'woocommerce_before_shop_loop_item_title', 'mem_add_on_hover_shop_loop_image' ) ; 
        function mem_add_on_hover_shop_loop_image() {
        $image_id = wc_get_product()->get_gallery_image_ids()[0] ; 
        if ( $image_id ) {
            echo wp_get_attachment_image( $image_id, 'woocommerce_thumbnail' ) ; 
        } else { 
            //echo wp_get_attachment_image( wc_get_product()->get_image_id() ) ; 
            echo wp_get_attachment_image( wc_get_product()->get_image_id(), 'woocommerce_thumbnail' ) ; 
        }
    }
It works and it switches the category image on hover.
The problem is that a PHP error is showing related to this line:
$image_id = wc_get_product()->get_gallery_image_ids()[0] ;
The error is PHP Warning: Undefined array key 0
How can I fix this please?
Thank you Tamsin
I have not tried a fix yet.
 
    