I'm trying to add the meta Ready_by
to an order by taking the time set by Order Due Date
and deducting an hour from it. This Order Due Date
is set using the plugin Order Delivery Date Pro, which adds a calendar date/time picker to checkout.
I've been trying between the hooks woocommerce_checkout_create_order
and woocommerce_thankyou
and couldn't get it work.
Here is the code I have so far in functions.php:
// Assign default ready by time by deducting an hour from the delivery due time
add_action('woocommerce_thankyou', 'define_default_ready_by_time', 10, 1);
function define_default_ready_by_time( $order_id ) {
$order = wc_get_order($order_id);
$order_due_time = get_post_meta($order, 'Order Due Date', true);
$ready_by_default = date('H:i',strtotime('-1 hour',strtotime(date('Y-m-d H:i:s',strtotime(str_replace('/','-',$order_due_time))))));
$order->update_meta_data( 'Ready_by', $ready_by_default);
}
If anyone can shed a light on this, it'd be greatly appreciated. Thank you!