How to use WooCommerce to only allow next day delivery if before 1pm and day after tomorrow if ordered after 1pm. For a client, we were working as WooCommerce developers. One of the problem was this simple request.
We tried to find a switch for this in settings but couldn’t. We also didn’t want to install a whole WooCommerce plugin for this small functionality. So ended up writing this simple code. You may use it in the functions.php to set WooCommerce for next day delivery.
add_action( 'woocommerce_thankyou', 'custom_woocommerce_orderlordapi' );
function custom_woocommerce_orderlordapi( $order_id ) {
// Lets grab the order
$order = wc_get_order( $order_id );
/**
* Put your tracking code here
* You can get the order total etc e.g. $order->get_total();
*/
foreach ( $order->get_items() as $item_id => $order_item ) {
//$custom_field = get_post_meta( $item_id, 'Delivery Date', true);
if(wc_get_order_item_meta( $item_id, 'Delivery Date', true )){
$delivery_date = wc_get_order_item_meta( $item_id, 'Delivery Date', true );
if(date('D') == 'Fri' && date('H') > 13) {
$modified_delivery_date = date('Y-m-d', strtotime($delivery_date . ' +3 day'));
wc_update_order_item_meta($item_id, 'Delivery Date', $modified_delivery_date);
}
elseif(date('D') == 'Sat') {
$modified_delivery_date = date('Y-m-d', strtotime($delivery_date . ' +2 day'));
wc_update_order_item_meta($item_id, 'Delivery Date', $modified_delivery_date);
}
elseif (date('H') > 13) {
$modified_delivery_date = date('Y-m-d', strtotime($delivery_date . ' +2 day'));
wc_update_order_item_meta($item_id, 'Delivery Date', $modified_delivery_date);
}
else{
$modified_delivery_date = date('Y-m-d', strtotime($delivery_date . ' +1 day'));
wc_update_order_item_meta($item_id, 'Delivery Date', $modified_delivery_date);
}
}
}
}
This will set the WooCommerce delivery date based on the client settings. Let us know what you think.
Our support staff is available 24/7 to take support calls and messages from clients.
We involve client in all stages of software development to deliver satisfaction and peace of mind.
We hire developers that are technically strong and discuss the project thoroughly before starting.
If you are not happy with the quality of work or we fail to achieve final technical goal, we’ll not take your money.
We have worked with some clients for over 7 years. Our commitment and dedication is a matter of pride for us.
We care about your investment. We will tell it straight if you are making a bad decision.
NDA implied. No spam. Privacy guaranteed.
Best web, app, eCommerce and custom software development company. We provide services to more than 100 clients world-wide.
Contact The Right Software today to discuss the your next big idea.