true ) ); } $settings_repo = new Siti_Stock_Settings( self::OPTION_KEY ); Siti_Stock_Sync_Controller::maybe_schedule_from_settings( self::CRON_HOOK, $settings_repo->get_all() ); } /** * Plugin deactivation callback. */ public static function deactivate() { Siti_Stock_Sync_Controller::clear_schedule( self::CRON_HOOK ); } private function __construct() { $this->settings = new Siti_Stock_Settings( self::OPTION_KEY ); $this->notices = new Siti_Stock_Admin_Notices(); $this->sync_controller = new Siti_Stock_Sync_Controller( $this->settings, $this->notices, self::CRON_HOOK ); $this->inventory_manager = new Siti_Stock_Inventory_Manager( self::EXTERNAL_STOCK_META_KEY ); $this->admin = new Siti_Stock_Admin( $this->settings, $this->sync_controller, $this->notices ); $this->admin->register_hooks(); $this->inventory_manager->register_hooks(); $this->sync_controller->register_hooks(); add_filter( 'woocommerce_data_stores', array( $this, 'override_product_data_store' ), 20 ); } /** * Ensure WooCommerce uses the custom data store so reservations see combined stock. * * @param array $stores Registered data store map. * @return array */ public function override_product_data_store( $stores ) { if ( isset( $stores['product'] ) && $this->ensure_product_data_store_loaded() ) { $is_cpt_store = is_a( $stores['product'], 'WC_Product_Data_Store_CPT', true ); if ( $is_cpt_store ) { $stores['product'] = 'Siti_Stock_Product_Data_Store'; } } return $stores; } /** * Load the custom product data store once WooCommerce base classes exist. * * @return bool */ private function ensure_product_data_store_loaded() { if ( class_exists( 'Siti_Stock_Product_Data_Store' ) ) { return true; } if ( ! class_exists( 'WC_Product_Data_Store_CPT' ) ) { return false; } require_once __DIR__ . '/class-siti-stock-product-data-store.php'; return class_exists( 'Siti_Stock_Product_Data_Store' ); } }