WC_Product_Importer::set_image_data
Convert raw image URLs to IDs and set.
Method of the class: WC_Product_Importer{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->set_image_data( $product, $data );
- $product(WC_Product) (required) (passed by reference — &)
- Product instance.
- $data(array) (required)
- Item data.
WC_Product_Importer::set_image_data() WC Product Importer::set image data code WC 10.6.2
protected function set_image_data( &$product, $data ) {
// Image URLs need converting to IDs before inserting.
if ( isset( $data['raw_image_id'] ) ) {
$attachment_id = $this->get_attachment_id_from_url( $data['raw_image_id'], $product->get_id() );
$product->set_image_id( $attachment_id );
wc_product_attach_featured_image( $attachment_id, $product );
}
// Gallery image URLs need converting to IDs before inserting.
if ( isset( $data['raw_gallery_image_ids'] ) ) {
$gallery_image_ids = array();
foreach ( $data['raw_gallery_image_ids'] as $image_id ) {
$gallery_image_ids[] = $this->get_attachment_id_from_url( $image_id, $product->get_id() );
}
$product->set_gallery_image_ids( $gallery_image_ids );
}
}