• Resolved Mushi

    (@mubashiriqbal)


    I was able to filter woocommerce customers from getting deleted and i have modified your query to the following

     $sql = "SELECT $select FROM ${pre}users AS u ".
               "LEFT OUTER JOIN ${pre}comments AS c ON u.ID = c.user_id ".
               "LEFT OUTER JOIN ${pre}posts AS p ON u.ID = p.post_author ".
               "LEFT OUTER JOIN ${pre}links AS l ON u.ID = l.link_owner ".
               "WHERE c.user_id IS NULL ".
               "AND p.post_author IS NULL AND l.link_owner IS NULL ".
               "AND u.ID NOT IN (SELECT DISTINCT(meta_value) from ${pre}postmeta WHERE meta_key = '_customer_user') ".        
               $this->getUserWhitelistSQL()." ".
               "AND u.user_registered < DATE_ADD(NOW(), INTERVAL -$daysGrace DAY) ".
               "GROUP BY u.ID${limit};";

    Above query works fine but as i have thousands of users in my users table your plugin get crashed. Can you help me how we can optimize this?

    If we can fix this then your plugin can add this feature to filter woocommerce customers. Because woocommerce stores order data in postmeta table and customer id is stored in the meta_value where meta_key = ‘_customer_user’

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Mushi

    (@mubashiriqbal)

    @joelhardi Can you please provide your feedback on this. Thanks

    Plugin Author joelhardi

    (@joelhardi)

    Hi,

    Not sure what you’re trying to accomplish, and I’m not familiar with WooCommerce, but I have a couple of thoughts, for whatever they’re worth.

    If all your users have got a specific value in the postmeta table and you want to exclude these users from being deleted, then what users do you *want* to delete? And if a spam/bot account registers on your site, wouldn’t they have this same postmeta value set?

    You’ve added a subselect into the query — I obviously can’t profile or test your query but I remember having to do significant query optimization when I originally developed this plugin, so I’d just draw your attention to that, there may be a problem with your query. It looks like your query would grow very large with the size of postmeta table.

    A super-easy thing to do if you can write a SQL query to accomplish what you want is just to run the query periodically, or in a cronjob.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Support for Woocommerce customers’ is closed to new replies.