Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 19, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/9a20d5f173498dd8a68074d4b87dafb1 to your computer and use it in GitHub Desktop.
Save xadapter/9a20d5f173498dd8a68074d4b87dafb1 to your computer and use it in GitHub Desktop.
Snippet to send estimated delivery on top to admin for new order and to customer for processing order status. Estimated Delivery Date Plugin for WooCommerce by PluginHive - https://www.pluginhive.com/product/estimated-delivery-date-plugin-woocommerce/
/**
* Snippet to send estimated delivery on top to admin for new order and to customer for processing order status.
* Created at : 30 July 2018
* Updated at : 30 July 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/9a20d5f173498dd8a68074d4b87dafb1
*/
add_action( 'woocommerce_email_order_details', 'ph_add_estimated_delivery_after_heading', 1, 4 );
if( ! function_exists('ph_add_estimated_delivery_after_heading') ) {
function ph_add_estimated_delivery_after_heading( $order, $sent_to_admin, $plain_text, $email ) {
// Supported Tags [DATE] in case of simple, [DATE_1] and [DATE_2] in case of date range and simple range
$estimated_delivery_text = "<strong>Estimated delivery :</strong> [DATE_1] - [DATE_2]<br/><br/>"; // Text to be printed on email html supported
$estimated_delivery_format = 'date_range'; // Possible value - simple or simple_range or date_range
// Attach estimated delivery to email sent to admin for new order and Customer for processing order status
if( $email instanceof WC_Email_New_Order || $email instanceof WC_Email_Customer_Processing_Order ) {
$estimated_delivery = $order->get_meta("_est_date"); // Get estimated delivery from order
if( ! empty($estimated_delivery) )
{
// Simple range and date range
if( $estimated_delivery_format == 'date_range' || $estimated_delivery_format == 'simple_range' ) {
$exploded_est_delivery = array_map( 'trim', explode( '-', $estimated_delivery ) );
// Two date or days count should be available in case of range
if( count($exploded_est_delivery) == 2 ) {
// Remove days in case of simple range
if( $estimated_delivery_format == 'simple_range' ) {
$exploded_est_delivery[1] = str_replace( " days", "", $exploded_est_delivery[1] );
}
$message = str_replace( array( "[DATE_1]", "[DATE_2]"), array( $exploded_est_delivery[0], $exploded_est_delivery[1] ), $estimated_delivery_text );
}
}
// Simple
elseif( $estimated_delivery_format == "simple" ) {
$estimated_delivery = trim($estimated_delivery);
$message = str_replace( "[DATE]", $estimated_delivery, $estimated_delivery_text );
}
// Print the message in email sent
if( ! empty($message) ) {
echo $message;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment