Skip to content

Commit

Permalink
Load payment fields after setup theme for translations
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jan 20, 2025
1 parent a38af39 commit 0b2383e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Gateway/MolliePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public function __construct(
);
$this->supports = $this->paymentMethod->getProperty('supports');

// Load the settings.
$this->init_form_fields();
// Load the settings when translations are ready
add_action('after_setup_theme', [$this, 'init_form_fields']);

$this->init_settings();
$this->title = $this->paymentMethod->title();

Expand Down
18 changes: 18 additions & 0 deletions src/PaymentMethods/AbstractPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ abstract class AbstractPaymentMethod implements PaymentMethodI
* @var array
*/
private $apiPaymentMethod;
/**
* @var bool
*/
protected bool $translationsInitialized = false;

public function __construct(
Expand All @@ -63,6 +66,7 @@ public function __construct(
$this->settings = $this->getSettings();
$this->apiPaymentMethod = $apiPaymentMethod;
add_action('after_setup_theme', [$this, 'initializeTranslations']);
add_action('after_setup_theme', [$this, 'updateSettingsWithDefaults']);
}

public function title(): string
Expand Down Expand Up @@ -225,6 +229,20 @@ public function getProcessedDescriptionForBlock(): string
* @return array
*/
public function getSettings(): array
{
$optionName = 'mollie_wc_gateway_' . $this->id . '_settings';
$settings = get_option($optionName, false);
if (!$settings) {
$settings = [];
}
return $settings;
}

/**
* Update the payment method's settings with defaults if not exist
* @return array
*/
public function updateSettingsWithDefaults(): array
{
$optionName = 'mollie_wc_gateway_' . $this->id . '_settings';
$settings = get_option($optionName, false);
Expand Down

0 comments on commit 0b2383e

Please sign in to comment.