Skip to content

Instantly share code, notes, and snippets.

@renjith-ph
Last active January 14, 2019 07:15
Show Gist options
  • Save renjith-ph/f731cbec762b7036216709cdda7ee1e8 to your computer and use it in GitHub Desktop.
Save renjith-ph/f731cbec762b7036216709cdda7ee1e8 to your computer and use it in GitHub Desktop.
Snippet to change cutoff time based on shipping method.PluginHive Plugins : https://www.pluginhive.com/plugins/
/**
* Snippet to change cutoff time based on shipping method.
* Created at : 28 Nov 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
*/
add_filter( 'ph_estimated_delivery_get_cutoff_time', 'ph_estimated_delivery_get_custom_cutoff_time', 10, 2 );
if( ! function_exists('ph_estimated_delivery_get_custom_cutoff_time') ) {
function ph_estimated_delivery_get_custom_cutoff_time( $cutoff, $cur_day ) {
$adjustment = array(
'table_rate:2:1'=>array( 'mon'=>"18:00", 'tue'=>"18:00", 'wed'=>"18:00", 'thu'=>"18:00", 'fri'=>"18:00", 'sat'=>"18:00", 'sun'=>"18:00" )
); // provide cutoff time for each shipping methods.
$shipping_method=WC()->session->get( 'chosen_shipping_methods' );
if(!empty($shipping_method))
{
$shipping_method=$shipping_method[0];
}
if(!empty($shipping_method) && isset($adjustment[$shipping_method]) ) {
$cutoff_time = !empty($adjustment[$shipping_method][$cur_day] ) ? $adjustment[$shipping_method][$cur_day] : '';
$cutoff_time = !empty( $cutoff_time ) ? $cutoff_time : '20:00';
$cutoff_time = str_replace('.', ':', $cutoff_time);
$cutoff=(strstr($cutoff_time, ':') ) ? explode( ':', $cutoff_time ) : array($cutoff_time, '');
}
return $cutoff;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment