WPSlash Licences

Trigger your custom JS when Extra Options changing

Trigger your custom JS when Extra Options changing – code snippet guide from WPSlash
Published
Updated
Reading time
1 minutes
Written by
WPSlash team

You copy and paste the following snippet to your functions.php on your child theme.

The following code will give an alert() to user when an extra option is checked.

Adjust the code to your needs

Code
add_action("wp_footer", "wpslash_woofood_extra_option_triggers" ); 
function wpslash_woofood_extra_option_triggers()
{
?>
<script>
jQuery(document).on("change", ".extra-options-accordion input, .extra-options-accordion select", function(){
 						var current_extra =  urldecode(this.value);
 						var obj_current_extra = jQuery.parseJSON(current_extra);

 						var id = obj_current_extra.id;
 						var cat = obj_current_extra.category;
 						var price_html = obj_current_extra.price;
 						var price = obj_current_extra.price_float;
 						var name = obj_current_extra.name;

 						if(this.checked || this.selected)
 						{
 							alert(name+" has Bee checked")
 						}

                    
                     
 });

       function urldecode(str) {
   return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
</script>
<?php
}
All guides

FoodMaster (formerly WooFood)12 min read

Best Store Address Setup for Pickup

Compare single-address, multi-location, and directions-first pickup setups to reduce wrong-door visits and simplify checkout.

The plugins these guides are about

FoodMaster for restaurants, courier vouchers for the Greek market, marketplace sync and store tools, all for WooCommerce.

Browse plugins30-day money-back on every plugin