• Resolved Soft79

    (@josk79)


    I get this fatal error when a plugin calls WC_Order::has_shipping_method():

    PHP Fatal error: Uncaught Error: Call to a member function get_method_id() on array

    Reason: $shipping_method->get_method_id() is called in function has_shipping_method but $shipping_method is an array (as returned from ->get_items).

    
    	public function has_shipping_method( $method_id ) {
    
    		$shipping_methods = $this->get_shipping_methods();
    		$has_method = false;
    
    		if ( empty( $shipping_methods ) ) {
    			return false;
    		}
    
    		foreach ( $shipping_methods as $shipping_method ) {
    			if ( strpos( $shipping_method->get_method_id(), $method_id ) === 0 ) {
    				$has_method = true;
    			}
    		}
    
    		return $has_method;
    	}
    
    • This topic was modified 7 years, 6 months ago by Soft79.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘2.6.5 fatal error when calling WC_Order::has_shipping_method’ is closed to new replies.