Skip to content

Instantly share code, notes, and snippets.

@varun-pluginhive
Last active September 14, 2018 06:40
Show Gist options
  • Save varun-pluginhive/068bb9aa5b54e79973255b571d0ab629 to your computer and use it in GitHub Desktop.
Save varun-pluginhive/068bb9aa5b54e79973255b571d0ab629 to your computer and use it in GitHub Desktop.
Snippet to convert the dimension in FedEx plugin. WOOCOMMERCE FEDEX SHIPPING PLUGIN WITH PRINT LABEL - https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
/**
* Snippet to convert the dimension in FedEx plugin.
* Created at : 14 Sep 2018
* Updated at : 14 Sep 2018
* Xadapter Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/varun-pluginhive/068bb9aa5b54e79973255b571d0ab629
*/
if( ! function_exists('ph_fedex_convert_dimension') ) {
function ph_fedex_convert_dimension( $converted_dimension, $dimension, $to_unit, $from_unit ) {
if( empty($from_unit) ) $from_unit = get_option( 'woocommerce_dimension_unit' );
$from_unit = strtolower($from_unit);
$to_unit = strtolower($to_unit);
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;
case 'ft' :
$dimension *= 30.48;
break;
}
switch( $to_unit ) {
case 'in' :
$converted_dimension = $dimension * 0.3937;
break;
case 'cm' :
$converted_dimension = $dimension;
break;
}
}
return $converted_dimension;
}
add_filter( 'ph_fedex_get_converted_dimension', 'ph_fedex_convert_dimension', 10, 4 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment