Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bekarice/13acd0241a6ab8b64364 to your computer and use it in GitHub Desktop.
Save bekarice/13acd0241a6ab8b64364 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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
Copy link

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
Copy link

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