PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / markup / pickup_choice.php

pickup_choice.php in WPPizza – A Restaurant Plugin 3.20, at classes/markup/pickup_choice.php

167 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MARKUP_PICKUP Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPizza Pickup/Delivery toggles
7 * @copyright Copyright (c) 2015, Oliver Bach
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 3.0
10 *
11 */
12 if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/
13
14 /* ================================================================================================================================= *
15 *
16 *
17 *
18 * CLASS - WPPIZZA_MARKUP_PICKUP
19 *
20 *
21 *
22 * ================================================================================================================================= */
23
24 class WPPIZZA_MARKUP_PICKUP_CHOICE{
25
26 /******************************************************************************
27 *
28 *
29 * [construct]
30 *
31 *
32 *******************************************************************************/
33 function __construct() {
34 }
35
36 /******************************************************************************
37 *
38 *
39 * [methods]
40 *
41 *
42 *******************************************************************************/
43 /***************************************
44 [apply attributes]
45 ***************************************/
46 function attributes($atts, $type){
47 global $wppizza_options;
48 /** set as var - php 5.3 */
49 $shop_open = wppizza_is_shop_open();
50 /*
51 allow the pickup toggle to always be shown, even if shop is closed
52 provided toggle is enabled in cart/orderpage in the first place
53 */
54 if($type == 'cart' || $type == 'orderpage' ){
55 $force_pickup_toggle = apply_filters('wppizza_filter_force_pickup_toggle_display', false);
56 if($type == 'cart'){
57 $force_pickup_toggle = ($wppizza_options['order_settings']['order_pickup_display_location'] == 2) ? false : $force_pickup_toggle ;//check if actually enabled in cart in the first place
58 }
59 if($type == 'orderpage'){
60 $force_pickup_toggle = ($wppizza_options['order_settings']['order_pickup_display_location'] == 1) ? false : $force_pickup_toggle ;//check if actually enabled on orderpage in the first place
61 }
62 }
63 /* no toggle if closed, not displayed on a particular page , not enabled anyway and not force enabled */
64 if(
65 empty($wppizza_options['order_settings']['order_pickup']) || /* pickup/switch not enabled */
66 $wppizza_options['order_settings']['delivery_selected']=='no_delivery' || /* no delivery offered */
67 ($type == 'cart' && $wppizza_options['order_settings']['order_pickup_display_location']==2) || /* not displayed under cart */
68 ($type == 'orderpage' && $wppizza_options['order_settings']['order_pickup_display_location']==1) || /* not displayed on orderpage */
69 empty($shop_open) /* shop closed */
70 ){
71
72 if(empty($force_pickup_toggle)){
73 return;
74 }
75 }
76
77 /**get markup**/
78 $markup = $this->get_markup($atts, $type);
79
80 return $markup;
81 }
82
83 /***************************************
84 [markup]
85 ***************************************/
86 function get_markup($atts, $type){
87 global $wppizza_options;
88 static $unique_id=0;$unique_id++;
89 $txt = $wppizza_options['localization'];
90
91 /*
92 checked or not | invert when self pickup is default
93 */
94 $is_pickup = WPPIZZA() -> session -> is_pickup();
95 $checkbox_is_pickup = empty($wppizza_options['order_settings']['order_pickup_as_default']) ? $is_pickup : ($is_pickup ? false : true );
96
97 /*
98 label: alternate label if pickup is default
99 */
100 $label = empty($wppizza_options['order_settings']['order_pickup_as_default']) ? $txt['order_self_pickup'] : $txt['order_request_delivery'];
101 /*
102 checkbox: put here as it should not really be edited
103 */
104 $option = '<label><input type="checkbox" class="'.WPPIZZA_PREFIX.'-order-pickup" name="'.WPPIZZA_PREFIX.'-order-pickup" value="1" ' . checked($checkbox_is_pickup,true,false) . ' />'.$label.'</label>';
105
106 /*
107 using 2 radios instead, unless toggle is specifically set to 0
108 */
109 /* default */
110 $force_toggle = !empty($wppizza_options['order_settings']['order_pickup_toggled']) ? true : false;
111 /* set to radio toggle */
112 $force_toggle = (isset($atts['toggle']) && $atts['toggle']==1 ) ? true : $force_toggle; /* if distinctly set to 1 */
113 /* set to checkbox toggle */
114 $force_toggle = (isset($atts['toggle']) && $atts['toggle']==0 ) ? false : $force_toggle; /* if distinctly set to 0 */
115
116 if($force_toggle ){
117 $option = '';
118 $selected = (!$is_pickup) ? ' '.WPPIZZA_PREFIX.'-pickup-toggle-selected' : '' ;
119 $option .= '<label class="'.WPPIZZA_PREFIX.'-pickup-toggle'.$selected.'"><input type="radio" class="'.WPPIZZA_PREFIX.'-order-pickup '.WPPIZZA_PREFIX.'-toggle-delivery" name="'.WPPIZZA_PREFIX.'-order-pickup" value="0" ' . checked(!$is_pickup,true,false) . ' /><span>'.$txt['pickup_toggle_delivery'].'</span></label>';
120 $selected = ($is_pickup) ? ' '.WPPIZZA_PREFIX.'-pickup-toggle-selected' : '' ;
121 $option .= '<label class="'.WPPIZZA_PREFIX.'-pickup-toggle'.$selected.'"><input type="radio" class="'.WPPIZZA_PREFIX.'-order-pickup '.WPPIZZA_PREFIX.'-toggle-pickup" name="'.WPPIZZA_PREFIX.'-order-pickup" value="1" ' . checked($is_pickup,true,false) . ' /><span>'.$txt['pickup_toggle_pickup'].'</span></label>';
122 }
123
124 /*********************
125 set unique id
126 *********************/
127 $id = WPPIZZA_PREFIX.'-orders-pickup-choice-'.$unique_id;
128
129 /*********************
130 set classes
131 *********************/
132 $class= array();
133 $class[] = WPPIZZA_PREFIX.'-orders-pickup-choice';
134 if(!empty($atts['class'])){
135 $class[] = esc_html($atts['class']);
136 }
137 if($force_toggle){
138 $class[] = WPPIZZA_PREFIX.'-orders-pickup-choice-toggle';
139 }
140 $class = trim(implode(' ', $class));
141
142 /*********************
143 ini markup array
144 *********************/
145 $markup = array();
146
147 /*********************
148 get markup
149 *********************/
150 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/global/pickup_choice.php')){
151 require(WPPIZZA_TEMPLATE_DIR.'/markup/global/pickup_choice.php');
152 }else{
153 require(WPPIZZA_PATH.'templates/markup/global/pickup_choice.php');
154 }
155
156 /*********************
157 apply filter if required and implode for output
158 *********************/
159 $markup = apply_filters('wppizza_filter_pickup_choice_widget_markup', $markup, $atts, $unique_id, $is_pickup);
160 $markup = trim(implode('', $markup));
161
162 return $markup;
163
164
165 }
166 }
167 ?>