Zen Cart Logo
Forums / Addon Shipping Modules / UK shipping by postcode error logs

UK shipping by postcode error logs

Views: 910

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

richard7315

New Zenner

Join Date:
Jul 2017
Location:
West Midlands, UK
Posts:
51
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, 2:48 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

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'] [B]?? ''[/B];
        $pcode = preg_replace('/\s\s*/', '', $destination_postcode);
16 May 2025, 9:43 AM
#3
richard7315 avatar

richard7315

New Zenner

Join Date:
Jul 2017
Location:
West Midlands, UK
Posts:
51
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