allow variation image to be removed via REST API
This commit is contained in:
parent
cbfe4bd595
commit
78c2a07306
|
@ -354,16 +354,21 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
|||
protected function set_variation_image( $variation, $image ) {
|
||||
$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
|
||||
|
||||
if ( 0 === $attachment_id && isset( $image['src'] ) ) {
|
||||
$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
|
||||
if ( 0 === $attachment_id ) {
|
||||
if ( isset( $image['src'] ) ) {
|
||||
$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
|
||||
|
||||
if ( is_wp_error( $upload ) ) {
|
||||
if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) {
|
||||
throw new WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 );
|
||||
if ( is_wp_error( $upload ) ) {
|
||||
if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) {
|
||||
throw new WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() );
|
||||
$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() );
|
||||
} else {
|
||||
$variation->set_image_id( '' );
|
||||
return $variation;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
|
|
Loading…
Reference in New Issue