Search code examples
phpwordpresswoocommerceproductdimensions

Product formatted dimensions display "×" instead of "x" in Woocommerce 3


I have such a problem with woocommerce plugin. Since last upgrade of woocommerce to last version I can see "×" instad "x" in dimension section in variant product. So I can see for ex. "&15times;15×15cm" instead "15 x 15 x 15cm".

Official support recommends me to disable every plugin (try to plugin conflict) and activate storefront theme. I trie both of theese solvings and still no success (this means that problem could be in original woocommerce plugin). You can watch screenshot of this issue here: enter link description here

Thanks for help


Solution

  • You can use the following function hooked in woocommerce_format_dimensions filter hook to make the changes that you need this way (in the last line):

    add_filter( 'woocommerce_format_dimensions', 'change_formated_product_dimentions', 10, 2 );
    function change_formated_product_dimentions( $dimension_string, $dimensions ){
        if ( empty( $dimension_string ) )
            return __( 'N/A', 'woocommerce' );
    
        $dimensions = array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) );
    
        return implode( ' x ',  $dimensions ) . get_option( 'woocommerce_dimension_unit' );
    }
    

    Code goes in function.php file of the active child theme (or active theme). Tested and works.