Update minicart section after adding a product

whenever we add a product from custom plp page or custom page, auto update to cart is not enabled from magento.

Adding the following code to the script will enable auto update of the cart section in any page.

<script>
require([
           'Magento_Customer/js/customer-data'
        ], function (customerData) {
            var sections = ['cart'];
            customerData.invalidate(sections);
            customerData.reload(sections, true);
        });
</script>

This can be also used with ajax call also to update the minicart section after adding the product from the custom page.

Leave a comment

Your email address will not be published. Required fields are marked *