Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Trying to access array offset on value of type null

$
0
0

Replies: 0

I’m getting the following error when testing as a new (not logged-in) user. I added 1 item to the cart and went straight to the cart page.

Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\speciaalbierwebshop\wp-content\plugins\wt-smart-coupons-for-woocommerce\public\class-wt-smart-coupon-public.php

The particular line of code:
$chosen_shipping = $chosen_shipping_methods[0];

I suspect the error is thrown as no shipping method has been selected yet. I have set Woocommerce to hide shipping cost until an address has been input. No customized code, just the regular shipping option.

I have solved this temporarily by adding an if statement.

if ( isset($chosen_shipping_methods[0])) {
$chosen_shipping = $chosen_shipping_methods[0];
$chosen_shipping = substr($chosen_shipping, 0, strpos($chosen_shipping, “:”));
if (!in_array($chosen_shipping, $coupon_shipping_method_ids)) {
$valid = false;
}

if ( ! $valid ) {
throw new Exception( __( ‘Sorry, this coupon is not applicable to selected shipping method’, ‘wt-smart-coupons-for-woocommerce’ ), 109 );
}
}
}`


Viewing all articles
Browse latest Browse all 59525

Trending Articles