Search code examples
javascriptphpwordpresswoocommercehook-woocommerce

WooCommerce: How to change the label name Dimensions?


WooCommerce has a default attribute in the products data table called dimensions which takes values entered as LxBxH. I would like to change the label name dimensions to packaging dimensions in the front end as well as if possible in the back end. What code has to be entered in functions.php in order to achieve the same?

enter image description here


Solution

  • function woo_replace_string($translation, $text, $domain) {
    
        $search_string = 'Dimensions';
        if (strpos($translation, $search_string) !== false) {
    
            $translation = str_replace($search_string, 'Packaging Dimensions', $translation);
        }
        return $translation;
    }
    
    add_filter('gettext_woocommerce', 'woo_replace_string', 20, 3);
    

    Use gettext_{$domain} hook for this. See the doc here