WPSlash

How to Add Live Product Search to WooFood in WooCommerce

Thursday December 29, 2022

Enhancing the user experience of your WooCommerce-powered restaurant ordering system is crucial, and adding a live product search feature can significantly improve navigation. This feature allows customers to quickly find food items in your WooFood-powered menu without manually browsing through categories.

In this article, we’ll show you how to integrate a live product search above the accordion menu in WooFood using a simple jQuery script and PHP snippet.

Why Add Live Product Search to WooFood?

A live product search feature can:
✔ Improve the ordering experience by allowing instant product searches
✔ Enhance navigation, especially for menus with large numbers of items
✔ Increase conversions by helping customers find what they want faster

How to Implement Live Product Search in WooFood

To add a live search bar above the WooFood accordion menu, insert the following PHP snippet into your theme’s functions.php file:

add_action("wp_footer", function()
{
	?>
	<style>
		input.woofood-live-search
		{
			width: 100%;
			margin-bottom: 10px;
			border: none;
			border: 1px solid #bdb0b0;
			padding: 10px;
		}
	</style>
	<script>
		jQuery(document).ready(function()
		{
			jQuery( "<input type='text' class='woofood-live-search' placeholder='Search for Products...'/> " ).insertBefore( ".woofood-accordion:first" )
			jQuery( "<div class='woofood-live-results'><ul class='woofood-products'></ul></div>" ).insertBefore( ".woofood-accordion:first" )

		});
		jQuery(document).on('propertychange input', '.woofood-live-search', function (e) {
			var valueChanged = false;
			var search_value = jQuery(this).val();
			var vthis = jQuery(this);
			if (search_value=="")
			{

				jQuery('.woofood-live-results .woofood-products').html("");
			}
			else
			{



				if (e.type=='propertychange') {
					valueChanged = e.originalEvent.propertyName=='value';
				} else {
					valueChanged = true;
				}
				if (valueChanged) {




				}
				jQuery('.woofood-live-results .woofood-products').html("");

				jQuery('.woofood-product-loop').each(function( index ) {
					console.log( index + ": " + jQuery( this ).find('.product-title span:first').text().toLowerCase() );
					if(jQuery( this ).find('.product-title span').text().toLowerCase().includes(search_value.toLowerCase()))
					{
						jQuery( this).clone().appendTo( ".woofood-live-results .woofood-products" );


					}
					else
					{
						


					}
				});
			}


		});

	</script>
	<?php



});

How This Code Works

✅ The script inserts a search bar above the WooFood accordion menu.
✅ As the user types, the script searches through product titles in the menu.
✅ Matching products are cloned and displayed dynamically without refreshing the page.
✅ If the search box is empty, the search results are cleared.

Best Practices for Using This Live Search Feature

🔹 Ensure your WooFood setup is working properly before adding this customization.
🔹 Modify the CSS styles to match your restaurant theme design.
🔹 Test the feature on both desktop and mobile devices for the best user experience.

Need a Complete WooCommerce Restaurant Ordering System?

If you’re looking for a powerful and fully automated WooCommerce food ordering solution, WooFood – WooCommerce Food Delivery Plugin is the best choice.

With WooFood, you can:
✅ Accept pickup and delivery orders seamlessly
✅ Provide customers with an interactive and mobile-friendly ordering experience
✅ Add features like live search, cart customization, and real-time order updates

👉 Check out WooFood here and enhance your WooCommerce food ordering system today! 🚀

Leave a Comment

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

Related Articles

WooFood

How to Disable Coupons for Delivery Orders in WooCommerce

If you’re running a WooCommerce-powered restaurant or food delivery service, you might want to restrict certain coupon codes for delivery orders while keeping them valid for pickup orders. This ensures better control over discounts, prevents misuse, and improves your store’s pricing strategy. Why Restrict Coupons for Delivery Orders? Offering coupons is a great way to attract customers, but in food […]
June 20, 2023
WooFood

How to Automatically Re-Enable Disabled Products in WooFood Once a Day

If you’re running a WooCommerce-powered restaurant ordering system using WooFood, you might have products that automatically get disabled due to stock limits or availability settings. To ensure a smooth customer experience, you can automate the re-enabling process using a scheduled WordPress cron job. This method allows you to reset all product availability once a day, ensuring your menu stays active without manual intervention. Why […]
March 8, 2023
Tutorials WooFood

How to Disable Actions and Show an Overlay When Your WooCommerce Store is Closed

If you’re running a WooCommerce restaurant ordering system, you may want to disable ordering and display an overlay when your store is closed or not accepting orders. This ensures that customers know when ordering is unavailable, improving the user experience. In this guide, we’ll show you how to use a simple PHP snippet to automatically disable WooCommerce orders and display an overlay notification when the store is […]
June 2, 2022