Title: Some questionable logic in code
Last modified: March 29, 2021

---

# Some questionable logic in code

 *  Resolved [martinjts](https://wordpress.org/support/users/martinjts/)
 * (@martinjts)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/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.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Keylor Mendoza](https://wordpress.org/support/users/keylorcr/)
 * (@keylorcr)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/some-questionable-logic-in-code/#post-14363563)
 * Hey [@martinjts](https://wordpress.org/support/users/martinjts/)
 * I really appreciate your comment, I was pretending to set this function as deprecated,
   but it is in use for an addon of another developer and I’ve forgotten to remove
   that deprecation.
 * It will be fixed in the next release and also I will apply your suggestion for
   the value that returns.
 * Thank you for your support
 * Regards.
 *  Thread Starter [martinjts](https://wordpress.org/support/users/martinjts/)
 * (@martinjts)
 * [5 years ago](https://wordpress.org/support/topic/some-questionable-logic-in-code/#post-14424492)
 * [@keylorcr](https://wordpress.org/support/users/keylorcr/) Thanks a lot! I appreciate
   it.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Some questionable logic in code’ is closed to new replies.

 * ![](https://ps.w.org/wc-pickup-store/assets/icon-256x256.jpg?rev=2011755)
 * [WC Pickup Store](https://wordpress.org/plugins/wc-pickup-store/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wc-pickup-store/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wc-pickup-store/)
 * [Active Topics](https://wordpress.org/support/plugin/wc-pickup-store/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wc-pickup-store/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wc-pickup-store/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [martinjts](https://wordpress.org/support/users/martinjts/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/some-questionable-logic-in-code/#post-14424492)
 * Status: resolved