How to Display All Products With No Weight WooCommerce

WooCommerce Display All Products With No WeightDo you want to display all the all products with no weight in your WooCommerce store? In today’s tutorial, we will show you how to do this without going through all the products in your store.

If you sell physical goods, weight is one of the most important aspects you need to look at. This is because it affects the shipping price. Heavy products should have a relatively higher shipping rate than the other products.

In addition, customers in your store need to know the weight of the products to make a well-informed purchase. This allows them to buy the product they were looking for.

By default, WooCommerce allows you to add the product weight when adding products in the back end. This is a very convenient feature because you can use this information to create favorable shipping rates.

If you have few products, it will be very easy for you to know the products that do not have weight. However, if you have many products, this can be very hard. This is why we decided to create a custom-made solution for you.

WooCommerce Display All Products With No Weight

By the end of this tutorial, you will be able to display all the products with no weight on the view products page. In this post, we will be using a custom code snippet we specifically made to edit some of WooCommerce’s core files to get the desired result.

Therefore, you should install or create a child theme. This will ensure that your changes will not be lost during an update.

With that in mind, let us get right into it.

Steps to Display All Products With No Weight

Here are the simple steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to display all products with no weight.
  3. Add the following code to the functions.php file:
[php] add_action( ‘admin_notices’, ‘njengah_products_no_weight_admin’ );
function njengah_products_no_weight_admin(){
global $pagenow, $typenow;
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>’;
}
}
[/php]
  1. This is the outcome:product weigh

Wrapping Up

In summary, we have shared a solution to display all the products with no weight on the view product page. The code snippet also adds a link that directs you to the product edit page, where you can add the product’s weight.

However, you should have a complete backup of your site before editing WooCommerce’s core files. This will ensure that you can revert to the previous version if an error occurs.

We hope that this post provided a solution for you.

Similar Articles