wc_get_dimension() WC 1.0
Normalise dimensions, unify to cm then convert to wanted unit value.
Usage: wc_get_dimension( 55, 'in' ); wc_get_dimension( 55, 'in', 'm' );
Хуков нет.
Возвращает
float.
Использование
wc_get_dimension( $dimension, $to_unit, $from_unit );
- $dimension(число/float) (обязательный)
- Dimension.
- $to_unit(строка) (обязательный)
- Unit to convert to. Options: 'in', 'm', 'cm', 'm'.
- $from_unit(строка)
- Unit to convert from. Options: 'in', 'm', 'cm', 'm'.
По умолчанию: ''
Код wc_get_dimension() wc get dimension WC 5.0.0
function wc_get_dimension( $dimension, $to_unit, $from_unit = '' ) {
$to_unit = strtolower( $to_unit );
if ( empty( $from_unit ) ) {
$from_unit = strtolower( get_option( 'woocommerce_dimension_unit' ) );
}
// Unify all units to cm first.
if ( $from_unit !== $to_unit ) {
switch ( $from_unit ) {
case 'in':
$dimension *= 2.54;
break;
case 'm':
$dimension *= 100;
break;
case 'mm':
$dimension *= 0.1;
break;
case 'yd':
$dimension *= 91.44;
break;
}
// Output desired unit.
switch ( $to_unit ) {
case 'in':
$dimension *= 0.3937;
break;
case 'm':
$dimension *= 0.01;
break;
case 'mm':
$dimension *= 10;
break;
case 'yd':
$dimension *= 0.010936133;
break;
}
}
return ( $dimension < 0 ) ? 0 : $dimension;
}