Get WooCommerce product shipping class name

/**
 * Returns the product shipping class name.
 *
 * @return string
 */
function get_shipping_class_name( $product_id ) {
	$classes = get_the_terms( $product_id, 'product_shipping_class' );
	return ( $classes && ! is_wp_error( $classes ) ) ? current( $classes )->name : '';
}

You can add this snippet to your (child) theme's functions.php file.

No comments yet.

Leave a Reply