I also would have liked to do the same but only came across the following which displays the Shipping Class on the Checkout Page which may help:
https://stackoverflow.com/questions/48353893/add-shipping-class-below-each-product-in-woocommerce-shopping-cart-page
I found this option worked the best:
add_filter( ‘woocommerce_cart_item_name’, ‘shipping_class_in_item_name’, 20, 3);
function shipping_class_in_item_name( $item_name, $cart_item, $cart_item_key ) {
// Only in cart page (remove the line below to allow the display in checkout too)
//if( ! ( is_cart() || is_checkout() ) ) return $item_name;
$product = $cart_item[‘data’]; // Get the WC_Product object instance
$shipping_class_id = $product->get_shipping_class_id(); // Shipping class ID
$shipping_class_term = get_term( $shipping_class_id, ‘product_shipping_class’ );
if( empty( $shipping_class_id ) )
return $item_name; // Return default product title (in case of)
$label = __( ‘Shipping class’, ‘woocommerce’ );
return $item_name . ‘<br>
<p class=”item-shipping_class” style=”margin:12px 0 0;”>
‘ .$label . ‘: ‘ . $shipping_class_term->name . ‘</p>’;
}
—
The following line is commented out using // so that the Shipping Class displays on both the Cart and Checkout page. You may want to remove // so that the Shipping Class is displayed only on the Cart Page
if( ! ( is_cart() || is_checkout() ) ) return $item_name;
—
I used Code Snippets to add this code which works fine.
Hope this helps
-
This reply was modified 6 years, 8 months ago by
aristocats.