Automattic\WooCommerce\StoreApi\Routes\V1\Ucp

AbstractCatalogRoute::get_context │ protected │ WC 1.0

Extract the recognized context fields from a request.

Method of the class: AbstractCatalogRoute{}

No Hooks.

Returns

array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_context( $request ): array;
$request(WP_REST_Request) (required)
Request object.

AbstractCatalogRoute::get_context() code WC 11.3.0

protected function get_context( \WP_REST_Request $request ): array {
	$raw = $request->get_param( 'context' );

	if ( ! is_array( $raw ) ) {
		return array();
	}

	$context = array();

	foreach ( array( 'address_country', 'address_region', 'postal_code', 'intent', 'language', 'currency' ) as $key ) {
		if ( isset( $raw[ $key ] ) && is_scalar( $raw[ $key ] ) && '' !== (string) $raw[ $key ] ) {
			$context[ $key ] = (string) $raw[ $key ];
		}
	}

	return $context;
}