PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 9, 2022

[FIXED] How to set a non existing dimensions measurement unit in Woocommerce 3

 May 09, 2022     dimensions, php, product, woocommerce, wordpress     No comments   

Issue

In WooCommerce I would like to change cm to ft my products display in height, width and length,

You can see the products with their title below:

enter image description here


Solution

Try the following code that will change the displayed dimensions unit in front end:

add_filter( 'woocommerce_format_dimensions', 'custom_dimention_unit', 20, 2 );
function custom_dimention_unit( $dimension_string, $dimensions ){
    $dimension_string = implode( ' x ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) );

    if ( ! empty( $dimension_string ) ) {
        $dimension_string .= ' ' . __('ft');
    } else {
        $dimension_string = __( 'N/A', 'woocommerce' );
    }

    return $dimension_string;
}

Code goes in function.php file of your active child theme (or active theme).


Update: Make dimension unit "ft" (feet) globally (everywhere)

Woocommerce dimension available units are "m", "cm", "mm", "in" and "yd".

But "ft" is not available in the Woocommerce > Settings > Products > Mesurements section.

What you can do is the following:

  1. Paste the following line in your function.php file and save:

     update_option( 'woocommerce_dimension_unit', 'ft' );
    
  2. Browse any page of your web site.

  3. Remove or comment the line of code from your function.php file and save.

  4. You can also remove the first code snippet as it's not needed anymore.

  5. You are done.

You will get something like:

enter image description here

And in backend:

enter image description here


For info, to change the dimensions unit in Woocommerce > Settings > Products:

enter image description here



Answered By - LoicTheAztec
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing