Support » Plugin: Order Delivery Date for WooCommerce » Time Slot timestamp does not adjust for site timezone

  • Resolved Carl Brubaker

    (@imconfused4sure)


    I am trying to integrate WooCommerce with Shipday and am having trouble with the selected delivery time displaying correctly in Shipday. I have isolated the problem to the _orddd_lite_timeslot_timestamp is not adjusting for the timezone of my site. Instead it is saving the timestamp as UTC+0, not America/New_York where the site will be located. Currently this site is still in development, but here is all of the troubleshooting I have done to get me to this point.

    order-delivery-date-for-woocommerce/includes/class-orddd-lite-process.php

    
    # current line 186
    $timestamp = strtotime( $delivery_date );
    
    # correction line 186
    $timestamp = new DateTime( $delivery_date, new DateTimeZone(wp_timezone_string()));
    
    # correction line 188
    update_post_meta( $order_id, '_orddd_lite_timeslot_timestamp', $timestamp->format( 'U' );
    

    I ran this code against the original:

    
    # Date: 8 April, 2020 17:00
    $strtotime_way_in_plugin === 1649437200
    $datetime_way_w_timezone === 1649451600
    

    If there is a way I can set the timezone in the plugin let me know. Until then I will have to overwrite the plugin files.

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author tychesoftwares

    (@tychesoftwares)

    Hi @imconfused4sure,

    Currently, it’s not possible to set the timezone in the plugin. The plugin will consider WordPress Local Timezone. However, I’m escalating this as an enhancement to our development team so that they will see if they can give a setting or filter in the plugin to set a timezone.

    Thank you for sharing the solution as well as suggestions here.

    Thread Starter Carl Brubaker

    (@imconfused4sure)

    Thanks for the escalation. And no, the plugin does not currently consider WordPress Local Timezone when storing the time slot in the database. It always saves it as UTC 0.

    Plugin Author tychesoftwares

    (@tychesoftwares)

    Oh, then can you create the ticket here on our support tool so that we can check it?

    Thread Starter Carl Brubaker

    (@imconfused4sure)

    After some discussion with the support team, they are updating an action hook to include the $order_id and this is the resulting hook I came up with. This is mostly a modification of their code that I copied and pasted.

    add_action('orddd_after_timeslot_update', 'action_orddd_after_timeslot_update', 10, 2);
    
    /**
     * Sets _orddd_lite_timeslot_timestamp time zone to the time zone setting in the WordPress Admin
     * Settings instead of the default UTC-0.
     * @param string $time_slot Delivery time slot.
     * @param int    $order_id  Order ID to update post meta.
     */
    function action_orddd_after_timeslot_update($time_slot, $order_id)
    {
        if (empty($time_slot) || !isset($_POST['h_deliverydate'])) {
            return;
        }
        $h_deliverydate = $_POST['h_deliverydate'];
    
        if (!in_array($time_slot, ['asap', 'choose', 'NA', 'select'], true)) {
            $order_time_slot = $time_slot;
            $time_format     = get_option('orddd_lite_delivery_time_format');
            $time_slot_arr   = explode(' - ',$time_slot);
    
            $from_time = date('H:i',strtotime($time_slot_arr[0])); //phpcs:ignore
    
            $delivery_date = $h_deliverydate.' '.$from_time;
            $timestamp = new DateTime($delivery_date, new DateTimeZone(wp_timezone_string()));
    
            update_post_meta($order_id, '_orddd_lite_timeslot_timestamp', $timestamp->format('U'));
        }
    }
    Plugin Author tychesoftwares

    (@tychesoftwares)

    Hi @imconfused4sure,

    Thank you so much for sharing the solution here. It would be helpful to others.

    Plugin Support oluisrael

    (@oluisrael)

    @imconfused4sure, thanks for sharing the code. We will be adding the hook in the next update as that will be helpful to others. I’ll mark this thread as resolved since this is good to go.

    Thread Starter Carl Brubaker

    (@imconfused4sure)

    @oluisrael @tychesoftwares When is this getting added to the plugin? It still isn’t there.

    Thanks,
    Carl

    Plugin Support oluisrael

    (@oluisrael)

    Hey @imconfused4sure, we’re yet to roll out an update, but rest assured that we will add this to the next update rollout.

    Thank you for being so understanding.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.