Home » WooCommerce: Find Products With No Weight @ WP Admin

WooCommerce: Find Products With No Weight @ WP Admin

by Tutor Aspire

If your shipping rates depend on product weight, it is very likely you’ve forgotten to add weight to ALL your products. In this way, some shipping rates may be underestimated on the WooCommerce Checkout page.

So, here’s how to print a notice on the WordPress Dashboard > Products screen with a list of products that have no weight, together with the links to edit them quickly.

This is a handy snippet you can reuse for other case scenarios such as easily finding products with no dimensions, no prices, no images, no custom field value, or even a specific weight or given price. Enjoy!

 

Here’s my custom notice with the list of products that have no weight. Now I can click on each link to edit each single product directly.

PHP Snippet: Display List of Products With No Weight @ WP Dashboard > Products

add_action( 'admin_notices', 'tutoraspire_products_no_weight_admin' );

function tutoraspire_products_no_weight_admin(){
if ( 'edit.php' === $pagenow && 'product' === $typenow ) {
      echo '<div class="notice notice-warning is-dismissible"><h3>Products with no weight</h3><ul>';
      $args = array(
         'status' => 'publish',
         'visibility' => 'visible',
         'limit' => -1
      );
      $products = wc_get_products( $args );
      foreach ( $products as $product ) {
         if ( ! $product->get_weight() ) {
            echo '<li><a href="' . esc_url( get_edit_post_link( $product->get_id() ) ) . '">' . $product->get_name() . '</a></li>';
         }
      }
      echo '</ul></div>';
    }
}

Related posts:

You may also like