I’d like to change the product meta label from “Weight” to “Square Feet” in both the back end and front end.
I’ve tried this and a few [hundred] variations without success:
add_filter( 'woocommerce_register_post_type_product', 'custom_product_labels' );
function custom_product_labels( $args ) {
//
// change labels in $args['labels'] array
//
$args['labels']['_weight'] = 'Square Feet';
return $args;
I’ve successfully edited the UNITs with this:
add_filter( 'woocommerce_product_settings', 'add_woocommerce_dimension_units' );
function add_woocommerce_dimension_units( $settings ) {
foreach ( $settings as &$setting ) {
if ( $setting['id'] == 'woocommerce_dimension_unit' ) {
$setting['options']['feet'] = __( 'ft' ); // foot
}
if ( $setting['id'] == 'woocommerce_weight_unit' ) {
$setting['options']['sq ft'] = __( 'sq ft' ); // square feet
}
}
return $settings;
}
But I still can’t figure out how to hook into the measurement labels to edit them. It’s important to note that I don’t want to ADD a meta unit of “Square Feet” because we already have thousands of products filled in with the sq ft data in the Weight field.
My quick workaround was to find the actual code on these pages and edit them. But it’s a poor solution.
woocommerce/includes/admin/meta-boxes/views/html-product-data-shipping.php
woocommerce/includes/wc-formatting-functions.php
woocommerce/includes/wc-template-functions.php
Edit: Here is a page showing the use.
https://homedesigningservice.com/product/cape-house-plan-10034-cp/
Thank you in advance for saving my melting brain. 🙂
2
Answers
You may use this snippet
Woo has a filter for front end but no filter for backend label changing.. So use below code and it won’t conflict with any other label… Lakshman’s gettext will change weight anywhere in the site…