FedEx plugin integration
add_filter('woocommerce_package_rates', 'hide_shipping_method_based_on_estimate_delivery', 10, 2);
function hide_shipping_method_based_on_estimate_delivery($available_shipping_methods){
$cart_items = WC()->cart->cart_contents;
if ( $cart_items ) foreach ( $cart_items as $cart_item_key => $cart_item ) {
if ( isset( $cart_item['_ebs_start'] ) ) {
$start_date = strtotime( $cart_item['_ebs_start'] );
$est_day_limit = strtoupper( date( 'D', $start_date ) ); //provide the day limit to hide all services after this day
$day_order = array(
'0' => array('SUN', 'Sun'),
'1' => array('MON', 'Mon'),
'2' => array('TUE', 'Tue'),
'3' => array('WED', 'Wed'),
'4' => array('THU', 'Tue'),
'5' => array('FRI', 'Fri'),
'6' => array('SAT', 'Sat'),
);
$day_priority = array();
foreach ($day_order as $order => $day_arr) {
$day_priority[reset($day_arr)] = $order;
}
foreach ($available_shipping_methods as $key => &$method) {
$est_delivery = $method->get_meta_data();
if( isset($day_priority[$est_delivery['delivery_time']] ) && $day_priority[$est_delivery['delivery_time'] ] > $day_priority[$est_day_limit]){
unset( $available_shipping_methods[$key] );
}
}
}
}
return $available_shipping_methods;
}