WC_Tracker::send_tracking_data()public staticWC 1.0

Decide whether to send tracking data or not.

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

Возвращает

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

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

$result = WC_Tracker::send_tracking_data( $override );
$override(true|false)
Should override?.
По умолчанию: false

Код WC_Tracker::send_tracking_data() WC 8.7.0

public static function send_tracking_data( $override = false ) {
	// Don't trigger this on AJAX Requests.
	if ( Constants::is_true( 'DOING_AJAX' ) ) {
		return;
	}

	/**
	 * Filter whether to send tracking data or not.
	 *
	 * @since 2.3.0
	 */
	if ( ! apply_filters( 'woocommerce_tracker_send_override', $override ) ) {
		// Send a maximum of once per week by default.
		$last_send = self::get_last_send_time();
		if ( $last_send && $last_send > apply_filters( 'woocommerce_tracker_last_send_interval', strtotime( '-1 week' ) ) ) { // phpcs:ignore
			return;
		}
	} else {
		// Make sure there is at least a 1 hour delay between override sends, we don't want duplicate calls due to double clicking links.
		$last_send = self::get_last_send_time();
		if ( $last_send && $last_send > strtotime( '-1 hours' ) ) {
			return;
		}
	}

	// Update time first before sending to ensure it is set.
	update_option( 'woocommerce_tracker_last_send', time() );

	$params = self::get_tracking_data();
	wp_safe_remote_post(
		self::$api_url,
		array(
			'method'      => 'POST',
			'timeout'     => 45,
			'redirection' => 5,
			'httpversion' => '1.0',
			'blocking'    => false,
			'headers'     => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ),
			'body'        => wp_json_encode( $params ),
			'cookies'     => array(),
		)
	);
}