Title: PHP Error in Shipping Method Matching Function
Last modified: January 19, 2024

---

# PHP Error in Shipping Method Matching Function

 *  Resolved [vopsdev](https://wordpress.org/support/users/vopsdev/)
 * (@vopsdev)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/php-error-in-shipping-method-matching-function/)
 * Hi Jeremy,
 * I’ve been using your fantastic WordPress plugin for a while now and it’s been
   incredibly helpful. However, I’ve recently encountered a PHP error in one of 
   the functions, and I’m seeking your expertise to help resolve it.
 * The specific function causing the issue is was_match_methods in the file [/public_html/
   wp-content/plugins/woocommerce-advanced-shipping/includes/class-was-method.php:
   93]. The error message I’m getting is “CRITICAL Uncaught Error: [] operator not
   supported for strings.” After reviewing the code, I noticed that $matched_methods
   is initially declared as an empty string ($matched_methods = ”;), but later in
   the loop, it’s treated as an array ($matched_methods[] = $method->ID;), resulting
   in the mentioned error.
 * To resolve this issue, I suggest initializing $matched_methods as an empty array,
   like so: $matched_methods = array();. I’ve made this adjustment locally, and 
   it seems to have resolved the error.
 * Here’s the updated code snippet:
 *     ```wp-block-code
       public function was_match_methods( $package ) {
   
       $matched_methods = array(); // Initialize as an array(fixed)
       $methods = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'was', 'orderby' => 'menu_order', 'order' => 'ASC' ) );
   
       foreach ( $methods as $method ) :
   
           $condition_groups = get_post_meta( $method->ID, '_was_shipping_method_conditions', true );
   
           // Check if method conditions match
           $match = $this->was_match_conditions( $condition_groups, $package );
   
           // Add match to array
           if ( true == $match ) :
               $matched_methods[] = $method->ID;
           endif;
   
       endforeach;
   
       return $matched_methods;
       ```
   
 * }
   I wanted to bring this to your attention, and I’m open to any suggestions or
   guidance you may have. Your assistance in resolving this matter would be greatly
   appreciated.
 * Thank you for your time and for creating such a valuable plugin.
 * Best regards,
 * Ethan Reubens
   [ethan@webengine.co.il](https://wordpress.org/support/topic/php-error-in-shipping-method-matching-function/ethan@webengine.co.il?output_format=md)
   webengine.co.il
    -  This topic was modified 2 years, 4 months ago by [vopsdev](https://wordpress.org/support/users/vopsdev/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-error-in-shipping-method-matching-function%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Jeroen Sormani](https://wordpress.org/support/users/sormano/)
 * (@sormano)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/php-error-in-shipping-method-matching-function/#post-17356576)
 * Hi Ethan,
 * Looks like the error/code is from the [<u>Advanced Shipping</u>](https://aceplugins.com/plugin/advanced-shipping-for-woocommerce/purchase)
   plugin, not this ([Advanced Free Shipping](https://wordpress.org/plugins/woocommerce-advanced-free-shipping/))
   one.
 * For questions/support on that plugin you can reach out through the support channel
   here: [https://jeroensormani.com/woocommerce-advanced-shipping/support/](https://jeroensormani.com/woocommerce-advanced-shipping/support/)
 * Cheers,
   Jeroen

Viewing 1 replies (of 1 total)

The topic ‘PHP Error in Shipping Method Matching Function’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-advanced-free-shipping/assets/icon-256x256.png?
   rev=1171652)
 * [Advanced Free Shipping for WooCommerce](https://wordpress.org/plugins/woocommerce-advanced-free-shipping/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-advanced-free-shipping/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-advanced-free-shipping/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-advanced-free-shipping/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-advanced-free-shipping/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-advanced-free-shipping/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Jeroen Sormani](https://wordpress.org/support/users/sormano/)
 * Last activity: [2 years, 4 months ago](https://wordpress.org/support/topic/php-error-in-shipping-method-matching-function/#post-17356576)
 * Status: resolved