Quantity changes not reflected on block checkout page
-
I am using WooCommerce blocks for the first time. I am using it for both my cart and checkout pages.
I was having an issue, where if I modified a product’s quantity from within the cart page, the product price and shipping price would indeed be reflected in the cart totals. However when I clicked proceed to checkout, it would still show the original quantity and original product/shipping pricing. It would not update unless I either manually refreshed the checkout page, or otherwise interacted with the checkout page in a way that triggered a cart refresh (such as adding my shipping address, which would trigger a shipping price calculation).
In case anyone else is experiencing this issue, I was able to fix it with the following functions.
Javascript:
jQuery(document).ready(function($) {
const { extensionCartUpdate } = wc.blocksCheckout;function triggerServerSideUpdate() { extensionCartUpdate({ namespace: 'auto-refresh-checkout', data: { }, }); } $('body').on('init_checkout', triggerServerSideUpdate);
});
PHP:
add_action(‘woocommerce_blocks_loaded’, function() {
woocommerce_store_api_register_update_callback(
[
‘namespace’ => ‘auto-refresh-checkout’,
‘callback’ => function($data) {
}
]
);
});The strange part is that my callback function is empty, which means in reality it does nothing. It seems that all that is needed is to somehow trigger a server action when the checkout page initially loads, in order for it to refresh the order totals.
I don’t know if this is a WooCommerce issue, or something to do with my own setup, but if it’s a bug, I hope it gets fixed because it is rather troublesome.
Anyhow, I hope this helps somebody.
- The topic ‘Quantity changes not reflected on block checkout page’ is closed to new replies.