Fatal error in wc_get_product_max_limit()
-
Hi,
We’re getting a fatal error with Maximum Quantity for WooCommerce v2.3 during cart validation:
PHP Fatal error: Uncaught Error: Call to a member function get_meta() on false
in …/wp-content/plugins/woocommerce-max-quantity/woocommerce-max-quantity.php:132Abbreviated backtrace:
- wc_get_product_max_limit() — line 132
- wc_max_qty_update_cart_validation() — line 332 (hooked to woocommerce_update_cart_validation)
- theme mini-cart → admin-ajax.php
Root cause: in wc_get_product_max_limit( $product_id ), wc_get_product( $product_id ) can
return false (e.g. a cart item referencing a product/variation that no longer exists), and the
next line calls $product->get_meta( ‘_isa_wc_max_qty_product_max’ ) on that false value.Suggested fix:
$product = wc_get_product( $product_id );
if ( ! $product instanceof WC_Product ) {
return false;
}
$qty = $product->get_meta( ‘_isa_wc_max_qty_product_max’ );Environment: WordPress 7, WooCommerce 10.8, PHP 8.4, plugin v2.3 (latest). Logic-level bug
(not PHP-version specific); it breaks the cart for the affected session.Thanks!
You must be logged in to reply to this topic.