WC_Admin_Reports::delete_legacy_reports_transients
Execute legacy reports transient deletion (sync or async depending on the context)
Method of the class: WC_Admin_Reports{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Admin_Reports::delete_legacy_reports_transients( $order_id, $defer ): void;
- $order_id(int) (required)
- Order ID (unused, exists for compatibility between the hooks we are integrating with).
- $defer(true|false)
- Whether to defer the deletion or execute.
Default:true
Changelog
| Since 10.6.0 | Introduced. |
WC_Admin_Reports::delete_legacy_reports_transients() WC Admin Reports::delete legacy reports transients code WC 10.7.0
public static function delete_legacy_reports_transients( int $order_id, bool $defer = true ): void {
// Deferring is only making sense on sites without object cache enabled (if enabled, no SQLs being executed).
if ( $defer && ! wp_using_ext_object_cache() ) {
static $skip_consequent;
// Schedule the deletion, cap the execution to single pending event at any given time.
$schedule = ! $skip_consequent && ! as_has_scheduled_action( 'woocommerce_delete_legacy_report_transients', null, 'woocommerce' );
if ( $schedule ) {
as_schedule_single_action( time() + MINUTE_IN_SECONDS, 'woocommerce_delete_legacy_report_transients', array( $order_id, false ), 'woocommerce' );
}
$skip_consequent = true;
return;
}
delete_transient( 'wc_admin_report' );
foreach ( self::get_reports() as $report_group ) {
foreach ( $report_group['reports'] as $report_key => $report ) {
delete_transient( 'wc_report_' . $report_key );
}
}
}