Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #1478388

    Hi

    I am trying to figure out the correct code snippet to use for changing the main single product image on hover to the first gallery image.
    Example this page: https://labhuset.no/product/fiocchetti-plasmafryser-30-40c/

    I found this earlier thread: https://kriesi.at/support/topic/change-single-product-image-on-hover-with-gallery-first-image/
    But found the code shared there unclear. It would be great with an update with a workable code.

    Enfold has been used to customize all the single product pages in WooCommerce.
    I am working on figuring out how to change images on hover (for the first gallery image) of the main product in the Single product page

    2.
    It would also be helpful to at the same time have the correct code to change images on hover in the shop page AND the archive page. Having the thumbnails seen change to the first gallery image.

    Thank you!

    • This topic was modified 1 month ago by SHR Design. Reason: A mistake in adding the word flip. It has been adjusted
    #1478393

    Hey Silje,
    Try this CSS in your Enfold Theme Options ▸ General Styling ▸ Quick CSS field:

    .single-product .avia-image-overlay-wrap:hover {
    transform: rotateY(180deg);
    }

    before hover:
    Screen Shot 2025 03 02 at 11.25.00 AM
    on hover:
    Screen Shot 2025 03 02 at 11.26.01 AM

    Best regards,
    Mike

    #1478410

    Hey Mike

    I appologize. I did not mean flip. I meant to change the single product main image for the first gallery image on hover.

    So for the single product image. On hover change the main product image for the first gallery image.
    + To do so also for the thumbnails on the Shop and Archive pages.

    Thanks.

    #1478502

    Hi,
    your test product doesn’t have a gallery, I see other product images at the bottom of the page in columns, but these are not part of the product gallery, so it is not possible.
    It looks like you built the product with the ALB, try using the default editor and add your gallery under the product image in woocommerce, this should give you the effect you are looking for, as I understand.

    Best regards,
    Mike

    #1478584

    Hey Mike

    I have added a gallery image to one of the Fiocchetti products and will add additional images to other products where I plan on using the code..
    Here is what the screen looks like in the backend of the Enfold custom single product screen: https://www.dropbox.com/s/y154n178mrx85yz/Screenshot%202025-03-04%20at%2014.26.45.jpg?st=n7e1k9nw&dl=0
    The gallery images will not be visible on the frontend.

    I am looking for a code snippet to use which will then on hover use the first gallery image instead of the main product image.
    Similar to what is done here: https://www.fiocchetti.com/en/products/bloodbanks-4degc?e=275 but mainly for the single product page.

    I need the code for the shop, archive and the single product page.

    Thanks.

    • This reply was modified 4 weeks, 1 day ago by SHR Design. Reason: Additional information
    #1478690

    Hi,
    When creating a product with the ALB and you want to show the thumbnails under the main image you will first need to ensure that you have Enfold Theme Options ▸ Shop Options ▸ Product gallery ▸ WooCommerce 3.0 product gallery enabled.
    Enfold Support 5875
    Then add this css to your child theme stylesheet or the theme option Quick CSS

    .single-product .flex-control-thumbs li {
        display: flex !important;
        float: left;
    }

    then add this code to the end of your child theme functions.php file in Appearance ▸ Editor:

    add_shortcode( 'avs_product_gallery_hook', 'avs_product_gallery_hook_callback' );
    function avs_product_gallery_hook_callback( $atts ) {
    ob_start();
    woocommerce_show_product_images();
    $content = ob_get_clean();
    return $content;
    }

    Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
    and add this shortcode to your page where you want the image to show in a code block:
    [avs_product_gallery_hook]
    Enfold Support 6606
    Enfold Support 6608
    the switch occurs on click and not hover, as per woocommerce.
    This will only work on product pages and not shop or archive pages, perhaps there is a plugin that will do that but you will prob need to also use the default editor instead of the ALB.

    Best regards,
    Mike

    #1479030

    Hey Mike

    Thank you for the code walk through here but it is not what I have been asking about.

    1.
    The client does not want the gallery image to show on the frontend.

    2.
    The client wants to be able to hover the product image and have it switch to the first gallery image which is not seen on the frontend. The gallery image is only added to the backend product screen.

    They want it seen like this: https://www.fiocchetti.com/en/products/bloodbanks-4degc?e=275 (on the Single Product image screen.)

    There is this older support thread here: https://kriesi.at/support/topic/change-single-product-image-on-hover-with-gallery-first-image/

    If Ismael is around can he add the needed code to the older support thread and also add the needed code in this thread?

    • This reply was modified 3 weeks, 2 days ago by SHR Design. Reason: Adjusting
    #1479050

    Hey!

    Thank you for the update.

    Please note that the modification from the previous thread is for the default editor and the main/featured product image. It’s not going to work when the Advance Layout Builder (ALB) is active. This is still possible with the ALB, but you’ll have to use the Image element. Go to the Advanced > Animation panel, then set the Image Hover Effect settings to Fade to another image.

    Let us know if you need additional info.

    Cheers!
    Ismael

    #1479103

    Hi Ismael

    Thank you.

    In the steps that Mike added I stopped after adding the code snippet to a code snippet plugin.

    I now went to this product: https://labhuset.no/product/fiocchetti-plasma-freezer-10-20c-glass-door/ and in the backend ALB I clicked the main image and went to Advanced -> Animation -> Parallax Rules and Image Hover Effect and switched it to “Fade to another image”. I see there is no option to which image it should switch to though.

    Went to check out the product on the frontend and noticed no hover effect.

    #1479132

    Hi,

    I see there is no option to which image it should switch to though.

    You can upload the image using the Alternate Fade Image option. Please check the screenshot below.

    View post on imgur.com

    We selected a temp image from the Media > Library.

    View post on imgur.com

    Best regards,
    Ismael

    #1479152

    Hey Ismael

    That looks like it works nicely! Thank you very much!

    The steps to get this working for a new person coming across this long thread:
    If using the Enfold’s Advance Layout Builder (ALB) then the following needs to be done to get a single product image to change on hover. This will need to manually be done for each image and can not be done automatically from the approach Ismael showed.

    ————–

    Go to the product image in the backend.
    Click the main image and go to Advanced -> Animation -> Parallax Rules and Image Hover Effect and switch it to “Fade to another image” a little further down select which image it should switch to. Save the product and check the frontend. Hovering over the product image should now switch to the image that was selected.

    ——

    Ismael I got one more thing to ask…
    Can you also update the older thread showing the code needed? So that anyone whom comes across it can see the code snippet needed to get the general WooCommerce hover product (single, shop, archive) switch to another image.

    Thank you again!

    #1479297

    Hi,

    Thank you for sharing the complete steps. Regarding the older thread, the complete solution is already there; you just need to adjust the “std” parameter to “hover_active”.

    remove_filter( 'avf_builder_elements', 'avia_woocommerce_product_elements', 500, 1 );
    add_filter( 'avf_builder_elements', 'avia_woocommerce_product_elements_mod', 500, 1 );
    
    function avia_woocommerce_product_elements_mod( $elements )
    {
    	$posttype = avia_backend_get_post_type();
    
        if( ! empty( $posttype ) && $posttype == 'product' )
        {
            $elements[] = array("slug"	=> "avia_product_hover",
                "name" 	=> "Hover effect on <strong>Overview Pages</strong>",
                "desc" 	=> "Do you want to display a hover effect on overview pages and replace the default thumbnail with the first image of the gallery?",
                "id" 	=> "_product_hover",
                "type" 	=> "select",
                "std" 	=> "hover_active",
                "class" => "avia-style",
                "subtype" => array("Yes - show first gallery image on hover" => 'hover_active', "No hover effect" => ''));
    
            $counter = 0;
            foreach( $elements as $element )
            {
                if( $element['id'] == 'sidebar' ) 
    			{
    				$elements[ $counter ]['required'] = '';
    			}
                else if( $element['id'] == 'layout' ) 
                {
    	            $elements[ $counter ]['builder_active'] = true;
    	           // unset($elements[$counter]);
                }
                $counter++;
            }
        }
    
    	return $elements;
    }

    Best regards,
    Ismael

    #1480545

    Thank you Ismael!
    How would I got about using the code for any theme running WooCommerce?

    I am thinking about adding a tutorial and will add a link to this thread.
    Thank you again.

    #1480555

    Hi,

    This modification is intended only for the Enfold theme — it will not work with other themes.

    Best regards,
    Ismael

    #1480624

    Thank you for the feedback.
    Have a great day!

    #1480640

    Hi,
    Glad Ismael could help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 16 posts - 1 through 16 (of 16 total)
  • The topic ‘WooCommerce hover over image changes to first gallery image’ is closed to new replies.