WC_API_Products::upload_image_from_url()
Upload image from URL.
Method of the class: WC_API_Products{}
Hooks from the method
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() WC API Products::upload image from url code WC 7.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; }