Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 20, 2019 13:58
Show Gist options
  • Save xadapter/a3aebdd786e553056b49617cfea0cc8b to your computer and use it in GitHub Desktop.
Save xadapter/a3aebdd786e553056b49617cfea0cc8b to your computer and use it in GitHub Desktop.
Snippet to display estimated delivery in different format (simple and date range, settings should be in date range ) on product page based on shipping class. Estimated Delivery Date Plugin for WooCommerce - https://www.pluginhive.com/product/estimated-delivery-date-plugin-woocommerce/
/**
* Snippet to display estimated delivery in different format (simple and date range, settings should be in date range ) on product page based on shipping class.
* Created at : 13 July 2018
* Updated at : 13 July 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/a3aebdd786e553056b49617cfea0cc8b
*/
add_filter( 'woocommerce_get_availability', 'ph_change_estimated_delivery_style_based_on_shipping_class', 11, 2 );
if( ! function_exists('ph_change_estimated_delivery_style_based_on_shipping_class') ) {
function ph_change_estimated_delivery_style_based_on_shipping_class( $stock_arr, $item ) {
$product_page_text_without_date_tags = "Estimated delivery by";
$date_seperator = '-';
$shipping_class_arr = array('test','shoe'); // Shipping classes for which simple date has to be shown
$estimated_delivery_date = 'lower'; // Accepted value lower or higher
$shipping_class = $item->get_shipping_class();
if( ! empty($shipping_class) && in_array( $shipping_class, $shipping_class_arr) && ! empty($stock_arr['availability']) ) {
$exploded_text_arr = explode( $product_page_text_without_date_tags, $stock_arr['availability']);
$new_estimated_delivery = $exploded_text_arr[0].$product_page_text_without_date_tags.' ';
if( ! empty($exploded_text_arr[1]) ) {
$exploded_text_arr = explode( "</small>", $exploded_text_arr[1]);
$exploded_date = explode( $date_seperator, $exploded_text_arr[0] );
$exploded_date = array_map( 'trim', $exploded_date);
if( $estimated_delivery_date == "lower" && ! empty($exploded_date[0]) ) {
$new_estimated_delivery .= $exploded_date[0]."</small>";
}
elseif( $estimated_delivery_date == "higher" && ! empty($exploded_date[0]) ){
$new_estimated_delivery .= $exploded_date[1]."</small>";
}
if( ! empty($exploded_text_arr[1]) ) {
$new_estimated_delivery .= $exploded_text_arr[1];
}
$stock_arr['availability'] = $new_estimated_delivery;
}
}
return $stock_arr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment