Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flistefliste/03850acea5391e71bf11 to your computer and use it in GitHub Desktop.
Save flistefliste/03850acea5391e71bf11 to your computer and use it in GitHub Desktop.
Prepend "0" to product weight in WooCommerce when product weight notation is ie. ".19 kg" instead of "0.19 kg"
<?php
//prepend "0" to product weight in WooCommerce
add_filter( 'woocommerce_product_get_weight', 'prepend_zero' ,100, 1 );
if(!function_exists('prepend_zero')){
function prepend_zero($weight){
//check if first char is a dot "."
if (substr($weight, 0, 1) === '.'){
$weight = "0".$weight ;
}
return $weight ;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment