diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-images.php b/includes/admin/meta-boxes/class-wc-meta-box-product-images.php index 4da33f854e4..d7a873f99c6 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-images.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-images.php @@ -38,14 +38,33 @@ class WC_Meta_Box_Product_Images { $attachments = array_filter( explode( ',', $product_image_gallery ) ); + $update_meta = false; + if ( ! empty( $attachments ) ) { foreach ( $attachments as $attachment_id ) { + $attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' ); + + // if attachment is empty skip + if ( empty( $attachment ) ) { + $update_meta = true; + + continue; + } + echo '
  • - ' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . ' + ' . $attachment . '
  • '; + + // rebuild ids to be saved + $updated_gallery_ids[] = $attachment_id; + } + + // need to update product meta to set new gallery ids + if ( $update_meta ) { + update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) ); } } ?>