Duplicate product images
-
Very great plugin and helpful.
I need help becuase the many products have same images
can the function woocommerce_osc_import_image modified so that if image exist used their attachment id instead of upload same product for new product. please take a look the function if it works.function woocommerce_osc_import_image($url){
$attach_id = 0;
$wp_upload_dir = wp_upload_dir();$filename = $wp_upload_dir[‘path’].’/’.sanitize_file_name(basename($url));
if(file_exists($filename)){
$image_url = $filename;$attach_id = attachment_url_to_postid($local_url);
require_once(ABSPATH . ‘wp-admin/includes/image.php’);
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
}else{
//Encode the URL
$base = basename($url);
$url = str_replace($base,urlencode($base),$url);
if($f = @file_get_contents($url)){
file_put_contents($filename,$f);$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
‘guid’ => $wp_upload_dir[‘url’] . ‘/’ . basename( $filename ),
‘post_mime_type’ => $wp_filetype[‘type’],
‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)),
‘post_content’ => ”,
‘post_status’ => ‘inherit’
);
$attach_id = wp_insert_attachment( $attachment, $filename, 37 );
require_once(ABSPATH . ‘wp-admin/includes/image.php’);
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
}
return $attach_id;
}
- The topic ‘Duplicate product images’ is closed to new replies.