Automattic\WooCommerce\StoreApi\Schemas\V1

CartItemSchema::get_item_data │ protected │ WC 1.0

Format cart item data removing any HTML tag.

Method of the class: CartItemSchema{}

Hooks from the method

Returns

array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_item_data( $cart_item );
$cart_item(array) (required)
Cart item array.

CartItemSchema::get_item_data() code WC 11.2.1

protected function get_item_data( $cart_item ) {
	/**
	 * Filters cart item data.
	 *
	 * Allows extensions to attach their own name/value pairs to a cart item, which the Store
	 * API returns in the item's `item_data` field.
	 *
	 * Set `raw_key` so clients can find your entry without matching a translated label.
	 * Data you do not intend to display belongs in your `extensions` namespace.
	 *
	 * @since 4.3.0
	 *
	 * @internal Matches filter name in WooCommerce core.
	 *
	 * @param array $item_data Cart item data. Empty by default.
	 * @param array $cart_item Cart item array.
	 * @return array
	 */
	$item_data       = apply_filters( 'woocommerce_get_item_data', array(), $cart_item );
	$clean_item_data = [];
	foreach ( $item_data as $data ) {
		// A non-scalar value would fatal in wp_strip_all_tags, so drop the whole entry.
		foreach ( $data as $data_value ) {
			if ( ! is_scalar( $data_value ) ) {
				continue 2;
			}
		}
		$clean_item_data[] = $this->format_item_data_element( $data );
	}
	return $clean_item_data;
}