wordpresswoocommercecode-snippetsadd-filter

Woo-commerce Changing the default weight unit text from kg to kiloGrams and display kilograms in product page and in additional information


Hey I'm trying to change the weight unit text from kg to kiloGrams in additional information at product page but the code is working for Description string to change but not for working for kg text can't figure out why.

would be really great if anyone could suggest. Thanks.

add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 999, 3 );

function bbloomer_translate_woocommerce_strings( $translated, $untranslated, $domain ) {

   if ( ! is_admin() && 'woocommerce' === $domain ) {

      switch ( $translated) {

         case 'g' :

            $translated = 'grams';
            break;

         case 'Description' :

            $translated = 'Product Specifications';
            break;

         // ETC

      }

   }   

   return $translated;

}

Solution

  • // To update the units in woocommerce from g to grams or another

    update_option( 'woocommerce_weight_unit', 'grams' );