php - Get label name from product WooCommerce shipping class Id

one text

Solution:

Final update

Use the following to get the term name (label name) from a product shipping class Id:

$term_id   = (int) $product->get_shipping_class_id(); // Get the shipping class Id
$term_name = ''; // Initializing

if( $term_id > 0 ) {
    $term = get_term( $term_id, 'product_shipping_class' );
    if( is_a( $term, 'WP_Term') ) {
        $term_name = $term->name;
    }
} 

// testing output
echo '<h6>'. $term_name .'</h6>';

So in your code replace the line

$carousel_items .= '<h6>'.$product->get_shipping_class_id().'</h6></div>';

by the following code block:

$shipping_class_id   = (int) $product->get_shipping_class_id(); // Get shipping class Id
$shipping_class_name = ''; // Initializing
if ( $shipping_class_id > 0 ) {
    $shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' ); // Get the WP_Term Object
    if ( is_a( $shipping_class_term, 'WP_Term') ) {
        $shipping_class_name = $shipping_class_term->name; // The label name (term name)
    }
}
$carousel_items .= '<h6>'.$shipping_class_name.'</h6></div>'; // Add to output

Tested and works.

Source