Infinite loop caused by amelia WooCommerce cart integration
-
Hi there,
we are the developers of Germanized for WooCommerce and (together with one of our users) found an issue with the amelia booking WooCommerce integration. The issue seems to only affect your paid solutions but I’ve found no (easy) way to report bugs there, that’s why I’m using this channel.
The issue is related to your filter added to
woocommerce_checkout_get_value
inameliabooking/src/Infrastructure/WP/Integrations/WooCommerce/WooCommerceService.php
. Seems like under certain conditions the logic (which by itself callsWooCommerceService::processCart()
) eventually triggers a cart recalculation via:$wooCommerceCart->calculate_totals();
The issue is that any other extension (in our case, Germanized) which attaches it’s logic to a hook fired by the cart calculation, e.g.
woocommerce_before_calculate_totals
AND usesWC()->checkout()->get_value()
to retrieve a certain value directly from the checkout object will lead to an infinite loop in conjunction with the amelia logic which will (again) trigger the cart recalculation as soon as thewoocommerce_checkout_get_value
is fired by callingWC()->checkout()->get_value()
.To reproduce, try adding the following snippet to your current theme’s functions.php:
add_action( 'woocommerce_before_calculate_totals', function() { $checkout = WC()->checkout(); $checkout->get_value( 'test_yo' ); } );
When trying to book a course/appointment now, the infinite loop will fire as soon as the
admin-ajax.php?action=wpamelia_api&call=/payment/wc
call is made. Could you please look into that?A possible fix would be to add a check to the
$wooCommerceCart->calculate_totals();
to prevent this method from being called in case the hook is fired while already recalculating totals, e.g.:if ( ! doing_action( 'woocommerce_before_calculate_totals' ) ) { $wooCommerceCart->calculate_totals(); }
Cheers,
Dennis
- The topic ‘Infinite loop caused by amelia WooCommerce cart integration’ is closed to new replies.