Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow

WebflowMapper::extract_weightprivateWC 1.0

Convert Webflow weight (with optional weight-unit) to the store's weight unit.

Method of the class: WebflowMapper{}

No Hooks.

Returns

float|null.

Usage

// private - for code of main (parent) class only
$result = $this->extract_weight( $sku_field ): ?float;
$sku_field(object) (required)
SKU fieldData.

WebflowMapper::extract_weight() code WC 11.0.0

private function extract_weight( object $sku_field ): ?float {
	if ( ! isset( $sku_field->weight ) ) {
		return null;
	}

	$weight = (float) $sku_field->weight;
	if ( $weight <= 0 ) {
		return null;
	}

	$unit_key    = 'weight-unit';
	$source_unit = isset( $sku_field->{$unit_key} ) ? strtolower( (string) $sku_field->{$unit_key} ) : 'lbs';
	$source_unit = $this->normalize_weight_unit( $source_unit );

	$store_unit = strtolower( (string) get_option( 'woocommerce_weight_unit', 'kg' ) );

	if ( $source_unit === $store_unit ) {
		return $weight;
	}

	if ( function_exists( 'wc_get_weight' ) ) {
		$converted = wc_get_weight( $weight, $store_unit, $source_unit );
		return is_numeric( $converted ) ? (float) $converted : $weight;
	}

	return $weight;
}