Automattic\WooCommerce\Blocks\AIContent
UpdateProducts::product_image_upload()
Upload the image for the product.
Method of the class: UpdateProducts{}
No Hooks.
Return
Int|String|WP_Error
.
Usage
// private - for code of main (parent) class only $result = $this->product_image_upload( $product_id, $image_src, $image_alt );
- $product_id(int) (required)
- The product ID.
- $image_src(string) (required)
- The image source.
- $image_alt(string) (required)
- The image alt.
UpdateProducts::product_image_upload() UpdateProducts::product image upload code WC 9.8.1
private function product_image_upload( $product_id, $image_src, $image_alt ) { require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; // Since the media_sideload_image function is expensive and can take longer to complete // the process of downloading the external image and uploading it to the media library, // here we are increasing the time limit to avoid any issues. set_time_limit( 150 ); wp_raise_memory_limit( 'image' ); return media_sideload_image( $image_src, $product_id, $image_alt, 'id' ); }