woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
405 stars 218 forks source link

Validate data coming from "woocommerce_cart_shipping_packages" filter #9016

Open wavvves opened 1 year ago

wavvves commented 1 year ago

Describe the bug

A Warning/ TypeError (depending on PHP version used) is displayed on the front end when Multiple Packages for WooCommerce is activated but not yet configured, while WooCommerce Stripe Gateway is enabled and configured.

To reproduce

Steps to reproduce the behavior:

  1. Install and activate Multiple Packages for WooCommerce without setting it up
  2. Install, activate, and set Test Keys for WooCommerce Stripe Gateway
  3. Add an item to the cart and visit the Cart Block page
  4. See Warning/TypeError:

image

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php:604 
Stack trace: 
#0 woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php(879): WC_Stripe_Payment_Request->allowed_items_in_cart() 
#1 woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php(757): WC_Stripe_Payment_Request->should_show_payment_request_button() 
#2 wp-includes/class-wp-hook.php(308): WC_Stripe_Payment_Request->scripts('') 
#3 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array) 
#4 wp-includes/plugin.php(517): WP_Hook->do_action(Array) 
#5 wp-includes/script-loader.php(2194): do_action('wp_enqueue_scri...') 
#6 wp-includes/class-wp-hook.php(308): wp_enqueue_scripts('') 
#7 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array) 
#8 wp-includes/plugin.php(517): WP_Hook->do_action(Array) 
#9 wp-includes/general-template.php(3049): do_action('wp_head') 
#10 wp-content/themes/storefront/header.php(18): wp_head() 
#11 wp-includes/template.php(783): require_once('...') 
#12 wp-includes/template.php(718): load_template('...', true, Array) 
#13 wp-includes/general-template.php(48): locate_template(Array, true, true, Array) 
#14 wp-content/themes/storefront/page.php(13): get_header() 
#15 wp-includes/template-loader.php(106): include('...') 
#16 wp-blog-header.php(19): require_once('...') 
#17 index.php(17): require('...') 
#18 {main} 
thrown in woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 604

Expected behavior

No Warning/Error should be displayed.

Additional context

The problem seems to be the output of "woocommerce_cart_shipping_packages" filter, as it is expecting an array explicitly (L828 rules out object implementing Countable).

Note: This could be a good opportunity to revisit the TODO comment and address the duplicate code present there.

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface issues for review. If you are the author of the issue there's no need to comment as it will be looked at.