shadowbox0028
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] HPOS delete old post meta not functionalYess verry good, I literally pressed the Clean up order data from outdated tables function in woocommerce which is located under status -> tools.
this does nothing.
Forum: Plugins
In reply to: [WooCommerce] HPOS delete old post meta not functionalAs temporary fix i managed to accomplish the goal by adding this code to functions.php in my template and clicking trough the pages, note if someone would want to execute this code please know that you always have to backup your database! i am not responsible for your losses.
function delete_old_non_hpos_orders() {
$query_args = array(
'post_type' => 'shop_order',
'post_status' => 'any',
'posts_per_page' => 500,
'orderby' => 'date',
'order' => 'ASC',
'paged' => isset($_GET['paged']) ? intval($_GET['paged']) : 1, // Add pagination
);
$query = new WP_Query($query_args);
if ($query->have_posts()) { // Check if there are any posts
global $wpdb;
foreach ($query->posts as $post) {
$order_id = $post->ID;
// Check if the order exists in HPOS
$exists_in_hpos = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}wc_orders WHERE id = $order_id");
if ($exists_in_hpos) {
echo $order_id . PHP_EOL;
$wpdb->delete("{$wpdb->prefix}postmeta", ['post_id' => $order_id]);
$wpdb->update(
"{$wpdb->prefix}posts",
['post_type' => 'shop_order_placehold'],
['ID' => $order_id]
);
}
}
// Pagination links for the next 500 records
$total_pages = $query->max_num_pages;
$current_page = $query_args['paged'];
if ($current_page < $total_pages) {
$next_page_url = add_query_arg('paged', $current_page + 1, $_SERVER['REQUEST_URI']);
echo '<a href="' . esc_url($next_page_url) . '">Next 500</a>';
}
} else {
echo "No more orders found."; // Indicate the end of the orders
}
}
if (isset($_GET["delete_old_non_hpos_orders"])) {
add_action('wp', function () {
if (!current_user_can('administrator')) return;
delete_old_non_hpos_orders();
die('Stop');
});
}Then visit: YOURWEBSITEURL/?delete_old_non_hpos_orders=yes it will delete as you are clicking trough the pages
- This reply was modified 1 year, 3 months ago by shadowbox0028.
Forum: Plugins
In reply to: [WooCommerce] HPOS cleaning post/postmeta dataThe delete old post meta or posts, is not working, it just ran 3 times and then does nothing to the database size with me. my postmeta table is 800mb and is about 90% orders and i disabled every optimalization plugin (yes also caching, combining, minifying).. can you explain what is wrong with the feature?