Cart Block appears empty after adding a bundle
-
WordPress 6.7
Woocommerce 9.7
WPC Product Bundles 8.2.1
After adding a bundle to the cart, it appears empty, event if adding another product.
It seems there is a issue with how the product bundle quantity is handled as a float instead of an integer.
Therefore, in thenormalize_cart()function the normalized quantity of1cannot be type equal to the quantity of1.0leading to callingset_cart_item_quantity. But the item quantity is noteditable(=false) throwing an exception with the error messageThe quantity of %1$s cannot be changed./**
* Normalizes the cart by fixing any quantity violations.
*/
public function normalize_cart() {
$quantity_limits = new QuantityLimits();
$cart_items = $this->get_cart_items();
foreach ( $cart_items as $cart_item ) {
$normalized_qty = $quantity_limits->normalize_cart_item_quantity( $cart_item['quantity'], $cart_item );
if ( $normalized_qty !== $cart_item['quantity'] ) {
$this->set_cart_item_quantity( $cart_item['key'], $normalized_qty );
}
}
}I managed to fix the issue on our website by modifying cart items to cast quantity as integer through the
woosb_minify_itemsfilteradd_filter('woosb_minify_items', 'woosb_minify_items_cast_quantity_to_int'], 10, 2);
function woosb_minify_items_cast_quantity_to_int($minify_items): array
{
return array_map(function($item) {
$item['qty'] = (int) $item['qty'];
return $item;
}, $minify_items);
}Don’t know why item quantity is a float in your plugin but in our case it makes no sense so casting to integer seems ok.
The topic ‘Cart Block appears empty after adding a bundle’ is closed to new replies.