/** * AJAX: Clear all products with sync status 'failed'. */ public function ajax_clear_failed_products() { check_ajax_referer('wc_shopify_sync', 'nonce'); if (!current_user_can('manage_woocommerce')) { wp_send_json_error('Permission denied'); return; } // Get all products with sync status 'failed' $failed_products = get_posts(array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( array( 'key' => self::META_SYNC_STATUS, 'value' => 'failed', ), ), )); $cleared = 0; foreach ($failed_products as $product_id) { update_post_meta($product_id, self::META_SYNC_STATUS, 'pending'); delete_post_meta($product_id, self::META_LAST_SYNC_ERROR); $cleared++; } wp_send_json_success(array( 'cleared' => $cleared, 'failed_products' => $failed_products, )); }