Stats::DEFAULT_SALE_STATUSES, ]; } /** * {@inheritDoc} */ public function settingsSchema(): array { return [ 'sale_statuses' => [ 'type' => 'text', 'label' => __( 'وضعیت‌های فروش', 'rahkar-toolkit' ), 'help' => __( 'سفارشی که یکی از این وضعیت‌ها را دارد خرید شمرده می‌شود. با ویرگول جدا کنید، بی پیشوند wc-. باید با «وضعیت‌های فروش» داشبورد راهکار فروش یکی باشد؛ داشبورد اگر نباشد هشدار می‌دهد. عوض کردنش همه‌ی شاخص‌ها را از نو می‌سازد.', 'rahkar-toolkit' ), 'default' => Stats::DEFAULT_SALE_STATUSES, 'section' => 'general', ], ]; } /** * {@inheritDoc} */ public function settingsSections(): array { return [ 'general' => __( 'عمومی', 'rahkar-toolkit' ) ]; } /** * {@inheritDoc} */ public function register(): void { add_action( Hooks::CUSTOMER_STATS_FILL, static fn() => Plugin::make( StatsFill::class )->run() ); // The first fill starts on its own, after any queue run, so a store that // switched the module on and never opened a screen still gets one. add_action( 'rahkar_wp_queue_ran', static fn() => StatsFill::ensure() ); // Other sale statuses change which orders count: every row starts over. add_action( 'update_option_' . Settings::PREFIX . self::SLUG, static function ( $old, $new ): void { $before = is_array( $old ) ? (string) ( $old['sale_statuses'] ?? '' ) : ''; $after = is_array( $new ) ? (string) ( $new['sale_statuses'] ?? '' ) : ''; if ( $before !== $after ) { StatsFill::restart(); } }, 10, 2 ); add_action( 'woocommerce_after_order_object_save', static fn( $order ) => Plugin::make( StatsWatcher::class )->saved( $order ), 30 ); add_action( 'woocommerce_after_order_refund_object_save', static fn( $refund ) => Plugin::make( StatsWatcher::class )->saved( $refund ), 30 ); add_action( 'woocommerce_trash_order', static fn( $id ) => Plugin::make( StatsWatcher::class )->changed( $id ), 30 ); add_action( 'woocommerce_delete_order', static fn( $id ) => Plugin::make( StatsWatcher::class )->changed( $id ), 30 ); add_action( 'woocommerce_untrash_order', static fn( $id ) => Plugin::make( StatsWatcher::class )->changed( $id ), 30 ); } }