*/ private array $module_keys = [ 'sidecart' => [ 'key' => 'enable_reactsidecart', 'section' => 'sidecart_general_tabs', 'default' => 'off', ], 'cartrecovery' => [ 'key' => 'enable_cart_recovery', 'section' => 'cart_recovery_settings_tabs', 'default' => 'off', ], 'orderbumps' => [ 'key' => 'enable_orderbumps', 'section' => 'orderbumps_general_tabs', 'default' => 'off', ], 'cartgate' => [ 'key' => 'enable_cartgate', 'section' => 'cartgate_general_tabs', 'default' => 'off', ], 'localpickup' => [ 'key' => 'enable_localpickup', 'section' => 'localpickup_general_tabs', 'default' => 'off', ], 'cart_page' => [ 'key' => 'enable_cart_page', 'section' => 'cart_page_settings_tabs', 'default' => 'off', ], 'thankyou' => [ 'key' => 'enable_thankyou', 'section' => 'thankyou_general_tabs', 'default' => 'off', ], 'checkout' => [ 'key' => 'enable_checkout', 'section' => 'checkout_settings_tabs', 'default' => 'off', ], 'checkoutgate' => [ 'key' => 'enable_checkoutgate', 'section' => 'checkoutgate_general_tabs', 'default' => 'off', ], ]; public static function instance(): self { return self::$instance ??= new self(); } public function is_enabled( string $module ): bool { if ( ! $this->is_available( $module ) ) { return false; } $config = $this->module_keys[ $module ] ?? null; if ( ! is_array( $config ) ) { return false; } $value = function_exists( 'wooordercart_get_option' ) ? wooordercart_get_option( $config['key'], $config['section'], $config['default'] ) : $config['default']; return $this->normalize_bool( $value ); } /** * @return array */ public function all(): array { $flags = []; foreach ( array_keys( $this->module_keys ) as $module ) { $flags[ $module ] = $this->is_enabled( $module ); } return $flags; } public function any_frontend_module_enabled(): bool { foreach ( [ 'sidecart', 'orderbumps', 'cartgate', 'localpickup', 'cart_page', 'thankyou', 'checkout', 'checkoutgate' ] as $module ) { if ( $this->is_enabled( $module ) ) { return true; } } return false; } public function has_checkout_support_features_enabled(): bool { return $this->is_enabled( 'cartgate' ) || $this->is_enabled( 'checkoutgate' ) || $this->is_enabled( 'localpickup' ); } public function should_boot_modern_checkout_support(): bool { return $this->is_enabled( 'checkout' ) || $this->is_enabled( 'cartgate' ) || $this->is_enabled( 'checkoutgate' ); } public function should_boot_ajax_server_check(): bool { return $this->is_enabled( 'sidecart' ) || $this->is_enabled( 'checkout' ) || $this->is_enabled( 'cartgate' ) || $this->is_enabled( 'checkoutgate' ); } public function has_manage_screen( string $module ): bool { // Configuration stays accessible while storefront execution is disabled. return $this->is_available( $module ) && in_array( $module, [ 'orderbumps', 'cartgate', 'localpickup', 'checkoutgate' ], true ); } private function is_available( string $module ): bool { $features = [ 'cartrecovery' => 'abandoned_cart_recovery', 'orderbumps' => 'order_bumps', 'checkoutgate' => 'checkout_gate' ]; return ! isset( $features[ $module ] ) || \WooOrderCart\Cart\CartFeatureRegistry::instance()->is_enabled( $features[ $module ] ); } /** * @param mixed $value */ private function normalize_bool( $value ): bool { return in_array( $value, [ true, 1, '1', 'on', 'yes' ], true ); } }