Home Forums WoodMart support forum How to reference variation gallery images in functions.php

How to reference variation gallery images in functions.php

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #197082

    testing123
    Participant

    I’m trying to modify the main image of a variation that gets sent to google in my feed to replace it with the first image from the variation’s gallery if it has a certain tag. My understanding is that the variation galleries are not a feature native to WooCommerce, but are a part of the Woodmart theme. I can’t seem to figure out how to reference the gallery images in particular in the code. Here is the function I’ve written so far:

    function lw_woocommerce_gpf_feed_item_google( $feed_item, $product ) {
    
        $tags = wp_get_post_terms( $product->get_parent_id(), 'product_tag', array( 'fields' => 'ids' ) );
    
        if ( in_array( 6909, $tags ) ) {
    
            $attachment_ids = $product->get_gallery_image_ids();
    
            $first_gallery_image = wp_get_attachment_url( $attachment_ids[0] );
    
            $feed_item->image_link = $first_gallery_image;
        }
    
        return $feed_item;
    }
    add_filter( 'woocommerce_gpf_feed_item_google', 'lw_woocommerce_gpf_feed_item_google', 10, 2 );
    #197098

    Artem Temos
    Keymaster

    Hello,

    You can investigate how our variations gallery works in the following file where you can get the code you need woodmart\inc\integrations\woocommerce\modules\variation-gallery.php.

    Regards

    #197107

    testing123
    Participant

    Will check out that file. Separate but related issue: I think because of the way variation galleries are set up by Woodmart, it’s causing an issue with the google feed where every variation is displaying the same pool of images from all variations, not just that particular variation.

    #197317

    Artem Temos
    Keymaster

    Sorry, but we don’t quite understand the problem with our theme. Could you please provide some explanations so we can check the issue from our side?

    #199005

    testing123
    Participant

    We use WooCommerce’s Google Product Feed extension which supplies all product information, images, etc to Google, and in the case of variations that have gallery images (not just a main image), the Google feed seems to be receiving images from one big pool based on the parent product. So essentially, each variation is getting ALL the gallery images for every variation, instead of just the gallery images for that specific variation. I’ve included a snippet of the XML (showing two variations) so you can see what that looks like.

    
    <item>
    <g:ID>woocommerce_gpf_135944</g:ID>
    <g:item_group_id>woocommerce_gpf_135941</g:item_group_id>
    <title>
    <![CDATA[ Minelab X-TERRA 505 Metal Detector Bundles (Product Bundle: Treasure Bundle) ]]>
    </title>
    <link>https://sdcomlivedev.wpengine.com/product/minelab-x-terra-505-metal-detector-bundles/?attribute_pa_product-bundle=treasure-bundle</link>
    <description>
    <![CDATA[ <p>Bundled items included:</p> <ul> <li>Serious Detecting Camo Pouch</li> <li>Nylon digging trowel</li> <li>Pair of dipped digging gloves</li> </ul> ]]>
    </description>
    <g:image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2019/08/3705-0113-PKSD02ML-001-2.jpg ]]>
    </g:image_link>
    <g:price>349.00 USD</g:price>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2019/08/3705-0113-2018.jpg ]]>
    </g:additional_image_link>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2020/05/3705-0113_profind_15.jpg ]]>
    </g:additional_image_link>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2020/05/3705-0113_profind_35.jpg ]]>
    </g:additional_image_link>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2020/05/3705-0113_profind_35_battery.jpg ]]>
    </g:additional_image_link>
    <g:availability>
    <![CDATA[ in stock ]]>
    </g:availability>
    <g:condition>
    <![CDATA[ new ]]>
    </g:condition>
    <g:brand>
    <![CDATA[ Minelab ]]>
    </g:brand>
    <g:product_type>
    <![CDATA[ Metal Detectors _ Minelab _ Minelab X-TERRA 505 ]]>
    </g:product_type>
    <g:google_product_category>
    <![CDATA[ 361 ]]>
    </g:google_product_category>
    <g:size_system>
    <![CDATA[ US ]]>
    </g:size_system>
    <g:adwords_labels>
    <![CDATA[ Metal Detectors ]]>
    </g:adwords_labels>
    <g:min_handling_time>
    <![CDATA[ 1 ]]>
    </g:min_handling_time>
    <g:max_handling_time>
    <![CDATA[ 1 ]]>
    </g:max_handling_time>
    <g:promotion_id>
    <![CDATA[ 0 ]]>
    </g:promotion_id>
    <g:mpn>
    <![CDATA[ 3705-0113-test01 ]]>
    </g:mpn>
    <g:gtin>
    <![CDATA[ 811493012957 ]]>
    </g:gtin>
    <g:shipping_height>
    <![CDATA[ 16 cm ]]>
    </g:shipping_height>
    <g:shipping_width>
    <![CDATA[ 30 cm ]]>
    </g:shipping_width>
    <g:shipping_length>
    <![CDATA[ 59 cm ]]>
    </g:shipping_length>
    <g:shipping_weight>2438.057 g</g:shipping_weight>
    </item>
    <item>
    <g:ID>woocommerce_gpf_135945</g:ID>
    <g:item_group_id>woocommerce_gpf_135941</g:item_group_id>
    <title>
    <![CDATA[ Minelab X-TERRA 505 Metal Detector Bundles (Product Bundle: Adventure Bundle) ]]>
    </title>
    <link>https://sdcomlivedev.wpengine.com/product/minelab-x-terra-505-metal-detector-bundles/?attribute_pa_product-bundle=adventure-bundle</link>
    <description>
    <![CDATA[ <p>Includes Serious Detecting metal detector bag, Serious Detecting Camo Pouch, Nylon digging trowel, gloves, and Serious Detecting cap</p> ]]>
    </description>
    <g:image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2019/08/3705-0113-PKSD02ML-002-1.jpg ]]>
    </g:image_link>
    <g:price>389.00 USD</g:price>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2019/08/3705-0113-2018.jpg ]]>
    </g:additional_image_link>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2020/05/3705-0113_profind_15.jpg ]]>
    </g:additional_image_link>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2020/05/3705-0113_profind_35.jpg ]]>
    </g:additional_image_link>
    <g:additional_image_link>
    <![CDATA[ https://sdcomlivedev.wpengine.com/wp-content/uploads/2020/05/3705-0113_profind_35_battery.jpg ]]>
    </g:additional_image_link>
    <g:availability>
    <![CDATA[ in stock ]]>
    </g:availability>
    <g:condition>
    <![CDATA[ new ]]>
    </g:condition>
    <g:brand>
    <![CDATA[ Minelab ]]>
    </g:brand>
    <g:product_type>
    <![CDATA[ Metal Detectors _ Minelab _ Minelab X-TERRA 505 ]]>
    </g:product_type>
    <g:google_product_category>
    <![CDATA[ 361 ]]>
    </g:google_product_category>
    <g:size_system>
    <![CDATA[ US ]]>
    </g:size_system>
    <g:adwords_labels>
    <![CDATA[ Metal Detectors ]]>
    </g:adwords_labels>
    <g:min_handling_time>
    <![CDATA[ 1 ]]>
    </g:min_handling_time>
    <g:max_handling_time>
    <![CDATA[ 1 ]]>
    </g:max_handling_time>
    <g:promotion_id>
    <![CDATA[ 0 ]]>
    </g:promotion_id>
    <g:mpn>
    <![CDATA[ 3705-0113-test02 ]]>
    </g:mpn>
    <g:gtin>
    <![CDATA[ 811493012957 ]]>
    </g:gtin>
    <g:shipping_height>
    <![CDATA[ 16 cm ]]>
    </g:shipping_height>
    <g:shipping_width>
    <![CDATA[ 30 cm ]]>
    </g:shipping_width>
    <g:shipping_length>
    <![CDATA[ 59 cm ]]>
    </g:shipping_length>
    <g:shipping_weight>2438.057 g</g:shipping_weight>
    </item>
    
    #199033

    testing123
    Participant

    Essentially, from what I can tell, Woodmart seems to be storing the variation gallery images into one big pool based on the parent ID rather than the variation ID, so I don’t know how to access/do anything with the gallery images for a particular variation, and they are also being supplied to the Google feed incorrectly as a result.

    #199135

    Artem Temos
    Keymaster

    Yes, it is stored in one array that contains variations IDs and set of IDs of images uploaded for each variation.

Viewing 7 posts - 1 through 7 (of 7 total)