How to Return a Default Weight for Products in Woocommerce shop?


Depending on the theme, if the product-item weight is not specified, it may be incorrectly displayed or hidden. However, if you want to assign a default weight, you can add the following filter in your child theme’s functions template.

This is particular useful if you take the product weight in shipping costs. If it is zero weight, then bang, you have a bug: you can put as many items as possible in the shipping box!

1
2
3
4
5
6
7
8
9
function woocommerce_product_get_weight_filter($weight) {
  $default_weight = 0.1; // 100g 
  if ((!is_numeric($weight)) || ($weight <= 0.001)) {
    return $default_weight;
  }
  return $weight;
}
 
add_filter('woocommerce_product_get_weight', 'woocommerce_product_get_weight_filter');
function woocommerce_product_get_weight_filter($weight) {
  $default_weight = 0.1; // 100g 
  if ((!is_numeric($weight)) || ($weight <= 0.001)) {
    return $default_weight;
  }
  return $weight;
}

add_filter('woocommerce_product_get_weight', 'woocommerce_product_get_weight_filter');

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
153 words
Last Post: How to Add a Clear-Cart Button in Woocommerce?
Next Post: How to Change the SwapFile Size at Linux?

The Permanent URL is: How to Return a Default Weight for Products in Woocommerce shop?

Leave a Reply