With the use of complex shipping class configurations in WooCommerce it can be really convenient to be able to see those settings in the Woo Products Bulk Editor as an additional column. Even better you may want to toggle visibility on and off via the Screen Options tab. This snippet shows one approach that can be adapted to display other Woo product data as well. You can drop this into your functions.php, custom plugin, or a Code Snippet plugin. Just don’t add to opening PHP tag if redundant with your existing PHP code.
<?php
/* === CONFIGURE THESE FOR YOUR PROJECT ===
* This is optional but allows us to share generic code that is not specific to a particular site's text domain/prefix
* If not used you would need to manually update all of the instances below where it calls for MY_TEXT_DOMAIN and MY_PREFIX
*/
if ( ! defined( 'MY_PREFIX' ) ) define( 'MY_PREFIX', 'mytheme' ); // Change 'mytheme' to your prefix
if ( ! defined( 'MY_TEXT_DOMAIN' ) ) define( 'MY_TEXT_DOMAIN', 'mytheme' ); // Change 'mytheme' to your text domain
/* === End text domain configuration === */
/* Custom product shipping class column, toggle via Screen Options */
add_filter('manage_edit-product_columns', function($columns){
$columns[MY_PREFIX . '_shipping_class'] = __('Shipping Class', MY_TEXT_DOMAIN);
return $columns;
}, 20);
/* This is where the database is queried for product data to display in the custom column */
add_action('manage_product_posts_custom_column', function($column, $post_id){
if ( $column !== MY_PREFIX . '_shipping_class' ) return;
$product = wc_get_product($post_id);
if ( ! $product ) { echo '—'; return; }
$class_id = $product->get_shipping_class_id();
if ( ! $class_id ) { echo '—'; return; }
$term = get_term($class_id, 'product_shipping_class');
echo $term && ! is_wp_error($term) ? esc_html($term->name) : '—';
}, 10, 2);
/* Make new column sortable */
add_filter('manage_edit-product_sortable_columns', function($columns){
$columns[MY_PREFIX . '_shipping_class'] = MY_PREFIX . '_shipping_class';
return $columns;
});
/* Retrieve the product's shipping class term from the database for display in the custom column */
add_action('pre_get_posts', function($query){
if ( ! is_admin() || ! $query->is_main_query() ) return;
if ( $query->get('post_type') !== 'product' ) return;
if ( $query->get('orderby') !== MY_PREFIX . '_shipping_class' ) return;
// Join term relationships to sort by shipping class name
$query->set('orderby', 'title'); // fallback simple order; full taxonomy sort requires heavier joins
});