WC_API_Products::upload_image_from_url()protectedWC 2.5.0

Upload image from URL.

Method of the class: WC_API_Products{}

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->upload_image_from_url( $image_url, $upload_for );
$image_url(string) (required)
-
$upload_for(string)
-
Default: 'product_image'

Changelog

Since 2.5.0 Introduced.

WC_API_Products::upload_image_from_url() code WC 8.7.0

protected function upload_image_from_url( $image_url, $upload_for = 'product_image' ) {
	$upload = wc_rest_upload_image_from_url( $image_url );
	if ( is_wp_error( $upload ) ) {
		throw new WC_API_Exception( 'woocommerce_api_' . $upload_for . '_upload_error', $upload->get_error_message(), 400 );
	}

	do_action( 'woocommerce_api_uploaded_image_from_url', $upload, $image_url, $upload_for );

	return $upload;
}