WC_Tracker::send_tracking_data
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 Tracker::send tracking data WC 11.2.1
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_attempt = max( (int) self::get_last_send_time(), (int) get_option( 'woocommerce_tracker_last_attempt', 0 ) );
if ( $last_attempt > strtotime( '-1 hours' ) ) {
return;
}
}
// Recorded before building the snapshot so overlapping override sends are still suppressed.
update_option( 'woocommerce_tracker_last_attempt', time(), false );
// Count the attempt before the snapshot is built. A fatal or timeout inside
// get_tracking_data() never reaches record_send_result(), so a counter that only
// moved on delivery outcomes would let an unbuildable snapshot rebuild on every
// scheduled run instead of giving up the way a failed delivery does.
$attempts = (int) get_option( 'woocommerce_tracker_send_failures', 0 ) + 1;
if ( self::MAX_CONSECUTIVE_SEND_FAILURES < $attempts ) {
self::finish_snapshot();
wc_get_logger()->warning(
'WooCommerce tracker snapshot attempts ended before recording a result; giving up until the next interval.',
array(
'source' => 'woocommerce-tracker',
'failures' => $attempts - 1,
)
);
return;
}
update_option( 'woocommerce_tracker_send_failures', $attempts, false );
$body = wp_json_encode( self::get_tracking_data() );
if ( false === $body ) {
self::record_send_failure( false, 0, 'json_encode_failure', 0 );
return;
}
$response = wp_safe_remote_post(
self::$api_url,
array(
'method' => 'POST',
'timeout' => 10,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array( 'user-agent' => 'WooCommerceTracker/' . md5( esc_url_raw( home_url( '/' ) ) ) . ';' ),
'body' => $body,
'cookies' => array(),
)
);
self::record_send_result( $response, strlen( $body ) );
}