WPPizza – A Restaurant Plugin for WordPress › Support › Feature Requests › Additional filter suggestions
- AuthorPosts
- 12 February, 2016 at 10:12 am #15724
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']; }
12 February, 2016 at 1:30 pm #15728question 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 case15 February, 2016 at 12:39 pm #15795Small 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; }
15 February, 2016 at 2:36 pm #15797ok,
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 wholenew WPPIZZA_ORDER_DETAILS()
etc shebang26 April, 2016 at 4:02 pm #17657Hi,
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?
26 April, 2016 at 4:04 pm #17663i dont know what location exactly you are referring to .
in any event , that filter lets you select printers based on order variables27 April, 2016 at 1:22 pm #17682You 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. - AuthorPosts
- The topic ‘Additional filter suggestions’ is closed to new replies.