Automattic\WooCommerce\Admin\API

Experiments::get_assignment()publicWC 1.0

Forward the experiment request to WP.com and return the WP.com response.

{} Это метод класса: Experiments{}

Хуков нет.

Возвращает

\WP_Error|\WP_REST_Response.

Использование

$Experiments = new Experiments();
$Experiments->get_assignment( $request );
$request(\WP_REST_Request) (обязательный)
Request data.

Код Experiments::get_assignment() WC 6.6.1

public function get_assignment( $request ) {
	$args = $request->get_query_params();

	if ( ! isset( $args['experiment_name'] ) ) {
		return new \WP_Error(
			'woocommerce_rest_experiment_name_required',
			__( 'Sorry, experiment_name is required.', 'woocommerce' ),
			array( 'status' => 400 )
		);
	}

	unset( $args['rest_route'] );

	$abtest   = new \WooCommerce\Admin\Experimental_Abtest(
		$request->get_param( 'anon_id' ) ?? '',
		'woocommerce',
		true, // set consent to true here since frontend has checked it already.
		true  // set true to send request as auth user.
	);
	$response = $abtest->request_assignment( $args );
	if ( is_wp_error( $response ) ) {
		return $response;
	}

	return json_decode( $response['body'], true );
}