I would like to change add to cart button on woodmart theme to quick view.
Here is my code but it does not work.
Any help is appreciated.
My code so far:
function woodmart_trigger_quick_view_on_add_to_cart()
{
// Check if WooCommerce is active
if (!class_exists('WooCommerce')) {
return;
}
// Enqueue jQuery script
wp_enqueue_script('jquery');
// Output the JavaScript code
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.add_to_cart_button').on('click', function(event) {
event.preventDefault();
var quickViewButton = $(this).closest('.product').find('.quick-view-button');
if (quickViewButton.length > 0) {
setTimeout(function() {
quickViewButton;
}, 0);
}
});
});
</script>
<?php
}
2
Answers
I have revisited your code nearly completely and managed to fix your issues.
The revisited code is:
;
Almost, but doesn’t work with ajax filters. When filter is added, it reverts to default behaviour again.