Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
WC_API_Products::save_product_shipping_data( WC_Product $product, array $data )
Save product shipping data
Description Description
Parameters Parameters
- $product
-
(Required)
- $data
-
(Required)
Return Return
Source Source
File: includes/legacy/api/v2/class-wc-api-products.php
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;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.2 | Introduced. |