تابع ووکامرسی wc_get_dimension تبدیل اندازه ابعاد سانتی متر به واحد مورد نظر

تابع ووکامرسی wc_get_dimension تبدیل اندازه ابعاد سانتی متر به واحد مورد نظر

تابع ووکامرسی wc_get_dimension – تبدیل اندازه ابعاد سانتی متر به واحد مورد نظر

Syntax – سینتکس

(float) wc_get_dimension( (int|float) $dimension, (string) $to_unit, (string) $from_unit = '' ); 

Parameters – پارامتر ها (3)

  • 1- $dimension (int|float)
  • 2- $to_unit (string)
  • 3- $from_unit (string)

Usage – نحوه استفاده

if ( !function_exists( 'wc_get_dimension' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
} 
  
// The dimension. 
$dimension = null; 
  
// 'in', 'm', 'cm', 'm' 
$to_unit = ''; 
  
// (optional) 'in', 'm', 'cm', 'm' 
$from_unit = ''; 
  
// NOTICE! Understand what this does before running. 
$result = wc_get_dimension($dimension, $to_unit, $from_unit); 
    

Defined – محل تعریف

/includes/wc-formatting-functions.php

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; 
} 

versions – نسخه ها

از نسخه : 3.0.2

نسخه فعلی : 3.0.6

دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

ارسال نظر

جهت استفاده از کد حتما از تگ pre استفاده نمایید .

contact us