Some questionable logic in code
-
Hello,
Sorry, I couldn’t find a git repo where to post this, so I’ll do it here.
In your wps-functions.php file you have a function called wps_get_chosen_shipping_method() which is marked as deprecated as per phpdoc. The successor function is_wps_chosen_shipping_method() is noted in the docs, but it literally just uses the same old deprecated function. This is not how deprecation works, you need to revise that logic.
Also, in the function wps_get_chosen_shipping_method() you have the following code:
$chosen_methods = WC()->session->get('chosen_shipping_methods'); return $chosen_methods[0];
In most cases ‘chosen_shipping_methods’ is empty, so it returns NULL, but your following line tries to parse it like it’s an array. This throws a notice on all pages where this function is called out (product page, adding to cart, cart, checkout, etc). A simple validation for $chosen_methods will fix this. Or just do this:
return $chosen_methods[0] ?? null;
Thank you for your attention.
- The topic ‘Some questionable logic in code’ is closed to new replies.