Forums / Addon Shipping Modules / UK shipping by postcode error logs

UK shipping by postcode error logs

Results 1 to 3 of 3
15 May 2025, 12:09
#1
richard7315 avatar

richard7315

New Zenner

Join Date:
Jul 2017
Posts:
50
Plugin Contributions:
1

UK shipping by postcode error logs

Hi,
I have installed the UK shipping by postcode module (on ZenCart 2.1.0 using PHP 8.3).

When viewing the shopping cart, a couple of PHP logs are generated due to the delivery postcode not being available/entered yet. The shipping estimator successfully displays at the bottom of the page, but the following logs are generated:

--> PHP Warning: Undefined array key "postcode" in ……../includes/modules/shipping/ukpost.php on line 178.


--> PHP Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in ……../includes/modules/shipping/ukpost.php on line 179.



Please see below lines 178 and 179 of ukpost.php

        $destination_postcode = $order->delivery['postcode'];
  	  $pcode = preg_replace('/\s\s*/', '', $destination_postcode);



The errors are only generated if a postcode has not been entered. Any help with this issue would be much appreciated.
Rick
15 May 2025, 14:48
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: UK shipping by postcode error logs

richard7315:

Hi,
I have installed the UK shipping by postcode module (on ZenCart 2.1.0 using PHP 8.3).

When viewing the shopping cart, a couple of PHP logs are generated due to the delivery postcode not being available/entered yet. The shipping estimator successfully displays at the bottom of the page, but the following logs are generated:

--> PHP Warning: Undefined array key "postcode" in ……../includes/modules/shipping/ukpost.php on line 178.


--> PHP Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in ……../includes/modules/shipping/ukpost.php on line 179.



Please see below lines 178 and 179 of ukpost.php

        $destination_postcode = $order->delivery['postcode'];
        $pcode = preg_replace('/\s\s*/', '', $destination_postcode);



The errors are only generated if a postcode has not been entered. Any help with this issue would be much appreciated.
Rick

Make the highlighted change to line 178:
        $destination_postcode = $order->delivery['postcode'] ?? '';
        $pcode = preg_replace('/\s\s*/', '', $destination_postcode);
16 May 2025, 09:43
#3
richard7315 avatar

richard7315

New Zenner

Join Date:
Jul 2017
Posts:
50
Plugin Contributions:
1

Re: UK shipping by postcode error logs

Hi Lat9
Thank you for your help. The addition of the ?? '' null coalescing operator worked perfectly.
Many thanks
Rick