• Hello! How can I add the Product Code as a search criteria in woocommerse?
    Example: I have a product with the code “123456”. Wen you put “123456” in the Search Product field of woocommerse nothing is found.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author artiosmedia

    (@artiosmedia)

    Greetings,

    The ‘postmeta’ table is where all the custom field data is stored in the database. By default, the WordPress search functionality is set to search the ‘posts’ table only. In order to include the custom fields data in our search, we need to perform a left join on the ‘posts’ and ‘postmeta’ tables in the database and modify the WordPress search query to include custom fields. Finally, we need to add the DISTINCT keyword to the SQL query in order to prevent returning duplicates.

    Paste the following into your WordPress child theme’s functions.php. Remove the starting ‘<?php’ if you have other code already active in that file. https://gist.github.com/Artiosmedia/4b0d065bc033885d2b44bbefcdfb6f17

    Once installed, cache purged and browser reloaded, try to search a unique Product Code entered from the WordPress default search.

    Plugin Author artiosmedia

    (@artiosmedia)

    The results may not be consistent since it is a generic search. SearchWP might be more applicable, but it has not been tested.

    • This reply was modified 5 years, 7 months ago by artiosmedia.
    Thread Starter agustinfiori

    (@agustinfiori)

    Cool!! thank you!!!!!

    Plugin Author artiosmedia

    (@artiosmedia)

    I am going to do more research on this, to hopefully modify the Gist code to specifically include the data table “_product_code” where the Gist snippet nor the search add-ons like SearchWP and Relevanssi cannot acknowledge nor index the custom field, even though the custom field data is selectable. Something is not quite right with the plugins code, where it is not correlating with any custom field snippets or add-ons. The plugin needs adjusted to work in unison with the two above mentioned plugins at minimum, but at least specifically with the Gist snippet.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Product Code as Search Criteria’ is closed to new replies.