Slow query while searching a product woocommerce

I was struggling with this issue since long with my wordpress with wooocommerce website. Whenever i was doing a search in admin dashboard for wooommerce products it was taking long time and end up with no results.

SELECT DISTINCT posts.ID as product_id, posts.post_parent as parent_id
    FROM wp_posts posts 
         LEFT JOIN wp_postmeta postmeta ON posts.ID = postmeta.post_id 
    WHERE ( posts.post_title LIKE '%Samsung%' 
            OR posts.post_excerpt LIKE '%Samsung%' 
            OR posts.post_content LIKE '%Samsung%' 
            OR ( postmeta.meta_key = '_sku'
                 AND postmeta.meta_value LIKE '%Samsung%' ) ) 
          AND posts.post_type IN ('product','product_variation') 
    ORDER BY posts.post_parent ASC, posts.post_title ASC

After months of troubleshooting i am still not able to fully resolve the issue, however with this workaround i am finally somewhat relived.

To resolve this issue…

Edit this file – public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php

In Woocommerce version 3.4.6 look for search_products function

On line no. 1397 look for

$term_group_query .= $wpdb->prepare( ” {$searchand} ( ( posts.post_title LIKE %s) OR ( posts.post_excerpt LIKE %s) OR ( posts.post_content LIKE %s ) OR ( postmeta.meta_key = ‘_sku’ AND postmeta.meta_value LIKE %s ) )”, $like, $like, $like, $like ); // @codingStandardsIgnoreLine.

Remove following code

OR ( postmeta.meta_key = ‘_sku’ AND postmeta.meta_value LIKE %s )

It should then look like this…

$term_group_query .= $wpdb->prepare( ” {$searchand} ( ( posts.post_title LIKE %s) OR ( posts.post_excerpt LIKE %s) OR ( posts.post_content LIKE %s ) )”, $like, $like, $like, $like ); // @codingStandardsIgnoreLine.

Save the file and you should be able to search for products now. The downside with this is you’ll not be able to search SKU’s. But i was ok with this as dont have SKU’s added to my products.

I hope this will help you.

Best WordPress Coupon Theme You Always Wanted To Earn More

Coupon WordPress Theme is a beautiful and professional theme built from the ground up for the coupon business. Impress your visitors and convert more sales with this highly professional and fully customizable theme. The best theme for selling coupons, full stop!

Features

  • Responsive
  • Speed Optimized
  • SEO Ready
  • Use On Unlimited Sites

What You Get with this theme

  1. Unlimited Domain Usage
  2. One Click Installation
  3. Support & Updates for One Year
  4. 24×7 Premium Technical Support
  5. Narrated Video Tutorials
  6. Options Panel
  7. Secured & Optimized Code
  8. 30 Day Money Back Policy

Coupon Code MCHNY16

Get any #WordPress Theme or Plugin for just $19 #XMAS #Discount BUY FOR $19 (LIMITED TIME!)

 

Forgotten wp-admin Password and Username – WordPress

 

wpadmin-wrong-password[1]

 

Retrieve WordPress User Name

Go back to PhpMyAdmin, go to the ‘SQL’ tab, and paste this:

SELECT * FROM wp_users LEFT JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id WHERE meta_value LIKE '%administrator%'

You should get a list of all the users with the ‘administrator’ role. One of those should be your account. You ought to recognize the email address or something. Then use the password reset function at /wp-login.php to straighten things out. Be sure to check that the email address in the database is an address you still use. If not, change it so that you get the reset email.

Resetting_Your_Password

Fatal error: Allowed memory size of 33554432 bytes exhausted WordPress

You can create a php.ini file in your Public_html and wp-admin folder and add the below line on it.

memory_limit = 64M

Once you create the above file then you can able to install wordpress and all the themes.