First verify your product attribute (meta_key) by running this query
Note: Change table prefix according to your wordpress database mine is
default wp_
SELECT * FROM wp_postmeta WHERE meta_key LIKE '%code%'; /* get attribute name example (_sku, _stock, _stock_status, height, width )*/
Now add this to your functions.php file
function Add_custom_search( $query )
{
if( ! is_admin() && $query->is_main_query() )
{
if ( $query->is_search() )
{
$meta_query = $query->get( 'meta_query' );
$meta_query[] = array(
'key' => 'code', /* Product Attribute Meta key Here example (_sku, _stock, _stock_status, height, width ) */
'value' => $query->query['s'],
'compare' => 'LIKE'
);
$query->set( 'meta_query', $meta_query );
}
}
}
add_action( 'woocommerce_product_query' , 'Add_custom_search' );
Related Posts:
- Search results don’t show products
- How to search Woo Commerce products with punctuation in title?
- Woocommerce wp-admin search products through custom meta value too
- if statement for search results
- Separeting product from post in search result
- Woocommerce custom search
- Change the Title Tag of Search Products Page
- WooCommerce orderby template disappears and not longer works on search page
- search customers in front end by billing data
- Create a shortcode for native WooCommerce search form [closed]
- Can’t find a product by SKU
- Absolute search against wordpress api
- override the default WooCommerce products search form
- Create a Search Form that only Searches with WooCommerce Sale Products
- Call product search from custom hook
- Search doesn’t return anything
- edit URL of search result
- No Results in WooCommerce Product Search
- Woocommerce Multisite global search how to mod ajax function?
- I wan redirect link post search to search product woocommerce?
- How to filter result set in custom metaboxes?
- Notice: Trying to get property of non-object in
- How can I change my search form to bring up product results, not blog results
- Is it possible to hide certain products from displaying in the search results
- Woocommerce ajax search can’t work on mobile
- How can I define a custom template for woocommerce [products] shortcode? [closed]
- Display Categories Assigned to a WooCommerce Product
- Get current WooCommerce endpoint not working
- Changing Woocommerce price display [closed]
- Which WooCommerce hook do I need to use to place the coupon field after the checkout sidebar
- WooCommerce Cart – Group Products By Category
- Set a default quantity input value for a variable product category in WooCommerce
- WooCommerce product sorting VERY slow
- WooCommerce change price in cart [closed]
- Categories not shown in admin after adding woocommerce products via wp wc cli
- Enabling autosave when plugin disabled
- WooCommerce email text based on category && shipping zone && payment method [closed]
- woocommerce – get_image_size() deprecated [closed]
- Problem with cURL and rest API
- Avada & WooCommerce Customization – Replacing product_title in woo-config.php [closed]
- WooCommerce template page for category
- Woocommerce PHP site that shows table with orders from specific category
- How to get the webshop page in 2:nd language, with Polylang and Hyyan
- Subcategories not working when using shared base with custom taxonomy
- WooCommerce Cart Total Table chronology order change [closed]
- Woocommerce Update Order Notes Date
- Shipping Method does not inherit settings from the class
- My woocommerce checkout page and woocommerce setting page are not responding [closed]
- Woocommerce Shortcode custom orderby not working
- Overwrite ‘require’ in child-theme
- Javascript error when adding an item to the cart [closed]
- Best Practice – Customise a WooCommerce+WordPress Templates
- Woocommerce: Complex query in pre_get_posts [closed]
- How can I get all the woocommerce api orders [closed]
- Is it possible to update the total price on the checkout page in woocommerce from a custom field
- Customize WooCommerce Add To Cart Form Name [closed]
- Remove WooCommerce block styles
- WooCommerce adding product to cart programatically [closed]
- Weird strange letters appeared in all website links [duplicate]
- password_reset doesnt work
- How can I reference external attachments without breaking core WordPress files?
- Hide prices from certain category in woocommerce
- Check if a WooCommerce Order Item has a specific meta data key
- WooCommerce Cart Items
- Online wc-blocks-style.css rendering instead of the hosted wc-blocks-style.css
- Broken link additional images after moving server
- I have 3 types of prices in WP and I need to change price for each specific user role using hooks
- How do I display only the relevant attributes?
- How to hide “Shipping” label from Woocommerce cart page
- What is the problem with these lines of code?
- How to add php variable inside wc_enqueue_js(‘jQuery’) function?
- Show menu order field in quick edit
- Adapt shipping surcharge code [closed]
- How to access product’s meta data when deleting a WooCommerce product?
- WC_Structured_Data Class Causing Needless Translation
- Placing Lock Icon on WooCommmerce “Place Order” Checkout Button (WordPress ‘ignoring’ Changes…)
- How to Sync Woocommerce and CRM via External API
- Add sale count next to star rating in woocommerce single product page
- Format number to 2 decimal places
- Two e-commerce in two different folders of the same domain
- Random 503 and 504 errors
- How do i display zip code options during checkout [closed]
- Woocommerce language isn’t default language
- How set variation after filter in WooCommerce?
- Does anyone know a crowdsourcing plugin that can support the following use case?
- How to get products without tag?
- Enable Payment gateway if ACF checkbox in user profile is checked
- How do you reactive related products on WooCommerce when it has been disabled?
- How can I locate where the actions are defined? [duplicate]
- Shortcodes in billing fields doesn’t work
- Update a user meta key based on WooCommerce product purchase
- show multiple product photos on WooCommerce single page
- Custom Search Template for Custom Post Types
- How to get _POST variable on WooCommerce product page (form on homepage)
- Search box missing Woocommerce Product Bundle Extension
- DatePicker in Woocommerce (My Account) Registration [closed]
- problems with an object product wooCommerce [closed]
- Critical error on woocommerce checkout page
- Can’t add variable products since update WooCommerce [closed]
- Add custom ID to WooCommerce product tab