I was trying to make a sidebar using mini-cart.php on woocommerce and so far im doing okay, but i wanted to trigger the sidebar after i click on "add to cart" button on page product.
I found Run javascript code after ajax add to cart event in Woocommerce answer and I made some changes to the code:
add_action( 'wp_footer', 'trigger_for_ajax_add_to_cart' );
function trigger_for_ajax_add_to_cart() {
?>
<script type="text/javascript">
(function($){
$('body').on( 'click', '.single_add_to_cart_button', function(){
$( ".open-side-cart" ).trigger( "click" );
});
})(jQuery);
</script>
<?php
}
What I want is to trigger the mini-cart.php
sidebar when the user clicks on the ".single_add_to_cart_button" class button, and it works. But as woocommerce reloads the page updating the mini-cart.php
, so the trigger works before reloading the page.
Is there a way to trigger after reloading the page?