WC_REST_Products_V2_Controller::save_product_shipping_data()
Save product shipping data.
Method of the class: WC_REST_Products_V2_Controller{}
No Hooks.
Return
WC_Product
.
Usage
// protected - for code of main (parent) or child class $result = $this->save_product_shipping_data( $product, $data );
- $product(WC_Product) (required)
- Product instance.
- $data(array) (required)
- Shipping data.
WC_REST_Products_V2_Controller::save_product_shipping_data() WC REST Products V2 Controller::save product shipping data code WC 7.7.0
protected function save_product_shipping_data( $product, $data ) { // Virtual. if ( isset( $data['virtual'] ) && true === $data['virtual'] ) { $product->set_weight( '' ); $product->set_height( '' ); $product->set_length( '' ); $product->set_width( '' ); } else { if ( isset( $data['weight'] ) ) { $product->set_weight( $data['weight'] ); } // Height. if ( isset( $data['dimensions']['height'] ) ) { $product->set_height( $data['dimensions']['height'] ); } // Width. if ( isset( $data['dimensions']['width'] ) ) { $product->set_width( $data['dimensions']['width'] ); } // Length. if ( isset( $data['dimensions']['length'] ) ) { $product->set_length( $data['dimensions']['length'] ); } } // Shipping class. if ( isset( $data['shipping_class'] ) ) { $data_store = $product->get_data_store(); $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) ); $product->set_shipping_class_id( $shipping_class_id ); } return $product; }