wc_get_weight()
Normalise weights, unify to kg then convert to wanted unit value.
Usage: wc_get_weight(55, 'kg'); wc_get_weight(55, 'kg', 'lbs');
No Hooks.
Return
float
.
Usage
wc_get_weight( $weight, $to_unit, $from_unit );
- $weight(int|float) (required)
- Weight.
- $to_unit(string) (required)
- Unit to convert to. Options: 'g', 'kg', 'lbs', 'oz'.
- $from_unit(string)
- Unit to convert from. Options: 'g', 'kg', 'lbs', 'oz'.
Default: ''
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' );