• Resolved hemantvihan

    (@hemantvihan)


    We want to use external images for woocommerce it is working fine when we add a single product but fails with woocommerce bulk importer in that case it downloads images.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,
    Do you mean you want this plugin to also work with product images when you import products using WooCommerce’s inbuilt import feature?
    Best regards

    Thread Starter hemantvihan

    (@hemantvihan)

    Yes that’s what I am looking for

    Sorry for the delay.
    Please follow this guide to add below PHP snippet:

    add_filter( 'woocommerce_product_import_process_item_data', function ( $data ) {
    	global $raw_image_id, $raw_gallery_image_ids;
    	if ( isset( $data['raw_image_id'] ) ) {
    		$raw_image_id = $data['raw_image_id'];//save to process later
    		unset( $data['raw_image_id'] );//unset this so that images are not imported by WooCommerce
    	} else {
    		$raw_image_id = '';
    	}
    	if ( isset( $data['raw_gallery_image_ids'] ) ) {
    		$raw_gallery_image_ids = $data['raw_gallery_image_ids'];//save to process later
    		unset( $data['raw_gallery_image_ids'] );//unset this so that images are not imported by WooCommerce
    	} else {
    		$raw_gallery_image_ids = array();
    	}
    
    	return $data;
    } );
    add_action( 'woocommerce_product_import_inserted_product_object', function ( $product, $data ) {
    	global $raw_image_id, $raw_gallery_image_ids;
    	if ( class_exists( 'EXMAGE_WP_IMAGE_LINKS' ) ) {
    		$save = false;
    		if ( $raw_image_id ) {
    			$add_image = EXMAGE_WP_IMAGE_LINKS::add_image( $raw_image_id, $image_id );
    			if ( $add_image['id'] ) {
    				$product->set_image_id( $add_image['id'] );
    				$save = true;
    			}
    		}
    		if ( $raw_gallery_image_ids ) {
    			$gallery_image_ids = array();
    
    			foreach ( $raw_gallery_image_ids as $image_url ) {
    				$add_image = EXMAGE_WP_IMAGE_LINKS::add_image( $image_url, $image_id );
    				if ( $add_image['id'] ) {
    					$gallery_image_ids[] = $add_image['id'];
    				}
    			}
    			if ( $gallery_image_ids ) {
    				$product->set_gallery_image_ids( $gallery_image_ids );
    				$save = true;
    			}
    		}
    		if ( $save ) {
    			$product->save();
    		}
    	}
    
    }, 10, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce’ is closed to new replies.