This repository was archived by the owner on Feb 23, 2024. It is now read-only.
This repository was archived by the owner on Feb 23, 2024. It is now read-only.
Validate data coming from "woocommerce_cart_shipping_packages" filter #9016
Open
Description
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:
- Install and activate Multiple Packages for WooCommerce without setting it up
- Install, activate, and set Test Keys for WooCommerce Stripe Gateway
- Add an item to the cart and visit the Cart Block page
- See Warning/TypeError:
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.