Find WooCommerce products without a shipping class

Shipping classes are used to group similar products together to provide different flat-rate shipping costs to each group. In a recent project, we grouped about a thousand products into three shipping classes; 500g satchel, 1kg satchel, or bulky parcel.

The size of the inventory practically guaranteed that a few products would be missed. When we compared the number of products in each shipping class with the total size of the inventory, it was immediately obvious that a few dozen products hadn’t been assigned a shipping class, but WooCommerce provided no immediately obvious way of identifying them.

This little plugin was put together to quickly generate a list of all published products that don’t have a shipping class assigned.

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

<?php

/**
* Plugin Name: Find Products Without Shipping Class
* Description: Adds a page that lists all products without a shipping class
* Author: Shane Gowland
* License: GPL
* License URI: https://gowland.me
*/
function register_shipping_class_checker_page() {
    add_submenu_page( 'edit.php?post_type=product', 'Missing Shipping Classes', 'No Shipping Class', 'manage_options', 'missing_shipping_classes_page', 'missing_shipping_classes_page_callback' );
}
function missing_shipping_classes_page_callback() {  ?>

<div class="wrap">
  <h1>Missing Shipping Classes</h1>

<p>The products listed below do not have a Shipping Class assigned.</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);
        $shipclass = $_product->get_shipping_class();

    //Output the product
    if (strlen($shipclass) == 0) {
        echo '<br /> '.get_the_title(). ' — <a target="_blank" href="' . get_edit_post_link($post->ID) . '">Edit Product</a>';
    $products_found++;
    }

    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_shipping_class_checker_page',99);

Once all of the products have been identified and corrected, you can remove the plugin — or just leave it installed for next time.

4 thoughts on “Find WooCommerce products without a shipping class”

  1. Hello im use this awesome code script in my website and its working just fine! i wanted to ask if this can be used to get products that does not have weight? thank you in advance

    Reply
  2. Hello!

    I placed your code directly into the Snippets plugin instead of creating an extra plugin, and it works flawlessly. In 1500 products, I knew I had exactly 4 products without shipping class (how is that come, I don’t know, I’ve set all the products inside that categeory already).

    Now I can keep an eye on that.

    Many thanks!

    Cheers

    Reply

Leave a Reply