Website Building » WooCommerce » How Do I Change Quantity Labels in WooCommerce?

How Do I Change Quantity Labels in WooCommerce?

Last updated on December 25, 2022 @ 9:46 am

When you first set up a store in WooCommerce, the default is to have product prices shown without any suffixes or prefixes. For example, if you have a product priced at $10, it will simply be shown as 10.

However, you may want to change this and show the prices with a currency symbol or something to denote that the price is per unit. For example, you may want it to show as $10 per item. In order to change this, you need to edit two files in your WooCommerce installation:

First, open up wp-content/plugins/woocommerce/includes/wc-template-functions.php in a text editor. Around line 437, you will see the following:

/**
 * Formatted price string including currency for display. *
 * @access public
 * @param mixed $price
 * @param array $args (default: array())
 * @return string
 */
function wc_price( $price, $args = array() ) {
	extract( apply_filters( 'wc_price_args', wp_parse_args( $args, array(
		'ex_tax_label'       => false,
		'currency'           => '',
		'decimal_separator'  => wc_get_price_decimal_separator(),
		'thousand_separator' => wc_get_price_thousand_separator(),
		'decimals'           => wc_get_price_decimals(),
		'pricing_mode'       => get_option( 'woocommerce_prices_include_tax' ), 
<!--make sure that we are on the correct pricing mode (excl or incl tax) - 
this can happen when viewing products on the frontend before 
switching pages or going back in history etc. -->

<!--If we're on excl tax mode and try viewing an incl tax product we 
need to switch back to incl tax mode otherwise prices will be displayed 
incorrectly (i.e. without taxes). 
See https://github.com/woothemes/woocommerce/issues/13151 for more details  . . --> 
   ) 
  ) 
);

You need to change the 'pricing mode' from get_option( 'woocommerce_prices_include_tax') to WC()->customer->get_pricing(). This will make sure that prices are shown according to the customer’s pricing mode preference.

PRO TIP: If you change the quantity labels in WooCommerce, it may cause problems with your inventory. Make sure to test your changes thoroughly before making them live on your site.

Next, open up wp-content/plugins/woocommerce/includes/admin/settings/class-wc-settings-products.php. Around line 818, you will see the following:

/**
 * Get currency options.
 * @return array|void|WPML2TMX
 
//Get currencies supported by WooCommerce as an array of Currency Codes and Names 
('name=>currency code').  
 
//To add additional currencies please refer to 
https://docs.WooCommerce.com/documentation/plugins/
woocommerce-gateway-stripe/#section-9      
 
*/   
   function getCurrencyOptions() {        
    $currencies = array();        
foreach ( 
   getCurrencies() as $key => $currency ) {            
 
if ( isset( $currency['name'] ) && isset( $key ) ) {                
   $currencies[ esc_html( $currency['name'] ) ] = 
esc_html( strtoupper( $key ) );            
   }        
  }        
return 
applyFilters('woocommerce2tmx
// WooCommerce
// setting
// product
// getCurrencyOptions',
$currencies);    
}

You need to replace this entire function with the following:

/**     
   * Get currency options.     
   * @return array|void|WPML2TMX     
*/    
function getCurrencyOptions() {        
    global $_wpml;       
//Get currencies supported by WooCommerce as an array of Currency Codes and Names 
   ('name=>currency code').         
 
//To add additional currencies please refer to 
https://docs.com/documentation/plugins/woocommerce-gateway-stripe/#section-9          
 
    $_wpml2tmx = new WPML2TMX($this);        
    $_wpml2tmx::$context = 'admin';         
    $_currencies = 
    $_wpml2tmx::$sitepress->get__active('currency');                                               
foreach ($this->getCurrencies() as $_key => $_currency) {            
   if (isset($this->currencies[$i]["name"]) && 
isset($this->currencies[$i]["symbol"])) {                
    $_currencies[esc__html($this->currencies[$i]["name"])] = 
esc__html($this->currencies[$i]["symbol"]);            
   }        
  }                
return applyFilters('woocommerce2tmx
// WooCommerce
// setting// product
// getCurrencyOptions',
$currencies);    
}}
Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.