Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 19, 2019 12:32
Show Gist options
  • Select an option

  • Save xadapter/dc915ec735c5aba2d8d191d7563e563d to your computer and use it in GitHub Desktop.

Select an option

Save xadapter/dc915ec735c5aba2d8d191d7563e563d to your computer and use it in GitHub Desktop.
Snippet to show WooCommerce Estimated Delivery after Email text you have received an order(default) in New Order Email sent to admin. All Text Format( simple, simple_range and date_range ) supported. Estimated Delivery Date Plugin for WooCommerce - https://www.pluginhive.com/product/estimated-delivery-date-plugin-woocommerce/
/**
* Snippet to show woocommerce estimated delivery after email text you have received an order (default) in New Order Email sent to admin. All Text Format( simple, simple_range and date_range ) supported
* Created at : 19 July 2018
* Updated at : 19 July 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/dc915ec735c5aba2d8d191d7563e563d/
*/
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
if( $sent_to_admin && $email instanceof WC_Email_New_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;
}
}
}
}
}
@xadapter

xadapter commented Jul 19, 2018

Copy link
Copy Markdown
Author

Estimated delivery will be shown as in below screenshot
estimated delivery on top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment