A few weeks ago one of our followers raised a database problem in a Google+ group.

In his post José Costa Ros raised a serious problem that had come up for one of his clients, specifically the online shop TuBabyShop, with the ID field of the wp_posts table, which had reached a total length of 13 digits, which made it impossible for him to take payment for orders through Redsys.

The problem is caused by the strict rules of Redsys when it comes to processing orders, since it makes the use of 4 digits and 8 characters essential, and as the ID field had a code 13 digits long it was materially impossible to complete the orders in WooCommerce, since the code received, the first 4 digits of the 13 of the order number, made it impossible to know which order the payment referred to and so they were always left waiting for payment.

The best solution that can be given to a problem like the one our friend José raised is to renumber the ID field of the wp_posts table of the database, but how?

Solution

To do so, the first thing we did was look at what had happened in the wp_posts table and we discovered that the problem had arisen almost a year earlier when, all of a sudden, it jumped from code 1302 to a completely wild number 13 digits long. The problem most likely arose as a result of some badly executed SQL query or some kind of one-off failure in the MySQL server, although we did not dig much further either since we found no more related problems.

Once the problem had been located we proceeded to create a small PHP script with some SQL queries that we placed in the WordPress root directory and that would automate the task of renumbering the ID field from number 1303 onwards, but not only in the wp_posts table, but in all the other tables of the database that are related to it. Specifically the PHP code we used was this:

Copy to clipboard

Thanks to it we were able to reorder the ID field of the wp_posts table and of all the other tables related to this same field. In addition we modified the table’s auto-increment value to prevent those 13-digit codes from continuing to appear.

The truth is that right now this situation is no longer a problem if you use the WooCommerce Sermepa payment gateway plugin and its new feature, requested by us ourselves. Another day we will publish a couple of functions for getting round this same problem using the new wc_myredsys_merchant_order_encode and wc_myredsys_merchant_order_decode filters.

We hope you find this small PHP script useful and that it gets you out of more than one tight spot.

Related posts

Comments

Suscríbete
Notificar de
2 Comments
Más antiguos
Más recientes Más votados
Jose Costa Ros
31 de mayo de 2016 17:05

Excelente solución dada en http://www.tubabyshop.es al problema que se nos planteó.

Me alegra que transmitas conocimiento y experiencia, tus soluciones ayudan a resolver estos problemas y aportan valor. Además siempre podemos contar con tu excelente soporte y soluciones profesionales.

Gracias!!

Art Project Group
31 de mayo de 2016 17:07
Responder a  Jose Costa Ros

Gracias a vosotros por la confianza que siempre depositáis en Art Project Group.

Un saludo.

In this post

Products and services

Latest posts

Latest comments

Subscribe!

Lista de correos de APG

DATA PROTECTION: In accordance with data protection regulations, we provide you with the following processing information: (+)

  • Responsible: Art Project Group.
  • Treatment purposes: to respond to queries or any type of request made by the user through any of the forms of contact that are made available on the website. Sending communications about products or services (with your consent).
  • Your rights: access, rectification, portability, deletion, limitation and opposition. More information about the treatment in the Privacy Policy.

What we post on !

Se ha publicado #WooCommerce 11.2.2: actualización de seguridad que refuerza las API REST y Store, mejora la validación de CSV y corrige problemas en pagos y pedidos. Incluye cambios en la base de datos.

¡Actualiza cuanto antes!

November 5, 2026