Hi @toad78,
At the moment, the plugin doesn’t include an option to automatically open the slideout when a product is added to the cart. Customers can always open it manually by clicking the menu cart item.
The current behavior is intentional, as automatically opening the slideout every time a product is added may interrupt the shopping experience for some customers. However, we understand that this can be a useful behavior depending on the store.
If this is something you’d like to implement, I’d be happy to discuss it with my colleagues and see what the best approach would be, whether through a custom snippet or as a potential enhancement for a future version.
If you don’t mind me asking, could you tell us a bit more about your use case? We’d be interested to understand why you’d expect the slideout to open automatically, as that feedback can help us evaluate whether this is something we should consider adding in the future.
Hi again @toad78,
I went ahead and wrote this code snippet for you that should do the trick:
/**
* Menu Cart for WooCommerce:
* Opens the sidebar slide-out automatically when a product is added to cart
*/
add_action( 'wp_footer', function() {
if ( ! is_admin() ) :
?>
<script>
jQuery(function($) {
$(document.body).on('added_to_cart', function() {
setTimeout(function() {
$('.wpmenucartli a.wpmenucart-contents').trigger('click');
}, 100);
});
});
</script>
<?php
endif;
} );
If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use code snippets. We also have a blog post here that you may find helpful about adding custom code to your site.
Let me know if you need more help!
Thread Starter
toad78
(@toad78)
Thank you, Yordan. This worked splendidly!