Show shipping class in admin product list

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.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)