Automattic\WooCommerce\Blocks\Domain\Services

CheckoutLink::parse_product_data │ protected │ WC 11.2.0

Parse a semicolon-separated list of key-value pairs.

Method of the class: CheckoutLink{}

No Hooks.

Returns

array<string, string>. Sanitized product data.

Usage

// protected - for code of main (parent) or child class
$result = $this->parse_product_data( $raw_data );
$raw_data(string) (required)
Raw product data from the checkout link.

Changelog

Since 11.2.0 Introduced.

CheckoutLink::parse_product_data() code WC 11.3.0

protected function parse_product_data( $raw_data ) {
	$data = [];

	foreach ( $this->split_escaped( $raw_data, ';' ) as $pair ) {
		if ( false === strpos( $pair, '=' ) ) {
			continue;
		}

		list( $key, $value ) = explode( '=', $pair, 2 );
		$key                 = sanitize_key( $key );

		if ( '' !== $key ) {
			$data[ $key ] = sanitize_text_field( $value );
		}
	}

	return $data;
}