WPSlash

Trigger your custom JS when Extra Options changing

Thursday November 19, 2020

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

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
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles

Tutorials

How to Set Up Stripe, PayPal, and Square Payment Gateways for Your WooCommerce Restaurant Ordering System: Step-by-Step Configuration, Transaction Fees Comparison, and Optimizing Checkout for Faster Food Orders (Complete Guide)

Why Payment Gateway Choice Matters for Restaurant Websites A customer is hungry, they’ve spent three minutes building the perfect pad thai order with extra peanuts and a side of spring rolls, and they hit “Checkout.” If the next screen loads slowly, asks them to create an account, or doesn’t support their preferred payment method, that […]
April 14, 2026
FoodMaster (formerly WooFood)

How to Set Up a Catering and Large Group Order System on Your WooCommerce Restaurant Website: Custom Menus, Minimum Order Requirements, Scheduled Delivery Windows, and Tiered Pricing for Events and Corporate Orders (Complete Guide)

Why Your Restaurant Needs a Dedicated Catering Order System Online Catering revenue in the United States reached an estimated $66.5 billion in 2023 according to the Catering Industry Association, and a significant portion of that spend is shifting online. Corporate clients, event planners, and families organizing celebrations increasingly expect to browse menus, customize orders, and […]
April 14, 2026
Tutorials

How to Set Up Automated Backups and Disaster Recovery for Your WooCommerce Restaurant Website: Scheduled Backups, One-Click Restore, and Protecting Your Menu, Orders, and Customer Data from Catastrophic Loss (Complete Guide)

Why Backups Are Non-Negotiable for WooCommerce Restaurant Websites Your restaurant website isn’t a brochure. It’s a living, breathing system that processes orders, stores customer data, manages delivery zones, and handles payments around the clock. Every hour your site is operational, new transactional data flows into your database — orders with special instructions, customer addresses, payment […]
April 13, 2026