WC_API_Products::save_product_shipping_data()privateWC 2.2

Save product shipping data

Метод класса: WC_API_Products{}

Хуков нет.

Возвращает

WC_Product.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->save_product_shipping_data( $product, $data );
$product(WC_Product) (обязательный)
-
$data(массив) (обязательный)
-

Список изменений

С версии 2.2 Введена.

Код WC_API_Products::save_product_shipping_data() WC 8.7.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;
}