• Resolved unapragmatica

    (@unapragmatica)


    Hello, I am having problems with the cart ajax. Basically it doesn’t open automatically when adding to cart (ajax is active in plugin settings) and it doesn’t update either. Only after reloading the page is the cart displayed correctly.

    My worpress version is 6.2.1
    WooCommerce 8.2.2
    Side Cart WooCommerce 2.4.7
    Php 8.1.26

    At one point I thought I had found the problem, because Jetpack was malfunctioning. Currently I deleted it and the cart worked for a few days, now it failed again. I am disoriented.

    Any help helps. Thank you.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author xootix

    (@xootix)

    Hello,

    Please try adding this snippet

    /* Block theme fix */
    add_action( 'wp_enqueue_scripts', function(){
    	wp_enqueue_script( 'wc-cart-fragments' );
    }, PHP_INT_MAX );
    
    add_action( 'wp_footer', function(){
    	?>
    	<script type="text/javascript">
    		jQuery(document).ready(function($){
    			$(document.body).on( 'wc-blocks_added_to_cart', function(){
    				$( document.body ).trigger( 'wc_fragment_refresh' );
    			} )
    		})
    	</script>
    	<?php
    } );
    Thread Starter unapragmatica

    (@unapragmatica)

    Thank you so much! I added it and now the cart updates every time I add a product. That’s great!

    Now what I notice is that it doesn’t open, so the number increases but it doesn’t open automatically (that option is active in settings).

    Plugin Author xootix

    (@xootix)

    Please replace

    /* Block theme fix */
    add_action( 'wp_enqueue_scripts', function(){
    	wp_enqueue_script( 'wc-cart-fragments' );
    }, PHP_INT_MAX );
    
    add_action( 'wp_footer', function(){
    	?>
    	<span class="xoo-wsc-cart-trigger" style="display: none;"></span>
    	<script type="text/javascript">
    		jQuery(document).ready(function($){
    			$(document.body).on( 'wc-blocks_added_to_cart', function(){
    				$( document.body ).trigger( 'wc_fragment_refresh' );
    				$('.xoo-wsc-cart-trigger').trigger('click');
    			} )
    		})
    	</script>
    	<?php
    } );

    I have the same problem. I tried the code but still doesn’t open.

    Plugin Author xootix

    (@xootix)

    @johnronniel
    The snippet above is a fix for block themes and works.
    Something else could be the issue on your end.
    Please open another support thread with your website link.

    Thread Starter unapragmatica

    (@unapragmatica)

    I confirm that it works correctly in themes with blocks. Thank you very much @xootix, success with your site @johnronniel.

    Regards.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Ajax not working’ is closed to new replies.