WC_API_Products::save_product_shipping_data() private WC 2.2
Save product shipping data
{} It's a method of the class: WC_API_Products{}
No Hooks.
Return
WC_Product.
Usage
// private - for code of main (parent) class only $result = $this->save_product_shipping_data( $product, $data );
- $product(WC_Product) (required)
- -
- $data(array) (required)
- -
Changelog
Since 2.2 | Introduced. |
Code of WC_API_Products::save_product_shipping_data() WC API Products::save product shipping data WC 5.0.0
private function save_product_shipping_data( $product, $data ) {
if ( isset( $data['weight'] ) ) {
$product->set_weight( '' === $data['weight'] ? '' : wc_format_decimal( $data['weight'] ) );
}
// Product dimensions
if ( isset( $data['dimensions'] ) ) {
// Height
if ( isset( $data['dimensions']['height'] ) ) {
$product->set_height( '' === $data['dimensions']['height'] ? '' : wc_format_decimal( $data['dimensions']['height'] ) );
}
// Width
if ( isset( $data['dimensions']['width'] ) ) {
$product->set_width( '' === $data['dimensions']['width'] ? '' : wc_format_decimal( $data['dimensions']['width'] ) );
}
// Length
if ( isset( $data['dimensions']['length'] ) ) {
$product->set_length( '' === $data['dimensions']['length'] ? '' : wc_format_decimal( $data['dimensions']['length'] ) );
}
}
// Virtual
if ( isset( $data['virtual'] ) ) {
$virtual = ( true === $data['virtual'] ) ? 'yes' : 'no';
if ( 'yes' == $virtual ) {
$product->set_weight( '' );
$product->set_height( '' );
$product->set_length( '' );
$product->set_width( '' );
}
}
// 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;
}