Created
July 29, 2021 09:38
-
-
Save jetsloth/d02ec7e8c83fb07a4b5c258e3ecc16c9 to your computer and use it in GitHub Desktop.
Toggle the WooCommerce elements (subtotal, total, quantity and add to cart) based on whether the last Collapsible Section is open or not. For use with WooCommerce Gravity Forms Product Addons and Collapsible Sections. The code below can be added to a HTML field in your form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
(function($){ | |
function toggleAddToCart( $form, show ) { | |
if ( typeof $form === 'undefined' || !$form.length ) { | |
return; | |
} | |
if ( show !== true ) { | |
show = false; | |
} | |
$form.find('.product_totals, .quantity, button[name="add-to-cart"]').toggle( show ); | |
} | |
$(document).ready(function(){ | |
var $lastSection = $('.gform_variation_wrapper .collapsible-sections-field:last'); | |
var lastSectionID = $lastSection.attr('id'); | |
var csDelay; | |
$('body').on('click', '.collapsible-sections-field', function(e){ | |
var $section = $(this); | |
clearTimeout(csDelay); | |
csDelay = setTimeout(function(){ | |
var show = ( $section.attr('id') === lastSectionID && $section.data('collapsible-closed') === false ); | |
toggleAddToCart( $section.closest('form'), show ); | |
}, 100); | |
}); | |
setTimeout(function(){ | |
toggleAddToCart( $lastSection.closest('form'), $lastSection.data('collapsible-closed') === false ); | |
}, 100); | |
}); | |
})(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment