| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_ORDERSETTINGS_PICKUP Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_ORDERSETTINGS_PICKUP |
| 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 |
* |
| 19 |
* |
| 20 |
* |
| 21 |
* |
| 22 |
************************************************************************************************************************/ |
| 23 |
class WPPIZZA_MODULE_ORDERSETTINGS_PICKUP{ |
| 24 |
|
| 25 |
private $settings_page = 'order_settings';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
private $localization_page = 'localization'; |
| 27 |
private $section_key = 'pickup';/* must be unique */ |
| 28 |
|
| 29 |
|
| 30 |
function __construct() { |
| 31 |
/********************************************************** |
| 32 |
[add settings to admin] |
| 33 |
***********************************************************/ |
| 34 |
if(is_admin()){ |
| 35 |
/* add admin options settings page*/ |
| 36 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 30, 5); |
| 37 |
/* add admin options settings page fields */ |
| 38 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 39 |
/* add admin options localization page - does not need fields action*/ |
| 40 |
add_filter('wppizza_filter_settings_sections_'.$this->localization_page.'', array($this, 'admin_options_localization'), 80, 5); |
| 41 |
|
| 42 |
/**add default options **/ |
| 43 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 44 |
/**validate options**/ |
| 45 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 46 |
|
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
/******************************************************************************************************************************************************* |
| 53 |
* |
| 54 |
* |
| 55 |
* |
| 56 |
* [frontend filters] |
| 57 |
* |
| 58 |
* |
| 59 |
* |
| 60 |
********************************************************************************************************************************************************/ |
| 61 |
/******************************************************************************************************************************************************* |
| 62 |
* |
| 63 |
* |
| 64 |
* |
| 65 |
* [add admin page options] |
| 66 |
* |
| 67 |
* |
| 68 |
* |
| 69 |
********************************************************************************************************************************************************/ |
| 70 |
|
| 71 |
/*------------------------------------------------------------------------------ |
| 72 |
# |
| 73 |
# |
| 74 |
# [settings page] |
| 75 |
# |
| 76 |
# |
| 77 |
------------------------------------------------------------------------------*/ |
| 78 |
|
| 79 |
/*------------------------------------------------------------------------------ |
| 80 |
# [settings section - setting page] |
| 81 |
# @since 3.0 |
| 82 |
# @return array() |
| 83 |
------------------------------------------------------------------------------*/ |
| 84 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 85 |
|
| 86 |
/*section*/ |
| 87 |
if($sections){ |
| 88 |
$settings['sections'][$this->section_key] = __('Pickup', 'wppizza-admin'); |
| 89 |
} |
| 90 |
/*help*/ |
| 91 |
if($help){ |
| 92 |
$settings['help'][$this->section_key][] = array( |
| 93 |
'label'=>__('Order Pickup', 'wppizza-admin'), |
| 94 |
'description'=>array( |
| 95 |
__('Please adjust settings as appropriate according to the information provided next to each individual option.', 'wppizza-admin') |
| 96 |
) |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
/*fields*/ |
| 101 |
if($fields){ |
| 102 |
$field = 'order_pickup'; |
| 103 |
$settings['fields'][$this->section_key][$field] = array( __('Allow order pickup by customer', 'wppizza-admin'), array( |
| 104 |
'value_key'=>$field, |
| 105 |
'option_key'=>$this->settings_page, |
| 106 |
'label'=>__('Customer can choose to pickup the order him/herself.', 'wppizza-admin'), |
| 107 |
'description'=>array( |
| 108 |
__('No delivery charges will be applied if customer chooses to do so.', 'wppizza-admin') |
| 109 |
) |
| 110 |
)); |
| 111 |
$field = 'order_min_for_pickup'; |
| 112 |
$settings['fields'][$this->section_key][$field] = array( __('Minimum order value - pickup', 'wppizza-admin'), array( |
| 113 |
'value_key'=>$field, |
| 114 |
'option_key'=>$this->settings_page, |
| 115 |
'label'=>__('minimum order value - on self pickup [0 to disable]', 'wppizza-admin'), |
| 116 |
'description'=>array( |
| 117 |
__('disables "place order" button in cart and order page until set order value (before any discounts etc) has been reached.', 'wppizza-admin') |
| 118 |
) |
| 119 |
)); |
| 120 |
$field = 'order_pickup_preparation_time'; |
| 121 |
$settings['fields'][$this->section_key][$field] = array( __('Preparation Time', 'wppizza-admin'), array( |
| 122 |
'value_key'=>$field, |
| 123 |
'option_key'=>$this->settings_page, |
| 124 |
'label'=>__('Time set here will be used in various customer notices when pickup has been selected', 'wppizza-admin'), |
| 125 |
'description'=>array() |
| 126 |
)); |
| 127 |
$field = 'order_pickup_discount'; |
| 128 |
$settings['fields'][$this->section_key][$field] = array( __('Discount for self-pickup', 'wppizza-admin'), array( |
| 129 |
'value_key'=>$field, |
| 130 |
'option_key'=>$this->settings_page, |
| 131 |
'label'=>__('in % - 0 to disable [will not be applied to menu items and categories set to be excluded from discount calculation above]', 'wppizza-admin'), |
| 132 |
'description'=>array() |
| 133 |
)); |
| 134 |
$field = 'order_pickup_alert'; |
| 135 |
$settings['fields'][$this->section_key][$field] = array( __('javascript alert on pickup', 'wppizza-admin'), array( |
| 136 |
'value_key'=>$field, |
| 137 |
'option_key'=>$this->settings_page, |
| 138 |
'label'=>__('enable javascript alert when user changes selection', 'wppizza-admin'), |
| 139 |
'description'=>array() |
| 140 |
)); |
| 141 |
$field = 'order_pickup_alert_confirm'; |
| 142 |
$settings['fields'][$this->section_key][$field] = array( __('Confirm pickup/delivery change', 'wppizza-admin'), array( |
| 143 |
'value_key'=>$field, |
| 144 |
'option_key'=>$this->settings_page, |
| 145 |
'label'=>__('make user *confirm* change of pickup/delivery using a popup javascript alert', 'wppizza-admin'), |
| 146 |
'description'=>array() |
| 147 |
)); |
| 148 |
$field = 'order_pickup_display_location'; |
| 149 |
$settings['fields'][$this->section_key][$field] = array( __('Checkbox location', 'wppizza-admin'), array( |
| 150 |
'value_key'=>$field, |
| 151 |
'option_key'=>$this->settings_page, |
| 152 |
'label'=>'', |
| 153 |
'description'=>array( |
| 154 |
__('Where would you like to display the checkbox to let customer select self pickup of order [if enabled above] ?', 'wppizza-admin') |
| 155 |
) |
| 156 |
)); |
| 157 |
$field = 'order_pickup_as_default'; |
| 158 |
$settings['fields'][$this->section_key][$field] = array( __('Pickup as default', 'wppizza-admin'), array( |
| 159 |
'value_key'=>$field, |
| 160 |
'option_key'=>$this->settings_page, |
| 161 |
'label'=>__('set "pickup" to be the default selection (make sure to clear your browser cache to see the effect)', 'wppizza-admin'), |
| 162 |
'description'=>array() |
| 163 |
)); |
| 164 |
$field = 'order_pickup_toggled'; |
| 165 |
$settings['fields'][$this->section_key][$field] = array( __('Choices Toggle', 'wppizza-admin'), array( |
| 166 |
'value_key'=>$field, |
| 167 |
'option_key'=>$this->settings_page, |
| 168 |
'label'=>__('by default an on/off checkbox will be used, enable to use a two button toggle', 'wppizza-admin'), |
| 169 |
'description'=>array() |
| 170 |
)); |
| 171 |
} |
| 172 |
|
| 173 |
return $settings; |
| 174 |
} |
| 175 |
/*------------------------------------------------------------------------------ |
| 176 |
# [output option fields - setting page] |
| 177 |
# @since 3.0 |
| 178 |
# @return array() |
| 179 |
------------------------------------------------------------------------------*/ |
| 180 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 181 |
|
| 182 |
if($field=='order_pickup'){ |
| 183 |
echo "<label>"; |
| 184 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 185 |
echo "".$label.""; |
| 186 |
echo "</label>"; |
| 187 |
echo"".$description.""; |
| 188 |
} |
| 189 |
if($field=='order_pickup_discount'){ |
| 190 |
echo "<label>"; |
| 191 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='5' type='text' value='".wppizza_output_format_percent($wppizza_options[$options_key][$field])."' />"; |
| 192 |
echo "".$label.""; |
| 193 |
echo "</label>"; |
| 194 |
echo"".$description.""; |
| 195 |
} |
| 196 |
if($field=='order_pickup_preparation_time'){ |
| 197 |
echo "<label>"; |
| 198 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='5' type='text' value='".($wppizza_options[$options_key][$field])."' />"; |
| 199 |
echo "".$label.""; |
| 200 |
echo "</label>"; |
| 201 |
echo"".$description.""; |
| 202 |
} |
| 203 |
if($field=='order_pickup_alert'){ |
| 204 |
echo "<label>"; |
| 205 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 206 |
echo "".$label.""; |
| 207 |
echo "</label>"; |
| 208 |
echo"".$description.""; |
| 209 |
} |
| 210 |
if($field=='order_pickup_alert_confirm'){ |
| 211 |
echo "<label>"; |
| 212 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 213 |
echo "".$label.""; |
| 214 |
echo "</label>"; |
| 215 |
echo"".$description.""; |
| 216 |
} |
| 217 |
if($field=='order_pickup_display_location'){ |
| 218 |
echo "<label>"; |
| 219 |
echo "".__('under cart only', 'wppizza-admin')."<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='radio' ".checked($wppizza_options[$options_key][$field],1,false)." value='1' /> "; |
| 220 |
echo "".__('on order page only', 'wppizza-admin')."<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='radio' ".checked($wppizza_options[$options_key][$field],2,false)." value='2' /> "; |
| 221 |
echo "".__('both', 'wppizza-admin')."<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='radio' ".checked($wppizza_options[$options_key][$field],3,false)." value='3' />"; |
| 222 |
echo "".$label.""; |
| 223 |
echo "</label>"; |
| 224 |
echo"".$description.""; |
| 225 |
} |
| 226 |
if($field=='order_pickup_as_default'){ |
| 227 |
echo "<label>"; |
| 228 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 229 |
echo "".$label.""; |
| 230 |
echo "</label>"; |
| 231 |
echo"".$description.""; |
| 232 |
} |
| 233 |
if($field=='order_pickup_toggled'){ |
| 234 |
echo "<label>"; |
| 235 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 236 |
echo "".$label.""; |
| 237 |
echo "</label>"; |
| 238 |
echo"".$description.""; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
/*------------------------------------------------------------------------------ |
| 245 |
# |
| 246 |
# |
| 247 |
# [localization page] |
| 248 |
# |
| 249 |
# |
| 250 |
------------------------------------------------------------------------------*/ |
| 251 |
/**************************************************************** |
| 252 |
* [settigs section - localization page] |
| 253 |
* @since 3.0 |
| 254 |
* @return array() |
| 255 |
****************************************************************/ |
| 256 |
function admin_options_localization($settings, $sections, $fields, $inputs, $help){ |
| 257 |
global $wppizza_options; |
| 258 |
/* skip if not enabled */ |
| 259 |
//if(empty($wppizza_options[$this->settings_page]['repurchase'])){ |
| 260 |
// return $settings; |
| 261 |
//} |
| 262 |
/******************************** |
| 263 |
* [Labels] |
| 264 |
********************************/ |
| 265 |
/*sections*/ |
| 266 |
if($sections){ |
| 267 |
$settings['sections'][$this->section_key] = __('Pickup / Delivery', 'wppizza-admin'); |
| 268 |
} |
| 269 |
/*fields*/ |
| 270 |
if($fields){ |
| 271 |
$field = 'pickup_toggle_delivery'; |
| 272 |
$settings['fields'][$this->section_key][$field] = array( '' , array( |
| 273 |
'value_key'=>$field, |
| 274 |
'option_key'=>$this->localization_page, |
| 275 |
'label'=>__('Label Delivery Button [if Order Settings -> Order Pickup -> Choices Toggle enabled]', 'wppizza-admin') |
| 276 |
)); |
| 277 |
$field = 'pickup_toggle_pickup'; |
| 278 |
$settings['fields'][$this->section_key][$field] = array( '' , array( |
| 279 |
'value_key'=>$field, |
| 280 |
'option_key'=>$this->localization_page, |
| 281 |
'label'=>__('Label Pickup Button [if Order Settings -> Order Pickup -> Choices Toggle enabled]', 'wppizza-admin') |
| 282 |
)); |
| 283 |
$field = 'order_page_selfpickup'; |
| 284 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 285 |
'value_key'=>$field, |
| 286 |
'option_key'=>$this->localization_page, |
| 287 |
'label'=>__('Self Pickup: text on order page / email to highlight self pickup (if applicable)', 'wppizza-admin') |
| 288 |
)); |
| 289 |
$field = 'generic_ready_for_pickup'; |
| 290 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 291 |
'value_key'=>$field, |
| 292 |
'option_key'=>$this->localization_page, |
| 293 |
'label'=>__('Self Pickup: generic label that could be used (by 3rd party plugins) when order is ready for pickup', 'wppizza-admin') |
| 294 |
)); |
| 295 |
$field = 'generic_ready_for_pickup_time'; |
| 296 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 297 |
'value_key'=>$field, |
| 298 |
'option_key'=>$this->localization_page, |
| 299 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 300 |
'label'=>__('Self Pickup: generic text that could be used (by 3rd party plugins) to indicate when an order will be ready for collection [%s to be replaced with appropriate time]', 'wppizza-admin') |
| 301 |
)); |
| 302 |
$field = 'order_page_no_delivery'; |
| 303 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 304 |
'value_key'=>$field, |
| 305 |
'option_key'=>$this->localization_page, |
| 306 |
'label'=>__('No Delivery Offered / Pickup Only: text on order page / email if delivery is not being offered (if applicable)', 'wppizza-admin') |
| 307 |
)); |
| 308 |
$field = 'order_self_pickup'; |
| 309 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 310 |
'value_key'=>$field, |
| 311 |
'option_key'=>$this->localization_page, |
| 312 |
'label'=>__('Self Pickup: text next to self pickup checkbox (if enabled)', 'wppizza-admin') |
| 313 |
)); |
| 314 |
$field = 'order_self_pickup_cart'; |
| 315 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 316 |
'value_key'=>$field, |
| 317 |
'option_key'=>$this->localization_page, |
| 318 |
'label'=>__('Self Pickup: text under total value (if selected by customer)', 'wppizza-admin') |
| 319 |
)); |
| 320 |
$field = 'order_self_pickup_cartjs'; |
| 321 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 322 |
'value_key'=>$field, |
| 323 |
'option_key'=>$this->localization_page, |
| 324 |
'label'=>__('Self Pickup: javascript alert when customer selects self pickup (if enabled)', 'wppizza-admin') |
| 325 |
)); |
| 326 |
$field = 'minimum_order'; |
| 327 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 328 |
'value_key'=>$field, |
| 329 |
'option_key'=>$this->localization_page, |
| 330 |
'label'=>__('Label Info: required minimum order value for pickup (displayed if applicable)', 'wppizza-admin') |
| 331 |
)); |
| 332 |
|
| 333 |
} |
| 334 |
|
| 335 |
return $settings; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
/*------------------------------------------------------------------------------ |
| 341 |
# [insert default option on install] |
| 342 |
# $parameter $options array() | filter passing on filtered options |
| 343 |
# @since 3.0 |
| 344 |
# @return array() |
| 345 |
------------------------------------------------------------------------------*/ |
| 346 |
function options_default($options){ |
| 347 |
|
| 348 |
/* |
| 349 |
order settings |
| 350 |
*/ |
| 351 |
$options[$this->settings_page]['order_pickup'] = true; |
| 352 |
$options[$this->settings_page]['order_pickup_alert'] = false; |
| 353 |
$options[$this->settings_page]['order_pickup_alert_confirm'] = false; |
| 354 |
$options[$this->settings_page]['order_pickup_as_default'] = false; |
| 355 |
$options[$this->settings_page]['order_pickup_toggled'] = false; |
| 356 |
$options[$this->settings_page]['order_pickup_discount'] = 0; |
| 357 |
$options[$this->settings_page]['order_pickup_preparation_time'] = 30; |
| 358 |
$options[$this->settings_page]['order_pickup_display_location'] = 3; |
| 359 |
|
| 360 |
/* |
| 361 |
localization |
| 362 |
*/ |
| 363 |
$options[$this->localization_page]['pickup_toggle_delivery'] = wppizza_textdomain('Delivery', 'wppizza'); |
| 364 |
$options[$this->localization_page]['pickup_toggle_pickup'] = wppizza_textdomain('Pickup', 'wppizza'); |
| 365 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 366 |
$options[$this->localization_page]['order_page_selfpickup'] = wppizza_textdomain('You have chosen to pickup the order yourself. This order will not be delivered. Please allow %s min. for us to prepare your order.', 'wppizza'); |
| 367 |
$options[$this->localization_page]['generic_ready_for_pickup'] = wppizza_textdomain('Please collect your order from the store at your earliest convenience.', 'wppizza'); |
| 368 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 369 |
$options[$this->localization_page]['generic_ready_for_pickup_time'] = wppizza_textdomain('Your order will be ready for collection at %s.', 'wppizza'); |
| 370 |
$options[$this->localization_page]['order_page_no_delivery'] = wppizza_textdomain('Please collect your order at the store.', 'wppizza'); |
| 371 |
$options[$this->localization_page]['order_self_pickup'] = wppizza_textdomain('I would like to pickup the order myself', 'wppizza'); |
| 372 |
$options[$this->localization_page]['order_self_pickup_cart'] = wppizza_textdomain('Delivery: pickup', 'wppizza'); |
| 373 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 374 |
$options[$this->localization_page]['order_self_pickup_cartjs'] = wppizza_textdomain('You have chosen to pickup the order yourself. This order will not be delivered. Please allow %s min. for us to prepare your order.', 'wppizza'); |
| 375 |
$options[$this->localization_page]['minimum_order'] = wppizza_textdomain('minimum order', 'wppizza'); |
| 376 |
return $options; |
| 377 |
} |
| 378 |
|
| 379 |
/*------------------------------------------------------------------------------ |
| 380 |
# [validate options on save/update] |
| 381 |
# |
| 382 |
# @since 3.0 |
| 383 |
# @return array() |
| 384 |
------------------------------------------------------------------------------*/ |
| 385 |
function options_validate($options, $input){ |
| 386 |
/**make sure we get the full array on install/update**/ |
| 387 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 388 |
return $input; |
| 389 |
} |
| 390 |
/* |
| 391 |
settings |
| 392 |
*/ |
| 393 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 394 |
$options[$this->settings_page]['order_pickup']=!empty($input[$this->settings_page]['order_pickup']) ? true : false; |
| 395 |
$options[$this->settings_page]['order_pickup_alert']=!empty($input[$this->settings_page]['order_pickup_alert']) ? true : false; |
| 396 |
$options[$this->settings_page]['order_pickup_alert_confirm']=!empty($input[$this->settings_page]['order_pickup_alert_confirm']) ? true : false; |
| 397 |
$options[$this->settings_page]['order_pickup_as_default']=!empty($input[$this->settings_page]['order_pickup_as_default']) ? true : false; |
| 398 |
$options[$this->settings_page]['order_pickup_discount']=wppizza_validate_float_pc($input[$this->settings_page]['order_pickup_discount']); |
| 399 |
$options[$this->settings_page]['order_pickup_display_location'] = wppizza_validate_int_only($input[$this->settings_page]['order_pickup_display_location']); |
| 400 |
$options[$this->settings_page]['order_pickup_preparation_time'] = wppizza_validate_int_only($input[$this->settings_page]['order_pickup_preparation_time']); |
| 401 |
$options[$this->settings_page]['order_pickup_toggled']=!empty($input[$this->settings_page]['order_pickup_toggled']) ? true : false; |
| 402 |
} |
| 403 |
|
| 404 |
/* |
| 405 |
localization strings are automatically validated |
| 406 |
*/ |
| 407 |
|
| 408 |
|
| 409 |
return $options; |
| 410 |
} |
| 411 |
} |
| 412 |
/*************************************************************** |
| 413 |
* |
| 414 |
* [ini] |
| 415 |
* |
| 416 |
***************************************************************/ |
| 417 |
$WPPIZZA_MODULE_ORDERSETTINGS_PICKUP = new WPPIZZA_MODULE_ORDERSETTINGS_PICKUP(); |
| 418 |
?> |