From 5b1b32f566e120d475c259c4c50ccd8e43e7a1d9 Mon Sep 17 00:00:00 2001 From: Michael Yick Date: Tue, 2 Jul 2024 22:36:44 -0500 Subject: [PATCH] Only throw an error if there's no shipping rates Changed so that error detection is based on a lack of shipping rates rather than the presence of an error message. --- pirateship-live-rates/pirateship-live-rates.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pirateship-live-rates/pirateship-live-rates.php b/pirateship-live-rates/pirateship-live-rates.php index 312af29..840be85 100644 --- a/pirateship-live-rates/pirateship-live-rates.php +++ b/pirateship-live-rates/pirateship-live-rates.php @@ -116,11 +116,11 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_ $weight = 0; $cost = 0; + foreach ($package['contents'] as $item_id => $values) { - - + #print($values["data"]); $_product = $values['data']; - $weight = $weight + $_product->get_weight() * $values['quantity']; + $weight = $weight + ((int) $_product->get_weight() * $values['quantity']); //TODO: Fix this so that shipping is per-item type rather than bulking everything together. $width = $_product->get_width(); $length = $_product->get_length(); @@ -140,7 +140,6 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_ $apiURL = 'https://ship.pirateship.com/api/graphql?opname=GetRates' ; //GraphQL statement codified in JSON for the incoming query - $JSONQuery = json_encode( array( "operationName" => "GetRates", @@ -198,12 +197,13 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_ #print($JSONQuery); #print($resp); + #error_log($resp); #print(implode(',', array_keys($resp["body"]))); $prices = json_decode($resp, True); - if (array_key_exists("errors", $prices)){ + if (empty($prices["data"]["rates"])){ $option = array( 'id' => "Fallback Price", 'label' => "Fallback Price - Failed to get shipping rate. Refresh page and report problem to Site Administrator if problem persists.",