Skip to content

Instantly share code, notes, and snippets.

@rajeshsingh520
Last active July 31, 2026 09:04
Show Gist options
  • Select an option

  • Save rajeshsingh520/500624b945a2832e4c2c9c8da2ce0cf8 to your computer and use it in GitHub Desktop.

Select an option

Save rajeshsingh520/500624b945a2832e4c2c9c8da2ce0cf8 to your computer and use it in GitHub Desktop.
preparation time to consider non working days
class pisol_custom_20260731{
static $instance = null;
public $format = 'Y/m/d';
public $today;
public $type;
public $holidays;
public $allowed_dates;
static function get_instance(){
if(self::$instance == null){
self::$instance = new self();
}
return self::$instance;
}
function __construct(){
add_filter('pisol_dtt_setting_filter_pi_order_preparation_days', [$this, 'days']);
}
function days($preparation_days){
$this->today = current_time($this->format);
$this->type = pi_dtt_delivery_type::getType();
$this->holidays = $this->getHolidays($this->type);
$this->allowed_dates = $this->allowedDates($this->type);
for($i = 0; $i < $preparation_days; $i++){
$date = date($this->format, strtotime($this->today.' + '.$i.' days'));
if($this->isHoliday($date) || $this->nonWorkingDay($date)){
$preparation_days++;
}
}
return $preparation_days;
}
function isHoliday($date){
$holidays = $this->holidays;
if(is_array($holidays) && in_array($date,$holidays)){
return true;
}
return false;
}
function getHolidays($type){
$var_name = 'pisol_dtt_'.$type.'_dd';
$holidays = get_option($var_name, array());
return $holidays;
}
function nonWorkingDay($date){
$week = date('w', strtotime($date));
$allowed_days = $this->allowed_dates;
if(is_array($allowed_days) && in_array($week, $allowed_days)){
return false;
}
return true;
}
function allowedDates($type){
$var_name = 'pi_'.$type.'_days';
$allowed_days = get_option($var_name, array());
if(empty( $allowed_days )){
return array(0,1,2,3,4,5,6);
}else{
return $allowed_days;
}
}
}
pisol_custom_20260731::get_instance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment