How can i display product attribute name in WooCommerce cart page

foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) :
	$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
	$attributes = $_product->get_attributes();
	if ( !empty( $attributes ) ) {
		$attr_arr = [];
		foreach( $attributes as $attr => $attr_val ) {

			if ( isset( $attributes[ $attr ] ) || isset( $attributes[ 'pa_' . $attr ] ) ) {

				$term_name = $_product->get_attribute( $attr );

				$term = get_term_by( 'name', $term_name, $attr );

				if ( !empty( $term ) ) {
					$attr_arr[] = $term->name;
				}

			}
		}
	}

	if ( !empty( $attr_arr )) {
		echo implode( ',', $attr_arr );
	}

endforeach;

Leave a Reply

Your email address will not be published. Required fields are marked *