0

I'm looking for a way to show the Shipping Class of a product in the product admin overview to be able to quickly check if the right shipping class was selected for a product.

Can you help?

1 Answer 1

3

You can add a new column to the product admin overview that displays the shipping class of each product. Here's how you can do it:

  1. Add the following code to your theme's functions.php file or a custom plugin:

     // Add new 'Shipping Class' column to the product admin overview
     add_filter( 'manage_edit-product_columns', 'show_product_shipping_class_column' );
     function show_product_shipping_class_column( $columns ) {
         $columns['shipping_class'] = __( 'Shipping Class', 'woocommerce' );
         return $columns;
     }
    
     // Populate 'Shipping Class' column with the product's shipping class
     add_action( 'manage_product_posts_custom_column', 'populate_product_shipping_class_column', 10, 2 );
     function populate_product_shipping_class_column( $column, $postid ) {
         if ( $column == 'shipping_class' ) {
             $_product = wc_get_product( $postid );
             $shipping_class = $_product->get_shipping_class();
    
             if ( ! empty( $shipping_class ) ) {
                 echo $shipping_class;
             } else {
                 echo '<span class="na">–</span>';
             }
         }
     }
    
     // Make 'Shipping Class' column sortable
     add_filter( 'manage_edit-product_sortable_columns', 'sortable_product_shipping_class_column' );
     function sortable_product_shipping_class_column( $columns ) {
         $columns['shipping_class'] = 'shipping_class';
         return $columns;
     }
    

This code does three things:

  • It adds a new 'Shipping Class' column to the product admin overview.
  • It populates this column with the shipping class of each product.
  • It makes the 'Shipping Class' column sortable.

Now, when you go to the product admin overview, you should see a new 'Shipping Class' column that displays the shipping class of each product. You can click on the column header to sort the products by their shipping class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.