Quote Originally Posted by schoolboy View Post
Thanks for the reply - and the various cautions.

To keep it relatively simple, and not specify a time of day (in addition to the day concerned), the following configuration is acceptable - being the day of the week only:

MODULE ACTIVE: Monday, Tuesday, Wednesday, Thursday.
MODULE INACTIVE: Friday, Saturday, Sunday

The module is out of "Big Royal Mail". The relevant code seems to be:
Quote Originally Posted by mc12345678 View Post
So looks like the code initially determines if the module is active or inactive based on the admin setting (Which in this case will be date related), then if other criteria are "met" the module is deactivated, such as too large of a weight, etc... See below with the colored text based on the criteria provided for day of week. Including time would be possible as well.. There still is the "issue" of how it is desired to handle say someone initiating the purchase at 2359 on Thursday night, but not getting to the final purchase until 0000+ the next day. If it is considered acceptable to have the purchase started but not completed until after that midnight cutoff, then a $_SESSION[] variable could be used as a standin that would expire with logout/timeout...
Would like to take my nickel back a little... Basically the previous code enabled the module regardless of the setting in the admin panel, which is less than ideal... Below is a more correct version. Sorry about that.
Code:
<?php
/*

GPL released as part of the big_royalmail_v2.3 package

see CREDITS.txt for the contributors and support forum.

*/


  class specialdelivery {
    var $code, $title, $description, $enabled, $num_zones ;


// class constructor
    function specialdelivery() {

      global $order, $total_weight, $messageStack ;

      $this->version = '2.3.8';
      $this->code = 'specialdelivery';
      $this->title = ( (defined('IS_ADMIN_FLAG') && IS_ADMIN_FLAG == true) ? @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TEXT_TITLE'). ' <b style="color:#ff4000">ver. '.$this->version.'</b>' : constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TEXT_TITLE') );
      $this->description = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TEXT_DESCRIPTION');
      $this->sort_order = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_SORT_ORDER');
      $this->icon = (( defined('DIR_WS_ICONS') ? DIR_WS_ICONS : 'images/icons/' ) . 'shipping_sdnd.gif');
      $this->tax_class = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TAX_CLASS');
      $this->dayofweek = date('N'); //mc12345678 added to use a single day-of-week value. 1= Monday, 7 = Sunday. if desired to instead use a session situation, then in addition to this line uncomment below:
//      if (isset($_SESSION['big_royal_day_of_week']) && $_SESSION['big_royal_day_of_week'] != '') {
//        $this->dayofweek = (int)$_SESSION['big_royal_day_of_week'];
//      } else {
//        $_SESSION['big_royal_day_of_week'] = $this->dayofweek;
//      }
      $this->enabled = (($this->dayofweek >= 1 && $this->dayofweek <= 4) && @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_STATUS') == 'True') ? true : false; //mc12345678 15-06-30 evaluates true for customers if within the day of the week desired and activated in admin, otherwise false.  This "setting" could also be incorporated into the module as criteria; however, would require a bit of rewriting and other logic.


      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
      $this->num_zones = 1;

// inspired by Jim Barrington (JollyJim)

      if( isset($order) && @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_HIDE_SHIPPING_ERRORS') == 'True' ){

        switch(isset($order->info['subtotal'])){

        case true:
          if( $order->info['subtotal'] < @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MIN_ORDERVALUE')){
              $this->enabled = false;
            return ;
          }else
          if(MODULE_SHIPPING_SPECIALDELIVERY_MAX_ORDERVALUE != -1 && $order->info['subtotal'] > @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MAX_ORDERVALUE')){
              $this->enabled = false;
            return ;
          }
        break;

        case false:
          if($order->info['total'] < @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MIN_ORDERVALUE')){
              $this->enabled = false;
              return ;
          }else
          if(MODULE_SHIPPING_SPECIALDELIVERY_MAX_ORDERVALUE != -1 && $order->info['total'] > @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MAX_ORDERVALUE')){
              $this->enabled = false;
              return ;
          }
        break;

        } // end of switch on subtotal


        // check that it is a valid country being shipped to.
        $dest_country = $order->delivery['country']['iso_code_2'];
        $dest_zone = 0;
  
        for ($i=1; $i<=$this->num_zones; $i++) {
          $countries_table = constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COUNTRIES_' . $i);
          $country_zones = preg_split("/,/", preg_replace('/\s*/','',$countries_table) );
          if (in_array($dest_country, $country_zones)) {
            $dest_zone = $i;
            break;
          }
        }

        // ship to country is invalid for this service
        if ($dest_zone == 0) {
              $this->enabled = false;
            return ;
        }else{

        $this->enabled = false;  // enabled set to true if valid shipping weight found

        $zones_cost = constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST0_' . $dest_zone)
          . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST1_' . $dest_zone)
          . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST2_' . $dest_zone)
          . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST3_' . $dest_zone)
          . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST4_' . $dest_zone);


        $zones_table = preg_split("/[:,]/" , preg_replace('/\s*/', '', $zones_cost) );

        $size = sizeof($zones_table);
        for ($i=0; $i<$size; $i+=2) {
          if ($total_weight <= $zones_table[$i]) {
            $this->enabled = true;
            break;
          }
        } // end of looping through

        return ;

      } // end of valid country

     } // end of if hide invalid shipping methods is set

    }