The following Query can be run once in your functions.php file. This will remove all the varation weights from your woocommerce install, and allow your products to use the default weight that is set by the product.

  1. $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_type, $wpdb->postmeta.meta_id, $wpdb->postmeta.meta_key, $wpdb->postmeta.meta_value
  2. FROM `$wpdb->posts`, `$wpdb->postmeta`
  3. WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
  4. AND `post_type` = 'product_variation'
  5. AND `meta_key` = '_weight'";
  6.  
  7. $results = $wpdb->get_results($querystr, OBJECT);
  8.  
  9. foreach ( $results as $result ) {
  10.   $metaid = $result->meta_id;
  11.   $table = "aus_postmeta";
  12.   $data = array('meta_value' => '');
  13.   $where = array('meta_key' => '_weight', 'meta_id' => $metaid);
  14.   $wpdb->update( $table, $data, $where );
  15. }

One comment on “Remove variation weights from Woocommerce”

  • Mike Lavdanitis

    hello, im trying to delete all weights data from variation products on my store but the code is not working, please can you give an advice or how to make it work, i have woocommerce 3.5.7 version. thank you in advance

Leave a Reply

Your email address will not be published. Required fields are marked *