1

In WooCommerce I would like to change cm to ft my products display in height, width and length,

You can see the products with their title below:

enter image description here

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

2 Answers2

2

Try the following code that will change the displayed dimensions unit in front end:

add_filter( 'woocommerce_format_dimensions', 'custom_dimention_unit', 20, 2 );
function custom_dimention_unit( $dimension_string, $dimensions ){
    $dimension_string = implode( ' x ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) );

    if ( ! empty( $dimension_string ) ) {
        $dimension_string .= ' ' . __('ft');
    } else {
        $dimension_string = __( 'N/A', 'woocommerce' );
    }

    return $dimension_string;
}

Code goes in function.php file of your active child theme (or active theme).


Update: Make dimension unit "ft" (feet) globally (everywhere)

Woocommerce dimension available units are "m", "cm", "mm", "in" and "yd".

But "ft" is not available in the Woocommerce > Settings > Products > Mesurements section.

What you can do is the following:

  1. Paste the following line in your function.php file and save:

     update_option( 'woocommerce_dimension_unit', 'ft' );
    
  2. Browse any page of your web site.

  3. Remove or comment the line of code from your function.php file and save.

  4. You can also remove the first code snippet as it's not needed anymore.

  5. You are done.

You will get something like:

enter image description here

And in backend:

enter image description here


For info, to change the dimensions unit in Woocommerce > Settings > Products:

enter image description here

Community
  • 1
  • 1
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
0

Modify WooCommerce settings field to add a new dimension unit to the list.

Add the following codes to your functions.php

add_filter( 'woocommerce_product_settings', 'add_custom_dimension_unit', 20, 1 );
function add_custom_dimension_unit( $settings ){

            foreach( $settings as $key => $field ) {
                if( $field['id'] == 'woocommerce_dimension_unit' ) {
                    $field['options']['ft'] = __( 'ft', 'woocommerce' );
                    $settings[ $key ] = $field;
                    break;
                }
            }

            return $settings;
        }

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
oneTarek
  • 21
  • 4