Skip to content
Advertisement

WooCommerce extend product search by custom product data field

I’m currently trying to extend the WooCommerce product search so that the search uses my custom field I’ve created within the general product data section:

JavaScript

With the above code, I can add and save my custom field. Now I’ve extended the search with the below hook:

JavaScript

When I set a text like “Iamabigtestword” to my field and put it in the search, I’m still getting nothing. What am I missing? I really can’t find the issue here. Normally, the hook should work (regarding an answer from StackOverflow: Include custom fields value in woocommerce search)

Note

You can copy/paste the code directly in the functions.php file of your child theme to test it, since it has no dependencies and should add the field to the Products > Product > General tab at the end.

Advertisement

Answer

I think I have found a way after some testing. First, I’ve debugged the WC function where the action gets applied, but changed my approach since I was making no progress. I’ve now extended the post search via the given WordPress filter:

JavaScript

I hope it helps someone! If someone finds a better approach, I can test it for you.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement