Duplicate Images

Closed

Import WP Addon - WooCommerce Updated 2 months ago 4 Replies

Callum asked 2 months ago on July 31, 2024 at 3:52 pm

Hi, just a simple import of Woocommerce from XML file.

When selecting ‘is featured?’ the image gets selected in the image gallery too. Is there a way to exclude the featured image from the image gallery so that it doesn’t come up twice?

Thanks!

J

James replied Support Agent

2 months ago on July 31, 2024 at 4:14 pm

Hi Callum,

If you use the attachments section to import the featured image, and then the product gallery to import the rest of the images this should avoid the duplication.

James

CH

Callum replied

2 months ago on July 31, 2024 at 4:27 pm

Hi James,

How would I ensure that only the first line image gets uploaded for featured, and then the other lines are uploaded for product gallery?

One other thing too, sorry for being cheeky. I'm uploading these via Woocommerce Products and can't seem to find a field/option for Shipping Class. Ideally I need these being classed as one thing due to shipping reasons for dropship. Any idea how I could add this in?

Many thanks!

J

James replied Support Agent

2 months ago on July 31, 2024 at 6:10 pm

Hi Callum,

The following code snippet should stop stop featured images being added to the product gallery:

/**
* Stop featured image being added to product gallery
*/
add_action('woocommerce_before_product_object_save', function($product){

/**
* @var \WC_Product $product
*/

if(is_null(iwp()->importer)){
return;
}

$changes = $product->get_changes();
if(!isset($changes['gallery_image_ids'])){
return;
}

$main_image = get_post_meta($product->get_id(), '_thumbnail_id', true);
if(!$main_image){
return;
}

$gallery = $product->get_gallery_image_ids();
if(in_array($main_image, $gallery)){
$product->set_gallery_image_ids(array_filter($gallery, function($image) use($main_image){
return $image != $main_image;
}));
}
});

You can set the shipping class via the taxonomies section, selecting the Product shipping class option.

James

 

CH

Callum replied

2 months ago on August 2, 2024 at 5:52 pm

Thanks James, fantastic work! Much appreciated, that sorted the duplicated feature image problem out and works fine :)

Many thanks!