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.

Leave a Reply