Skip to content

Commit

Permalink
Fix: Fixe for delivery date plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fean committed Jan 31, 2022
1 parent c53f4e9 commit 0937417
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion includes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ public static function getShippingRates(array $orderDetails, bool $includeAll =

$rates = json_decode($response['body']);
// For now only take the first one
return empty($rates) ? $rates : $includeAll ? $rates : [$rates[0]];
return empty($rates)
? $rates
: ($includeAll ? $rates : [$rates[0]]);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions includes/wc-internal/trunkrs-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,23 @@ private function getTychePluginMeta()
$meta = TRUNKRS_WC_Utils::findInArray(
$this->order->get_meta_data(),
function ($metaItem) {
$startsWithPrefix = substr($metaItem['key'], 0, strlen(self::TYCHE_DELIVERY_DATE_PREFIX)) === self::TYCHE_DELIVERY_DATE_PREFIX;
$endsWithPostFix = substr($metaItem['key'], -strlen(self::TYCHE_DELIVERY_DATE_TIMESTAMP_POSTFIX)) === self::TYCHE_DELIVERY_DATE_TIMESTAMP_POSTFIX;
$data = $metaItem->get_data();
$startsWithPrefix = substr($data['key'], 0, strlen(self::TYCHE_DELIVERY_DATE_PREFIX)) === self::TYCHE_DELIVERY_DATE_PREFIX;
$endsWithPostFix = substr($data['key'], -strlen(self::TYCHE_DELIVERY_DATE_TIMESTAMP_POSTFIX)) === self::TYCHE_DELIVERY_DATE_TIMESTAMP_POSTFIX;

return $startsWithPrefix && $endsWithPostFix;
}
);

return $meta;
return is_null($meta) ? null : $meta->get_data();
}

private function getDeliveryDate($item)
{
$deliveryDatePlugin = $this->getTychePluginMeta();

if (isset($deliveryDatePlugin)) {
$parsed = DateTime::createFromFormat('U', $deliveryDatePlugin);
$parsed = DateTime::createFromFormat('U', $deliveryDatePlugin['value']);
if ($parsed === false) return $item->get_meta(self::DELIVERY_DATE_KEY);
return TRUNKRS_WC_Utils::format8601Date($parsed);
}
Expand Down

0 comments on commit 0937417

Please sign in to comment.