diff --git a/modules.local/ppcp-wc-gateway/services.php b/modules.local/ppcp-wc-gateway/services.php index 1076d5561..0cc8f2ad5 100644 --- a/modules.local/ppcp-wc-gateway/services.php +++ b/modules.local/ppcp-wc-gateway/services.php @@ -62,11 +62,12 @@ return [ $settings = $container->get('wcgateway.settings'); $fields = $container->get('wcgateway.settings.fields'); $webhookRegistrar = $container->get('webhook.registrar'); + $state = $container->get('onboarding.state'); global $wpdb; $cacheFactory = new CachePoolFactory($wpdb); $pool = $cacheFactory->createCachePool('ppcp-token'); - return new SettingsListener($settings, $fields, $webhookRegistrar, $pool); + return new SettingsListener($settings, $fields, $webhookRegistrar, $pool, $state); }, 'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor { diff --git a/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php index 15806b653..d8a92d9bb 100644 --- a/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ b/modules.local/ppcp-wc-gateway/src/Settings/SettingsListener.php @@ -17,17 +17,20 @@ class SettingsListener private $settingFields; private $webhookRegistrar; private $cache; + private $state; public function __construct( Settings $settings, array $settingFields, WebhookRegistrar $webhookRegistrar, - CacheInterface $cache + CacheInterface $cache, + State $state ) { $this->settings = $settings; $this->settingFields = $settingFields; $this->webhookRegistrar = $webhookRegistrar; $this->cache = $cache; + $this->state = $state; } public function listen() @@ -73,6 +76,9 @@ class SettingsListener { $settings = []; foreach ($this->settingFields as $key => $config) { + if (! in_array($this->state->currentState(), $config['screens'], true)) { + continue; + } switch ($config['type']) { case 'checkbox': $settings[$key] = isset($rawData[$key]);