Find WooCommerce products with missing weight information

Having accurate product weight information is essential for the proper functioning of most shipping rate calculation plugins.

If a product is missing a weight value, it can cause shipping to be undercharged. In some circumstances, a product without weight information can’t be purchased at all.

Unfortunately, WooCommerce doesn’t provide an easy way to quickly identify all products that don’t have a weight, so I’ve put together this helpful little plugin. It finds all the weightless products in your store and prints them in a list.

Installation is easy: Just save the below code to a .php file and upload it to /wp-content/mu-plugins/, then No Product Weight should appear under Products in the WordPress dashboard. Check out ā€˜How to create a must use pluginā€˜ if you run into trouble.

You can also use the Code Snippets plugin to install the code, which is handy if you don’t have access to the filesystem.

<?php
 
/**
* Plugin Name: Find Products Without Weight 
* Description: Adds a page that lists all products without weight information
* Author: Shane Gowland
* License: GPL
* License URI: https://shanegowland.com
*/
function register_missing_weight_checker_page() {
    add_submenu_page( 'edit.php?post_type=product', 'Missing Weight Information', 'No Product Weight', 'manage_options', 'missing_weight_classes_page', 'missing_weight_classes_page_callback' );
}
function missing_weight_classes_page_callback() {  ?>
 
<div class="wrap">
  <h1>Missing Weight Information</h1>
 
<p>The products listed below do not have weight information provided.</p>
 
<?php
 
$args = array(
    'post_type' => 'product',
    'posts_per_page' => -1,
    'post_status' => 'publish'
 );
 
    $loop = new WP_Query( $args );
    global $post;
    global $product;
     
    //Count how many products were found so we can give zero-results feedback
    $products_found = 0;
     
    while ( $loop->have_posts() ) : $loop->the_post();
   
        $_product = wc_get_product($post->ID);
        $prod_weight = $_product->get_weight();
 
 
    if ( $_product->has_weight() == false ) {
        echo '<br /> '.get_the_title(). ' ā€” <a target="_blank" href="' . get_edit_post_link($post->ID) . '">Edit Product</a>';   
        $products_found = $products_found + 1;
    }

    endwhile;
    wp_reset_query();
     
    //Output something if the number of results is zero
    if ($products_found == 0) {
        echo "No products were found.";
    }
?>
 
</div>
 
<?php }
add_action('admin_menu', 'register_missing_weight_checker_page',99);

Once all of the products have been found and corrected, you can remove the plugin. Or just leave it installed for next time!

Shane Gowland

Hi! Iā€™m a web designer, software developer, and digital marketer based in South Australia. I've been building websites on WordPress for over 12 years. You can learn more about the projects and businesses I'm involved with on my website.

Leave a Reply