I hereby claim:
- I am kurtschlatzer on github.
- I am kurtschlatzer (https://keybase.io/kurtschlatzer) on keybase.
- I have a public key whose fingerprint is 6126 1316 C9FE 560A 650B 8771 45D5 0AC9 D2CD 4E16
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| <?php | |
| add_filter( 'get_user_metadata', 'mtkdocs_filter_user_metadata', 10, 4 ); | |
| function mtkdocs_filter_user_metadata( $value, $object_id, $meta_key, $single ) { | |
| // Check if it's one of the keys we want to filter | |
| if ( in_array( $meta_key, array( '_money_spent', '_order_count' ) ) ) { | |
| // Return 0 so WC doesn't try calculate it | |
| return 0; | |
| } | |
| // Default |
| # GET number of orders | |
| select count(*)from wp_posts where post_type = 'shop_order'; | |
| # DELETE ORDERS | |
| delete from wp_postmeta where post_id in ( | |
| select ID from wp_posts where post_type = 'shop_order'); | |
| delete from wp_posts where post_type = 'shop_order'; | |
| # DELETE order refunds |
| ## Delete duplicate WooCommerce products | |
| ## (Retains the lowest ID) | |
| ## Pro tip: Change to SELECT to test | |
| DELETE bad_rows.* | |
| from wp_posts as bad_rows | |
| inner join ( | |
| select post_title, MIN(id) as min_id | |
| from wp_posts | |
| where post_type = 'product' |
| # First Attempt, seemed to have worked | |
| SELECT DISTINCT(p.ID), p.post_title, p.post_content FROM `wp_posts` p | |
| LEFT JOIN wp_posts im ON p.ID = im.post_parent AND im.post_type = "attachment" | |
| WHERE p.post_status ='publish' | |
| AND p.post_type = "product" | |
| AND im.ID IS NULL | |
| AND p.post_content NOT REGEXP 'src=".*"' | |
| # This works well with woocommerce products. | |
| # Fast |
| /** | |
| * USE AT YOUR OWN RISK! | |
| * | |
| * In no way do I guarantee the accuracy of these queries to do exactly what you want on your own server. | |
| * I have written them down for my own personal record, and you are free to use at your own discretion, | |
| * and provide corrections. | |
| */ | |
| /** | |
| * 1. Delete order and coupon meta data. |
| // PHP snippet included in wp-config.php (or settings.php). | |
| // Including from that location in a separate file is OK as well. | |
| <?php | |
| // Remove any leading "www." from the host name. | |
| $redirect_host = str_replace('www.', '', $_SERVER['HTTP_HOST']); | |
| $redirect_path = strtolower(rtrim($_SERVER['REQUEST_URI'])); | |
| if (strlen($redirect_path) > 2) { | |
| $redirect_path = rtrim($redirect_path, '/'); | |
| } |
| <input type="submit" class="button" name="clear-cart" value="<?php _e('Empty Cart', 'woocommerce'); ?>" /> |