set_title( __( 'WooPayments: Fix incorrect order data', 'woocommerce-payments' ) ); $note->set_content( __( 'Some orders with canceled payment authorizations have incorrect data that may cause negative values in your WooCommerce Analytics. This affects stores using manual capture (authorize and capture separately). Run the fix tool to correct this.', 'woocommerce-payments' ) ); $note->set_content_data( (object) [] ); $note->set_type( Note::E_WC_ADMIN_NOTE_WARNING ); $note->set_name( self::NOTE_NAME ); $note->set_source( 'woocommerce-payments' ); $note->add_action( 'run-remediation-tool', __( 'Go to Tools page', 'woocommerce-payments' ), admin_url( self::NOTE_TOOLS_URL ), 'actioned', false ); return $note; } /** * Check if there are orders that need remediation. * * Uses a state machine backed by an option to avoid running the expensive * query inline. On the first call, schedules an async Action Scheduler job * and returns false. The note will be added on a subsequent admin_init * once the async check completes. * * @return bool */ private static function has_affected_orders() { $state = get_option( WC_Payments_Remediate_Canceled_Auth_Fees::CHECK_STATE_OPTION_KEY ); if ( false === $state ) { self::schedule_check(); return false; } if ( 'has_affected_orders' === $state ) { return true; } // 'scheduled', 'no_affected_orders', or any unexpected value. return false; } /** * Schedule the async affected orders check via Action Scheduler. * * @return void */ private static function schedule_check() { if ( ! function_exists( 'as_schedule_single_action' ) ) { return; } update_option( WC_Payments_Remediate_Canceled_Auth_Fees::CHECK_STATE_OPTION_KEY, 'scheduled', true ); as_schedule_single_action( time() + 10, WC_Payments_Remediate_Canceled_Auth_Fees::CHECK_AFFECTED_ORDERS_HOOK, [], 'woocommerce-payments' ); } /** * Check if remediation is currently running. * * @return bool */ private static function is_remediation_running() { if ( ! function_exists( 'as_has_scheduled_action' ) ) { return false; } return as_has_scheduled_action( WC_Payments_Remediate_Canceled_Auth_Fees::ACTION_HOOK ); } }