Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds a custom "league" unit to WooCommerce
/**
* This adds the new unit to the WooCommerce admin
*/
function add_woocommerce_dimension_unit_league( $settings ) {
foreach ( $settings as &$setting ) {
if ( 'woocommerce_dimension_unit' == $setting['id'] ) {
$setting['options']['league'] = __( 'league' ); // new unit
}
}
return $settings;
}
add_filter( 'woocommerce_products_general_settings', 'add_woocommerce_dimension_unit_league' );
@matteoraggi

This comment has been minimized.

Copy link

@matteoraggi matteoraggi commented Feb 12, 2016

In which folder of woocommerce 2.5.2 or of the plugin woocommerce-measurement-price-calculator I should insert the file wc-measurement-price-calculator-custom-unit.php ?

@tdonovic

This comment has been minimized.

Copy link

@tdonovic tdonovic commented Sep 15, 2017

Im a bit confused, with Matteoraggi with this one. I've tried putting it in theme function.php and that didn't seem to work

@YourBassHertz

This comment has been minimized.

Copy link

@YourBassHertz YourBassHertz commented Feb 11, 2018

So, I ran into the same problem mentioned above. I followed example listed on the woocommerce development site (https://docs.woocommerce.com/document/woocommerce-measurement-price-calculator-developer-documentation/), but to no avail. However, when I forced it into the array by calling the $key as well, that made all the difference.

foreach ( $settings as $key => $setting ) {
     if ( 'woocommerce_measurement_unit' == $setting['id'] ) {
         $settings[$key]['options']['league'] = __( 'league' );  // new unit
     }
}

I'm a bit confused why this is the case because there are plenty of times that I can remember where I've looped through the array and set the new value using the 'current instance' of the loop, but I guess not this time. I'm not sure if it's a php version difference, but in any case, this worked for me. I hope this helps!

@onebook0505

This comment has been minimized.

Copy link

@onebook0505 onebook0505 commented Apr 3, 2019

Hi @bekarice,why woocommerce_area_unit is not working?

in measurement tab, if not enabled Calculated Price,how can i show the product dimensions in the cart?

WooCommerce version 3.5.7
WooCommerce Measurement Price Calculator version 3.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment