Home › Forums › WoodMart support forum › How to reference variation gallery images in functions.php
How to reference variation gallery images in functions.php
- This topic has 6 replies, 2 voices, and was last updated 4 years, 9 months ago by
Artem Temos.
-
AuthorPosts
-
May 22, 2020 at 6:07 pm #197082
testing123ParticipantI’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 );
May 22, 2020 at 6:55 pm #197098
Artem TemosKeymasterHello,
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
May 22, 2020 at 7:37 pm #197107
testing123ParticipantWill 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.
May 23, 2020 at 4:44 pm #197317
Artem TemosKeymasterSorry, 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?
May 29, 2020 at 3:05 pm #199005
testing123ParticipantWe 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>
May 29, 2020 at 6:30 pm #199033
testing123ParticipantEssentially, 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.
May 30, 2020 at 8:25 am #199135
Artem TemosKeymasterYes, it is stored in one array that contains variations IDs and set of IDs of images uploaded for each variation.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register