Additional filter suggestions

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #15724
    RosaKick
    Participant

      May I suggest an extra filter for printer selection in the Cloud Print add on.

      For example in wppizza-google-cloudprint.php @ 511 replace

      /*get the first printer*/
      $printerid = $printers[0]['id'];

      with

      $printerid=apply_filters('wppizza_gcp_filter_printerselect',$printers);
      /*if no $printerid returned by filter, get the first printer*/
      if(!isset($printerid) || $printerid = '') {
      $printerid = $printers[0]['id'];
      }
      #15728
      Olly
      Admin & Mod

        question for you (as i dont even have a printer).

        have you actually tried this code and does it work to select from different printers ?
        happy to add this (or similar) if that is the case

        #15795
        RosaKick
        Participant

          Small edit, adding $orderId to the hook as it doesn’t seem to be global.

          $printerid=apply_filters('wppizza_gcp_filter_printerselect',$printers,$orderId);
          /*if no $printerid returned by filter, get the first printer*/
          if(!isset($printerid) || $printerid == '') {
          $printerid = $printers[0]['id'];
          }

          Yes, I’ve successfully selected different printers with this filter through the following function:

          function wppizza_printerselect($printers,$orderId) {
          require(WPPIZZA_PATH.'classes/wppizza.order.details.inc.php');
          $orderDetails=new WPPIZZA_ORDER_DETAILS();
          $orderDetails->setOrderId($orderId);
          $order=$orderDetails->getOrder();/**all order vars**/
          /********************************
          simplify vars to us in template
          ********************************/
          $location=$order['customer']['post']['ccustom1']['value'];//omit ['others'] here
          $delivery=$order['ordervars']['pickup_delivery']['value'];
          $deliveryarea=reset(explode(' ',$order['customer']['post']['wppizza-dbp-area']['value']));
          if($delivery == 'Heimsending') {
          $koparray = Array(109,111,200,201,202,203);
          $hfjarray = Array(210,220,221,222,225);
          if(in_array($deliveryarea,$koparray)) {
          return searchForId('Dalvegur',$printers);
          } elseif (in_array($deliveryarea,$hfjarray)) {
          return searchForId('Dalshraun',$printers);
          }
          } else {
          if (strpos($location, 'Dalvegur')) {
          return searchForId('Dalvegur',$printers);
          } elseif (strpos($location, 'Dalshraun')) {
          return searchForId('Dalshraun',$printers);
          }
          }
          }
          add_filter('wppizza_gcp_filter_printerselect','wppizza_printerselect',10,2);

          First it determines if the order is delivery, and if so, checks the post code and sends to the correct location. If not delivery, it sends the order print to the selected pickup location.

          The searchForId function is made by me. In the cloud print settings you can change the display name of a printer, and the function uses that name to determine which printer is which. Got this working with a EPSON TM-T20II USB printer.

          function searchForId($name, $array) {
          foreach ($array as $key => $val) {
          if ($val['displayName'] === $name) {
          return $val['id'];
          }
          }
          return null;
          }
          #15797
          Olly
          Admin & Mod

            ok,
            as of 3.4.1 i added the following filter just before $printerid = $printers[0]['id'];

            
            /**filter as required**/
            $printers = apply_filters('wppizza_gcp_filter_printers', $printers, $orderId, $order);
            

            which shuould let you do all your things there and also passes on the $order parameter so you can save yourself the whole new WPPIZZA_ORDER_DETAILS() etc shebang

            #17657
            mackildare
            Participant

              Hi,

              Just wondering if I’ve read this right. As of V3.4.1 is is possible to have multiple printers with the right one selected based on a location? Is this correct?

              #17663
              Olly
              Admin & Mod

                i dont know what location exactly you are referring to .
                in any event , that filter lets you select printers based on order variables

                #17682
                RosaKick
                Participant

                  You can do that using the added filter, but you would need to program your own function to handle that.

                  The way I do it:
                  I first check if it’s a pickup or delivery order.
                  If pickup, there is a required field to select location for pickup – determine printer from that.
                  If delivery, determine printer based on zip code.

                Viewing 7 posts - 1 through 7 (of 7 total)
                • The topic ‘Additional filter suggestions’ is closed to new replies.