Reply 322914 to: Product variation images generating in XML file

Avatar: Olga Barlow
Olga Barlow
Support staff
April 29, 2022 at 09:01

Hello,

Thank you for your patience.
Our developers took a look at the issue and found the following:

Plugin author uses $product->get_image_id() in his code but he should use $attachment_id
https://prnt.sc/bwkqupWZJkZe

It took the main image for each variation gallery image before https://prnt.sc/utcZh4ZSq_f-
after the global plugin code fix, it took the correct images
https://prnt.sc/Bed1dsuAntsi

Code before

public function get_gallery($product) {
        $attachment_ids = apply_filters('webexpert_skroutz_xml_custom_gallery', $product->get_gallery_image_ids(), $product);
        if (sizeof($attachment_ids)>0) {
            foreach ($attachment_ids as $attachment_id) {
                $this->xml->startElement('additional_imageurl');
                $this->xml->writeCData(esc_html(apply_filters('webexpert_skroutz_xml_custom_image',wp_get_attachment_url($product->get_image_id()),$product)));
                $this->xml->endElement();
            }
        }
    }

After

public function get_gallery($product) {
        $attachment_ids = apply_filters('webexpert_skroutz_xml_custom_gallery', $product->get_gallery_image_ids(), $product);
        if (sizeof($attachment_ids)>0) {
            foreach ($attachment_ids as $attachment_id) {
                $this->xml->startElement('additional_imageurl');
                $this->xml->writeCData(esc_html(apply_filters('webexpert_skroutz_xml_custom_image',wp_get_attachment_url($attachment_id),$product)));
                $this->xml->endElement();
            }
        }
    }

We added fix on your website globally in
plugins/webexpert-skroutz-xml-feed/includes/scripts/skroutz-engine-v3.php. Contact plugin author and ask them to fix the code because you will lose this fix after plugin update if they don’t fix it globally.

And we added custom filter in xstore-child/functions.php in addition

add_filter('webexpert_skroutz_xml_custom_gallery','webexpert_skroutz_xml_custom_gallery_custom',20,2);

function webexpert_skroutz_xml_custom_gallery_custom($gallery_image_ids,$product) {
	if ( $product->is_type( 'variation' ) ) {
		$has_variation_gallery_images = (bool) get_post_meta( $product->get_id(), 'et_variation_gallery_images', true );
		if ( $has_variation_gallery_images ) {
			$gallery_images = (array) get_post_meta( $product->get_id(), 'et_variation_gallery_images', true );
			return $gallery_images;
		}
        return $gallery_image_ids;
	}
	return $gallery_image_ids;
}

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.