Support » Plugin: WooCommerce » Unable to create order

  • Resolved Steveo123

    (@steveo123)


    We upgraded our dev site to Woocommerce 3.4.4. Since then when we try sending a test order through we are getting “Unable to create order” on the checkout page after we enter the billing information. I am not seeing anything in the logs. Any ideas?

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • I also just noticed that for my test order I am not able to delete the item from my shopping cart.

    Same problem here on a live shop, any news on the problem ?

    I found some issues with my database. Auto increment was not set on some of the table primary keys. Now I’m getting a different error (internal server error). Still working on that one.

    Plugin Support John Coy

    (@johndcoy)

    Automattic Happiness Engineer

    Hi @steveo123

    This isn’t something I’ve been ablet to replicate.

    After viewing your dev site’s checkout process I see that the console shows a few JS errors. Typically issues like this are caused by a theme or plugin conflict. try switching back to a default theme like Twenty Seventeen and disable all plugins except for WooCommerce to see if this resolves the issue.

    If so, then re-enable each one at a time until you find the one that’s causing the conflict.

    Plugin Support Luminus

    (@luminus)

    Automattic Happiness Engineer

    @steveo123,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Hi I just restored my old backup website to a new WordPress site and everything is working fine except order is not working. When I test order I keep getting UNABLE TO CREATE ORDER.
    How do I fix it?
    http://www.m6network.com is the the website

    Thought I would share the love and post the real solution to this problem.
    The problem manifests when WooCommerce attempts to save the shop_order post type to wp_posts table.
    When someone hits checkout, the woo data store attempts to save the order as a post:

    /wp-content/plugins/woocommerce/includes/data-stores/abstract-wc-order-data-store-cpt.php
    at public function create( &$order ) { line 56

    This is the code that inserts the order:
    $id = wp_insert_post(
    apply_filters(
    ‘woocommerce_new_order_data’,
    array(
    ‘post_date’ => gmdate( ‘Y-m-d H:i:s’, $order->get_date_created( ‘edit’ )->getOffsetTimestamp() ),
    ‘post_date_gmt’ => gmdate( ‘Y-m-d H:i:s’, $order->get_date_created( ‘edit’ )->getTimestamp() ),
    ‘post_type’ => $order->get_type( ‘edit’ ),
    ‘post_status’ => ‘wc-‘ . ( $order->get_status( ‘edit’ ) ? $order->get_status( ‘edit’ ) : apply_filters( ‘woocommerce_default_order_status’, ‘pending’ ) ),
    ‘ping_status’ => ‘closed’,
    ‘post_author’ => 1,
    ‘post_title’ => $this->get_post_title(),
    ‘post_password’ => wc_generate_order_key(),
    ‘post_parent’ => $order->get_parent_id( ‘edit’ ),
    ‘post_excerpt’ => $this->get_post_excerpt( $order ),
    )
    ), true
    );

    Now you will notice that the insert creates a value in post_password field using wc_generate_order_key()
    If you look in your database you will notice that the post_password table is a varchar with max length of 20 chars. I found that wc_generate_order_key() was generating a password LONGER than 20 chars and therefore the insert was failing which manifests further up the chain as “Unable to create order”

    Internally wc_generate_order_key() does this:
    function wc_generate_order_key() {
    return ‘wc_’ . apply_filters( ‘woocommerce_generate_order_key’, ‘order_’ . wp_generate_password( 13, false ) );
    }

    if you notice that wp_generate_password’s first parameter is the length of the password which in this case is 13
    the password is concatenated with “wc_” (length 3) and “order_” (length 6) so 13+3+6 = 22 chars of length

    So this got me thinking why would Woo write this code?
    Well it turns out that my wordpress version on the affected site was 4.7.12 ( we had ignored the updates to v5 as it as a heavy production site and we hadnt yet tested Gutenberg)
    I checked another site that was already at v5 of wordpress and sure enough the post_password field in wp_posts table is varchar(255) so later version of wordpress > 4.7.12 must have increased this field length:

    So the solution is:
    1. Update to latest WP version
    2. If you can update to latest WP Version because you havent tested it yet then go into PhpMyAdmin for your MySql database. You can find your Database name from wp-config.php
    Click on wp_posts or whatever prefix your posts table is using and click on “Structure” tab and modify the length of the post_password field to varchar(255)

    This drove me crazy and I see no solution anywhere on the internet for this.
    Hope this helps someone have a more productive day than I did lol
    🙂 🙂

    Thanks a lot!!! I don’t know what went wrong when I updated to WP 5, but thanks to you I just corrected the problem. THANKS THANKS a thousend times! I just used phpmyadmin to change the post_password field in wp_posts table as varchar(255) I would have taken me many hours to find out

    Thank you johnpaulbyrne

    2 months ago I had this problem in one of my client’s site. I lose some days of work and at the end I had to rebuild all site.

    Now I had this problem in another site, and in 5 minutes off “Googling”, I found your message here. And I took just one more minute to solve that bug.

    Thank you very much for sharing your solution. You save my day 🙂

    I am facing the same issue with my website from last 5-6 days. I came across this page and did the thing but in my database the post_password is already set to varchar(255).
    Please help me in resolving this issue.

    I’m having the same issue and I’m running the latest WP so I would assume that the lenght is sufficient. It all started some days ago and I can’t fix it. Store is not functioning as it should.

    I’m getting a red feild at the top saying “Cant place order” when I try to call on my payment service and finalize the order. Very frustrating.

    So I had the online service look into the database and the field was not uppdated. They did that change and now it works fine.

    One thousand thanks for the heads up!

    Thank you @johnpaulbyrne
    It worked for me too!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Unable to create order’ is closed to new replies.