[REST API] Throw messages when trying to manipulate variations in products endpoint
This commit is contained in:
parent
e1b914d227
commit
f23a529329
|
@ -142,7 +142,9 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
|||
$id = (int) $request['id'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
|
||||
if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
|
@ -247,7 +249,9 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
|||
$id = (int) $request['id'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
|
||||
if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -1786,7 +1786,9 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
|||
$force = (bool) $request['force'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
|
||||
if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid post ID.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue