Automattic\WooCommerce\Internal\StockNotifications
Telemetry{}
Tracker snapshot for the customer stock notifications feature.
Хуков нет.
Использование
$Telemetry = new Telemetry(); // use class methods
Методы
- public __construct()
- public add_snapshot_to_tracker_data( $data )
- public static collect_snapshot()
- ERROR: no method name found on line `}`
- ERROR: no method name found on line `* @return array<string, mixed>`
- private static get_notification_counts()
- private static get_settings()
- ERROR: no method name found on line ``
- ERROR: no method name found on line ``
- ERROR: no method name found on line `* can pass a different value along the filter chain.`
Код Telemetry{} Telemetry{} WC 11.2.2
class Telemetry {
/**
* Constructor.
*/
public function __construct() {
add_filter( 'woocommerce_tracker_data', array( $this, 'add_snapshot_to_tracker_data' ), 10, 1 );
}
/**
* Append the stock notifications snapshot to WC_Tracker's payload.
*
* Params are untyped and coerced in the body because any third-party callback
* can pass a different value along the filter chain.
*
* @internal
*
* @param mixed $data The aggregated tracker data.
* @return mixed
*/
public function add_snapshot_to_tracker_data( $data ) {
if ( ! is_array( $data ) ) {
return $data;
}
$data['customer_stock_notifications'] = self::collect_snapshot();
return $data;
}
/**
* Collect the stock notifications snapshot fields.
*
* @return array<string, mixed>
*/
public static function collect_snapshot(): array {
return array(
'settings' => self::get_settings(),
'notifications' => self::get_notification_counts(),
);
}
/**
* The feature's settings, as merchants configured them.
*
* @return array<string, mixed>
*/
private static function get_settings(): array {
return array(
'allow_signups' => Config::allows_signups() ? 'yes' : 'no',
'require_double_opt_in' => Config::requires_double_opt_in() ? 'yes' : 'no',
'require_account' => Config::requires_account() ? 'yes' : 'no',
'unverified_deletions_days_threshold' => Config::get_unverified_deletion_days_threshold(),
'hide_out_of_stock_items' => get_option( 'woocommerce_hide_out_of_stock_items', 'no' ),
);
}
/**
* The number of notifications in total and per status.
*
* @return array<string, int>
*/
private static function get_notification_counts(): array {
$counts_by_status = wc_get_container()->get( StockNotificationsDataStore::class )->count_by_status();
$counts = array( 'total' => array_sum( $counts_by_status ) );
foreach ( NotificationStatus::get_valid_statuses() as $status ) {
$counts[ $status ] = $counts_by_status[ $status ] ?? 0;
}
return $counts;
}
}