Merge pull request #15966 from woocommerce/fix/15960

[REST API] Allow unset product shipping_class
This commit is contained in:
Mike Jolley 2017-07-05 11:24:12 +01:00 committed by GitHub
commit d03982bea1
4 changed files with 12 additions and 20 deletions

View File

@ -1120,11 +1120,9 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
// Shipping class. // Shipping class.
if ( isset( $data['shipping_class'] ) ) { if ( isset( $data['shipping_class'] ) ) {
$shipping_class_term = get_term_by( 'slug', wc_clean( $data['shipping_class'] ), 'product_shipping_class' ); $data_store = $product->get_data_store();
$shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) );
if ( $shipping_class_term ) { $product->set_shipping_class_id( $shipping_class_id );
$product->set_shipping_class_id( $shipping_class_term->term_id );
}
} }
return $product; return $product;

View File

@ -1496,10 +1496,8 @@ class WC_API_Products extends WC_API_Resource {
if ( isset( $data['shipping_class'] ) ) { if ( isset( $data['shipping_class'] ) ) {
$data_store = $product->get_data_store(); $data_store = $product->get_data_store();
$shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) ); $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) );
if ( $shipping_class_id ) {
$product->set_shipping_class_id( $shipping_class_id ); $product->set_shipping_class_id( $shipping_class_id );
} }
}
return $product; return $product;
} }

View File

@ -2000,10 +2000,8 @@ class WC_API_Products extends WC_API_Resource {
if ( isset( $data['shipping_class'] ) ) { if ( isset( $data['shipping_class'] ) ) {
$data_store = $product->get_data_store(); $data_store = $product->get_data_store();
$shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) ); $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) );
if ( $shipping_class_id ) {
$product->set_shipping_class_id( $shipping_class_id ); $product->set_shipping_class_id( $shipping_class_id );
} }
}
return $product; return $product;
} }

View File

@ -932,11 +932,9 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
// Shipping class. // Shipping class.
if ( isset( $data['shipping_class'] ) ) { if ( isset( $data['shipping_class'] ) ) {
$shipping_class_term = get_term_by( 'slug', wc_clean( $data['shipping_class'] ), 'product_shipping_class' ); $data_store = $product->get_data_store();
$shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) );
if ( $shipping_class_term ) { $product->set_shipping_class_id( $shipping_class_id );
$product->set_shipping_class_id( $shipping_class_term->term_id );
}
} }
return $product; return $product;