Skip to content
Advertisement

Display product weight in KG when it’s over 1000 grams on Product Page

There is a similar question here: How to display the product weight in kg, if more than 1000 grams

But the code the user provides adds a new paragraph with the weight on every product description and thumbnail and leaves the weight in grams on the Aditional Information tab.

Is there a way to change the weight where it usually appears, the Product Page additional information tab?

Advertisement

Answer

Here is the solution, hope someone find this useful:

function woocommerce_format_weight( $weight_string, $weight ) { 

     if ( $weight >= 1000 ) {
            $weight_string = wc_format_localized_decimal($weight / 1000);
            $weight_string .= ' Kg';
        }
    return $weight_string; 
}; 

add_filter( 'woocommerce_format_weight', 'soltronic_woocommerce_format_weight', 10, 2 );
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement