wc_get_weight()
Converts weight from kilograms to any other unit of measurement and vice versa.
No Hooks.
Returns
float
. Converted weight, without specifying the unit of measurement.
Usage
wc_get_weight( $weight, $to_unit, $from_unit );
- $weight(int|float) (required)
- Weight.
- $to_unit(string) (required)
- The unit of measurement to convert to. Possible values: 'g', 'kg', 'lbs', 'oz'.
- $from_unit(string)
- The unit of measurement to convert from. Possible values: 'g', 'kg', 'lbs', 'oz'.
Default: '' - get_option( 'woocommerce_weight_unit' )
Examples
#1 Convert 1000 grams to kilograms
wc_get_weight( 1000, 'kg', 'g' );
#2 Convert 1.6 kilograms to grams
wc_get_weight( 1.6, 'g', 'kg' );
#3 Convert weight from "kg" to the default weight unit specified in woocommerce settings
wc_get_weight( $weight, get_option( 'woocommerce_weight_unit', 'g' ), 'kg' );