From d5571ce521adf7cfbd85c3b2b980b410a2b6fbce Mon Sep 17 00:00:00 2001 From: Stas Demin Date: Thu, 26 Dec 2024 12:53:12 +0300 Subject: [PATCH 1/2] fix: factory no recreate class object --- src/ShippingMethod.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ShippingMethod.php b/src/ShippingMethod.php index f7ddaf7..bbb8875 100644 --- a/src/ShippingMethod.php +++ b/src/ShippingMethod.php @@ -66,6 +66,7 @@ class ShippingMethod extends WC_Shipping_Method { use SettingsFields; + private static ?ShippingMethod $instance = null; private const DEFAULTS = [ 'automate_wait_gateways' => [], @@ -85,6 +86,7 @@ public function __construct($instance_id = 0) ]; $this->enabled = 'yes'; $this->init(); + static::$instance = $this; } final public function init(): void @@ -114,7 +116,7 @@ public static function factory(?int $instanceId = null): self } } - return WC()->shipping()->load_shipping_methods()[Config::DELIVERY_NAME]; + return static::$instance ?? WC()->shipping()->load_shipping_methods()[Config::DELIVERY_NAME]; } /** @noinspection MissingReturnTypeInspection */ From ef7f6ad076d76bbde9baa99515b9dfbfac493c92 Mon Sep 17 00:00:00 2001 From: Stas Demin Date: Thu, 26 Dec 2024 12:57:37 +0300 Subject: [PATCH 2/2] fix: ternary operator changes --- src/ShippingMethod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShippingMethod.php b/src/ShippingMethod.php index bbb8875..7bb0337 100644 --- a/src/ShippingMethod.php +++ b/src/ShippingMethod.php @@ -116,7 +116,7 @@ public static function factory(?int $instanceId = null): self } } - return static::$instance ?? WC()->shipping()->load_shipping_methods()[Config::DELIVERY_NAME]; + return static::$instance ?: WC()->shipping()->load_shipping_methods()[Config::DELIVERY_NAME]; } /** @noinspection MissingReturnTypeInspection */