Add WooCommerce product shipping class name to cart

/*
 * Add this to your (child) theme's functions.php file
 */
add_filter( 'woocommerce_cart_item_name', 'add_product_shipping_class', PHP_INT_MAX, 3 );
/*
 * add_product_shipping_class.
 */
function add_product_shipping_class( $cart_item_name, $cart_item, $cart_item_key ) {
	$product_id = ( 0 != $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'];
	$product_shipping_classes = get_the_terms( $product_id, 'product_shipping_class' );
	$product_shipping_class_name = ( $product_shipping_classes && ! is_wp_error( $product_shipping_classes ) ) ? current( $product_shipping_classes )->name : '';
	return $cart_item_name . ' ' . $product_shipping_class_name;
}

No comments yet.

Leave a Reply