• Resolved Olaf Lederer

    (@finalwebsites)


    Hi,

    My webshop is located in the Netherlands, and we use here a date format like dd-mm-yyyy. This can be configured correctly using the plugin’s options. However, I’m having a problem with the date being stored as text in a meta field and thus displayed incorrectly in the Woo Orders Rest API. The yyyy-mm-dd format is required for exchanging date fields.
    So, it works perfectly well for the date presentation om the site and in emails, but not for exchanging data with other systems, where the delivery date is very important.

    I’ve looked at the plugin’s code, but there’s no filter hook before saving the data. Do you have any other suggestions to solve this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Elena

    (@elenathemehigh)

    Could you please check after adding the below code in your child theme’s functions.php file?

    add_action('woocommerce_checkout_create_order', function( $order, $posted ) {
    // List of your date meta keys you want to fix
    $date_keys = array(
    'thwdtp_delivery_datepicker',
    'thwdtp_pickup_datepicker'
    );

    foreach ( $date_keys as $meta_key ) {
    $value = $order->get_meta( $meta_key );

    if ( ! empty( $value )) {
    $parts = explode('-', $value);
    if ( count($parts) === 3 ) {
    $new_value = $parts[2] . '-' . $parts[1] . '-' . $parts[0];
    $order->update_meta_data( $meta_key, $new_value );
    }
    }
    }

    $order->save(); // Save the updated meta

    }, 20, 2);

    Kindly check and verify it from your end?

    Have a great day!

    Thread Starter Olaf Lederer

    (@finalwebsites)

    Hi Elena,

    It’s a very nice workaround. I changed your snippet a little bit and used the PHP date and strtotime functions to format the new date.

    Thanks a lot!

    Elena

    (@elenathemehigh)

    Glad to hear that!

    Have a great day.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.