WC_REST_Telemetry_Controller::record_usage_data()publicWC 1.0

Record WCTracker Data

Метод класса: WC_REST_Telemetry_Controller{}

Хуков нет.

Возвращает

null. Ничего (null).

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

$WC_REST_Telemetry_Controller = new WC_REST_Telemetry_Controller();
$WC_REST_Telemetry_Controller->record_usage_data( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код WC_REST_Telemetry_Controller::record_usage_data() WC 9.3.1

public function record_usage_data( $request ) {
	$new = $this->get_usage_data( $request );
	if ( ! $new || ! $new['platform'] ) {
		return;
	}

	$data = get_option( 'woocommerce_mobile_app_usage' );
	if ( ! $data ) {
		$data = array();
	}

	$platform = $new['platform'];

	if ( isset( $data[ $platform ] ) ) {
		$existing_usage = $data[ $platform ];

		// Sets the installation date only if it has not been set before.
		if ( isset( $new['installation_date'] ) && ! isset( $existing_usage['installation_date'] ) ) {
			$data[ $platform ]['installation_date'] = $new['installation_date'];
		}

		if ( version_compare( $new['version'], $existing_usage['version'], '>=' ) ) {
			$data[ $platform ]['version']   = $new['version'];
			$data[ $platform ]['last_used'] = $new['last_used'];
		}
	} else {
		// Only sets `first_used` when the platform usage data hasn't been set before.
		$new['first_used'] = $new['last_used'];
		$data[ $platform ] = $new;
	}

	update_option( 'woocommerce_mobile_app_usage', $data );
}