WooCommerce\Admin

Experimental_Abtest::request_assignment()publicWC 1.0

Perform the request for a experiment assignment of a provided A/B test from WP.com.

Method of the class: Experimental_Abtest{}

No Hooks.

Return

Array|\WP_Error. A/B test variation error on failure.

Usage

$Experimental_Abtest = new Experimental_Abtest();
$Experimental_Abtest->request_assignment( $args );
$args(array) (required)
Arguments to pass to the request for A/B test.

Experimental_Abtest::request_assignment() code WC 8.7.0

public function request_assignment( $args ) {
	// Request as authenticated wp user.
	if ( $this->as_auth_wpcom_user && class_exists( Jetpack_Connection_Manager::class ) ) {
		$jetpack_connection_manager = new Jetpack_Connection_Manager();
		if ( $jetpack_connection_manager->is_user_connected() ) {
			$response = Jetpack_Connection_client::wpcom_json_api_request_as_user(
				'/experiments/0.1.0/assignments/' . $this->platform,
				'2',
				$args
			);
		}
	}

	// Request as anonymous user.
	if ( ! isset( $response ) ) {
		if ( ! isset( $args['anon_id'] ) || empty( $args['anon_id'] ) ) {
			return new \WP_Error( 'invalid_anon_id', 'anon_id must be an none empty string.' );
		}

		$url      = add_query_arg(
			$args,
			sprintf(
				'https://public-api.wordpress.com/wpcom/v2/experiments/0.1.0/assignments/%s',
				$this->platform
			)
		);
		$response = wp_remote_get( $url );
	}

	return $response;
}