diff --git a/src/Migration/Pdk/SettingsMigration.php b/src/Migration/Pdk/SettingsMigration.php index d2974a4c8..6c10e2ae6 100644 --- a/src/Migration/Pdk/SettingsMigration.php +++ b/src/Migration/Pdk/SettingsMigration.php @@ -194,20 +194,20 @@ private function convertShippingMethodId(string $shippingMethod, Collection $wcS if ($termId) { $match = $wcShippingMethods - ->filter(function ($shippingMethod) use ($termId, $shippingMethodName) { - return $shippingMethod->id === $shippingMethodName && (int) $shippingMethod->instance_id === (int) $termId; + ->filter(function ($wcShippingMethod) use ($termId, $shippingMethodName) { + return $wcShippingMethod->id === $shippingMethodName && (int) $wcShippingMethod->instance_id === (int) $termId; }) ->first(); if (! $match) { /** @var WP_Term|null $foundShippingClass */ $foundShippingClass = $wcShippingMethods - ->filter(function ($shippingMethod) use ($termId) { - if (! $shippingMethod instanceof WP_Term) { + ->filter(function ($wcShippingMethod) use ($termId) { + if (! $wcShippingMethod instanceof WP_Term) { return false; } - return $shippingMethod->term_id === (int) $termId; + return $wcShippingMethod->term_id === (int) $termId; }) ->first(); diff --git a/src/Pdk/Plugin/WcShippingMethodRepository.php b/src/Pdk/Plugin/WcShippingMethodRepository.php index 83f777388..b51c85e4c 100644 --- a/src/Pdk/Plugin/WcShippingMethodRepository.php +++ b/src/Pdk/Plugin/WcShippingMethodRepository.php @@ -33,7 +33,6 @@ public function __construct(WcShippingRepositoryInterface $wcShippingRepository) */ public function all(): PdkShippingMethodCollection { - // The "0" zone is the "Rest of the World" zone in WooCommerce. $wcShippingMethods = $this->wcShippingRepository->getShippingMethods(); $wcShippingClasses = $this->wcShippingRepository->getShippingClasses(); @@ -78,10 +77,11 @@ public function createFromWcShippingClass(WP_Term $shippingClass): PdkShippingMe */ private function createFromWcShippingMethod(WC_Shipping_Method $method): PdkShippingMethod { + $id = $method->get_rate_id(); return new PdkShippingMethod([ - 'id' => $method->get_rate_id(), + 'id' => $id, 'name' => $this->getShippingMethodTitle($method), - 'description' => "ID: {$method->get_rate_id()}", + 'description' => "ID: $id", 'isEnabled' => 'yes' === $method->enabled && ! $method instanceof WC_Shipping_Local_Pickup, ]); } diff --git a/tests/mock_wp_functions.php b/tests/mock_wp_functions.php index e3fee4b07..143fd9a49 100644 --- a/tests/mock_wp_functions.php +++ b/tests/mock_wp_functions.php @@ -201,7 +201,7 @@ function get_term_by($field, $value, $taxonomy = '', $output = 'OBJECT', $filter * * @return false|mixed|\WP_Term */ -function get_term($term, $taxonomy = '', $output = OBJECT, $filter = 'raw') +function get_term($term, $taxonomy = '', $output = 'OBJECT', $filter = 'raw') { if ($term instanceof WP_Term) { return MockWpTerm::get_instance($term->term_id, $taxonomy);