| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_ORDER_SETTINGS_DELIVERY Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_ORDER_SETTINGS_DELIVERY |
| 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_ORDER_SETTINGS_DELIVERY{ |
| 24 |
|
| 25 |
private $settings_page = 'order_settings';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
private $section_key = 'delivery';/* must be unique */ |
| 27 |
private $localization_page = 'localization'; |
| 28 |
private $localization_section_append = 'pickup';/* which localization section do we want to append the fileds to */ |
| 29 |
|
| 30 |
|
| 31 |
function __construct() { |
| 32 |
/********************************************************** |
| 33 |
[add settings to admin] |
| 34 |
***********************************************************/ |
| 35 |
if(is_admin()){ |
| 36 |
/* add admin options settings page*/ |
| 37 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 20, 5); |
| 38 |
/* add admin options settings page fields */ |
| 39 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 40 |
/* add admin options localization page - does not need fields action*/ |
| 41 |
add_filter('wppizza_filter_settings_sections_'.$this->localization_page.'', array($this, 'admin_options_localization'), 200, 5);/* highish priority to put it after all other miscellaneous localization fields (must be min 190)*/ |
| 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 |
[filter/actions depending on settings] |
| 49 |
***********************************************************/ |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
/******************************************************************************************************************************************************* |
| 54 |
* |
| 55 |
* |
| 56 |
* |
| 57 |
* [frontend filters] |
| 58 |
* |
| 59 |
* |
| 60 |
* |
| 61 |
********************************************************************************************************************************************************/ |
| 62 |
|
| 63 |
|
| 64 |
/******************************************************************************************************************************************************* |
| 65 |
* |
| 66 |
* |
| 67 |
* |
| 68 |
* [add admin page options] |
| 69 |
* |
| 70 |
* |
| 71 |
* |
| 72 |
********************************************************************************************************************************************************/ |
| 73 |
|
| 74 |
/*------------------------------------------------------------------------------ |
| 75 |
# |
| 76 |
# |
| 77 |
# [settings page] |
| 78 |
# |
| 79 |
# |
| 80 |
------------------------------------------------------------------------------*/ |
| 81 |
|
| 82 |
/*------------------------------------------------------------------------------ |
| 83 |
# [settings section - setting page] |
| 84 |
# @since 3.0 |
| 85 |
# @return array() |
| 86 |
------------------------------------------------------------------------------*/ |
| 87 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 88 |
|
| 89 |
/*section*/ |
| 90 |
if($sections){ |
| 91 |
$settings['sections'][$this->section_key] = __('Delivery', 'wppizza-admin'); |
| 92 |
} |
| 93 |
/*help*/ |
| 94 |
if($help){ |
| 95 |
$settings['help'][$this->section_key][] = array( |
| 96 |
'label'=>__('Delivery', 'wppizza-admin'), |
| 97 |
'description'=>array( |
| 98 |
__('Please adjust settings as appropriate according to the information provided next to each individual option.', 'wppizza-admin') |
| 99 |
) |
| 100 |
); |
| 101 |
} |
| 102 |
/*fields*/ |
| 103 |
if($fields){ |
| 104 |
$field = 'delivery'; |
| 105 |
$settings['fields'][$this->section_key][$field] = array( __('Delivery Type', 'wppizza-admin'), array( |
| 106 |
'value_key'=>$field, |
| 107 |
'option_key'=>$this->settings_page, |
| 108 |
'label'=>'', |
| 109 |
'description'=>array() |
| 110 |
)); |
| 111 |
$field = 'order_min_for_delivery'; |
| 112 |
$settings['fields'][$this->section_key][$field] = array( __('Minimum order value - delivery', 'wppizza-admin'), array( |
| 113 |
'value_key'=>$field, |
| 114 |
'option_key'=>$this->settings_page, |
| 115 |
'label'=>__('minimum order value - on delivery [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 |
__('customer can still choose "self-pickup" (if enabled / applicable).', 'wppizza-admin') |
| 119 |
) |
| 120 |
)); |
| 121 |
$field = 'order_min_on_totals'; |
| 122 |
$settings['fields'][$this->section_key][$field] = array( __('Minimum order of totals', 'wppizza-admin'), array( |
| 123 |
'value_key'=>$field, |
| 124 |
'option_key'=>$this->settings_page, |
| 125 |
'label'=>__('apply minimum order value on total sum of order (but before any tips and/or handling charges) [if left unchecked, minimum order uses only sum of items in cart before discounts etc]', 'wppizza-admin'), |
| 126 |
'description'=>array() |
| 127 |
)); |
| 128 |
$field = 'order_min_exclude_delivery_charges'; |
| 129 |
$settings['fields'][$this->section_key][$field] = array( '', array( |
| 130 |
'value_key'=>$field, |
| 131 |
'option_key'=>$this->settings_page, |
| 132 |
'label'=>'',// set directly as its a suboption |
| 133 |
'description'=>array() |
| 134 |
)); |
| 135 |
$field = 'order_delivery_time'; |
| 136 |
$settings['fields'][$this->section_key][$field] = array( __('Delivery time', 'wppizza-admin'), array( |
| 137 |
'value_key'=>$field, |
| 138 |
'option_key'=>$this->settings_page, |
| 139 |
'label'=>__('set delivery time that will be displayed in applicable alerts, emails, notices ', 'wppizza-admin'), |
| 140 |
'description'=>array( |
| 141 |
__('referenced in relevant localization strings', 'wppizza-admin') |
| 142 |
) |
| 143 |
)); |
| 144 |
$field = 'delivery_calculation_exclude_item'; |
| 145 |
$settings['fields'][$this->section_key][$field] = array( __('Exclude menu items from calculation', 'wppizza-admin'), array( |
| 146 |
'value_key'=>$field, |
| 147 |
'option_key'=>$this->settings_page, |
| 148 |
'label'=>__('<b>Exclude</b> following menu items when calculating if free delivery applies or minimum order value has been reached (if not using minimum order of totals)', 'wppizza-admin') . '<br/>(' . __('Consider updating your "minimum order..." localization strings too if you use this', 'wppizza-admin').')', |
| 149 |
'description'=>array() |
| 150 |
)); |
| 151 |
$field = 'delivery_calculation_exclude_cat'; |
| 152 |
$settings['fields'][$this->section_key][$field] = array( __('Exclude categories from calculation', 'wppizza-admin'), array( |
| 153 |
'value_key'=>$field, |
| 154 |
'option_key'=>$this->settings_page, |
| 155 |
'label'=>__('<b>Exclude</b> all menu items belonging to following *categories* when calculating if free delivery applies or minimum order value has been reached (if not using minimum order of totals)', 'wppizza-admin') . '<br/>(' . __('Consider updating your "minimum order..." localization strings too if you use this', 'wppizza-admin').')', |
| 156 |
'description'=>array( |
| 157 |
__('For example: you might want to offer free delivery only when total order of *meals* exceeds the set free delivery amount. In this case, exclude all your *drinks and non-meals* by selecting those above.', 'wppizza-admin') |
| 158 |
) |
| 159 |
)); |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
return $settings; |
| 165 |
} |
| 166 |
/*------------------------------------------------------------------------------ |
| 167 |
# [output option fields - setting page] |
| 168 |
# @since 3.0 |
| 169 |
# @return array() |
| 170 |
------------------------------------------------------------------------------*/ |
| 171 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 172 |
|
| 173 |
if($field=='delivery'){ |
| 174 |
/****sort in a more sensible manner**/ |
| 175 |
$wppizza_options[$options_key][$field]=array( |
| 176 |
'no_delivery'=>$wppizza_options[$options_key][$field]['no_delivery'], |
| 177 |
'minimum_total'=>$wppizza_options[$options_key][$field]['minimum_total'], |
| 178 |
'standard'=>$wppizza_options[$options_key][$field]['standard'], |
| 179 |
'per_item'=>$wppizza_options[$options_key][$field]['per_item'] |
| 180 |
); |
| 181 |
|
| 182 |
echo "<table id='wppizza_admin_table_".$field."' class='wppizza_admin_table'>"; |
| 183 |
foreach($wppizza_options[$options_key][$field] as $k=>$v){ |
| 184 |
echo "<tr>"; |
| 185 |
echo "<td>"; |
| 186 |
|
| 187 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][delivery_selected]' type='radio' ". checked($wppizza_options[$options_key]['delivery_selected']==$k,true,false)." value='".$k."' />"; |
| 188 |
|
| 189 |
if($k=='no_delivery'){ |
| 190 |
echo" ".__('No delivery offered / pickup only', 'wppizza-admin').""; |
| 191 |
echo"<br /><span class='description'>".__('removes any labels, text, charges, checkboxes etc associated with delivery options. You can still set a minimum order value below.', 'wppizza-admin')."</span>"; |
| 192 |
|
| 193 |
} |
| 194 |
if($k=='minimum_total'){ |
| 195 |
echo" ".__('Free delivery when total order value reaches', 'wppizza-admin').":"; |
| 196 |
echo"<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."][".$k."][min_total]' size='3' type='text' value='". ( $wppizza_options[$options_key][$field][$k]['min_total'] === 'n/a' ? 'n/a' : wppizza_output_format_price($wppizza_options[$options_key][$field][$k]['min_total']) )."' />"; |
| 197 |
echo"<div style='margin-left:20px'>"; |
| 198 |
echo"<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."][".$k."][deliver_below_total]' type='checkbox' ". checked($v['deliver_below_total'],true,false)." value='1' />"; |
| 199 |
echo" ".__('Deliver even when total order value is below minimum (the difference between total and "Minimum Total" above will be added to the Total as "Delivery Charges")', 'wppizza-admin').""; |
| 200 |
echo"<br />"; |
| 201 |
echo"<span class='description'>".__('(If this is not selected and the total order is below the set value above, the customer will not be able to submit the order to you)', 'wppizza-admin')."</span>"; |
| 202 |
echo"<br />"; |
| 203 |
echo"<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."][".$k."][deliverycharges_below_total]' size='3' type='text' value='".wppizza_output_format_price($wppizza_options[$options_key][$field][$k]['deliverycharges_below_total'])."' />"; |
| 204 |
echo" ".__('Fixed Delivery charges if order has not reached total for free delivery [0 to disable]', 'wppizza-admin').""; |
| 205 |
echo"<br />"; |
| 206 |
echo" <span class='description' style='color:red'>(".__('if set (i.e. not 0) "Deliver even when total order value is below minimum" must be checked for this to have any effect', 'wppizza-admin').")</span>"; |
| 207 |
|
| 208 |
echo"</div>"; |
| 209 |
} |
| 210 |
if($k=='standard'){ |
| 211 |
echo" ".__('Fixed Delivery Charges [added to order total]', 'wppizza-admin').":"; |
| 212 |
echo "<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][".$k."][delivery_charge]' size='3' type='text' value='".wppizza_output_format_price($wppizza_options[$this->settings_page][$field][$k]['delivery_charge'])."' />"; |
| 213 |
|
| 214 |
} |
| 215 |
if($k=='per_item'){ |
| 216 |
echo" ".__('Delivery Charges per item', 'wppizza-admin').":"; |
| 217 |
echo"<div style='margin-left:20px'>"; |
| 218 |
echo "<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][".$k."][delivery_charge_per_item]' size='3' type='text' value='".wppizza_output_format_price($wppizza_options[$this->settings_page][$field][$k]['delivery_charge_per_item'])."' />"; |
| 219 |
echo" ".__('Do not apply delivery charges when total order value reaches ', 'wppizza-admin').":"; |
| 220 |
echo"<input name='".WPPIZZA_SLUG."[".$this->settings_page."][".$field."][".$k."][delivery_per_item_free]' size='3' type='text' value='".wppizza_output_format_price($wppizza_options[$this->settings_page][$field][$k]['delivery_per_item_free'])."' />"; |
| 221 |
echo" ".__('[set to 0 to always apply charges per item]', 'wppizza-admin').""; |
| 222 |
echo"</div>"; |
| 223 |
} |
| 224 |
echo "</td>"; |
| 225 |
echo "</tr>"; |
| 226 |
} |
| 227 |
echo "</table>"; |
| 228 |
} |
| 229 |
|
| 230 |
if($field=='order_min_on_totals'){ |
| 231 |
echo "<label>"; |
| 232 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 233 |
echo "".$label.""; |
| 234 |
echo "</label>"; |
| 235 |
echo"".$description.""; |
| 236 |
|
| 237 |
/** add exclude delivery too here as suboption, setting label directly **/ |
| 238 |
$field='order_min_exclude_delivery_charges'; |
| 239 |
echo "<br><label>"; |
| 240 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 241 |
echo "".__('do not include delivery charges to calculate if minimum order value has been reached (only applicable if above option is also enabled)', 'wppizza-admin').""; |
| 242 |
echo "</label>"; |
| 243 |
//echo"".$description.""; |
| 244 |
} |
| 245 |
|
| 246 |
if($field=='order_min_for_delivery'){ |
| 247 |
echo "<label>"; |
| 248 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='3' type='text' value='".wppizza_output_format_price($wppizza_options[$options_key][$field])."' />"; |
| 249 |
echo "" . $label . ""; |
| 250 |
echo "</label>"; |
| 251 |
echo"".$description.""; |
| 252 |
} |
| 253 |
if($field=='order_delivery_time'){ |
| 254 |
echo "<label>"; |
| 255 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='3' type='text' value='".($wppizza_options[$options_key][$field])."' />"; |
| 256 |
echo "" . $label . ""; |
| 257 |
echo "</label>"; |
| 258 |
echo"".$description.""; |
| 259 |
} |
| 260 |
|
| 261 |
if($field=='order_min_for_pickup'){ |
| 262 |
echo "<label>"; |
| 263 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='3' type='text' value='".wppizza_output_format_price($wppizza_options[$options_key][$field])."' />"; |
| 264 |
echo "" . $label . ""; |
| 265 |
echo "</label>"; |
| 266 |
echo"".$description.""; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
if($field=='delivery_calculation_exclude_item'){ |
| 271 |
if(is_array(wppizza_get_menu_items())){ |
| 272 |
echo "<label>"; |
| 273 |
echo "".$label.""; |
| 274 |
echo "<br />"; |
| 275 |
echo"<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."][]' multiple='multiple' data-placeholder='".__('N/A', 'wppizza-admin')."' class='wppizza_multiselect wppizza_".$field."'>"; |
| 276 |
foreach(wppizza_get_menu_items() as $pKey=>$pVal){ |
| 277 |
echo"<option value='".$pVal->ID."' "; |
| 278 |
if(isset($wppizza_options[$options_key][$field]) && in_array($pVal->ID,$wppizza_options[$options_key][$field])){ |
| 279 |
echo" selected='selected'"; |
| 280 |
} |
| 281 |
echo">".$pVal->post_title."</option>"; |
| 282 |
} |
| 283 |
echo"</select>"; |
| 284 |
echo "</label>"; |
| 285 |
echo"".$description.""; |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
if($field=='delivery_calculation_exclude_cat'){ |
| 290 |
if(is_array(wppizza_get_categories())){ |
| 291 |
echo "<label>"; |
| 292 |
echo "".$label.""; |
| 293 |
echo "<br />"; |
| 294 |
echo"<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."][]' multiple='multiple' data-placeholder='".__('N/A', 'wppizza-admin')."' class='wppizza_multiselect wppizza_".$field."'>"; |
| 295 |
foreach(wppizza_get_categories() as $cKey=>$cVal){ |
| 296 |
echo"<option value='".$cVal->term_id."' "; |
| 297 |
if(isset($wppizza_options[$options_key][$field]) && isset($wppizza_options[$options_key][$field][$cVal->term_id])){ |
| 298 |
echo" selected='selected'"; |
| 299 |
} |
| 300 |
echo">".$cVal->name."</option>"; |
| 301 |
} |
| 302 |
echo"</select>"; |
| 303 |
echo "</label>"; |
| 304 |
echo"".$description.""; |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
/*------------------------------------------------------------------------------ |
| 310 |
# |
| 311 |
# |
| 312 |
# [localization page] |
| 313 |
# |
| 314 |
# |
| 315 |
------------------------------------------------------------------------------*/ |
| 316 |
/**************************************************************** |
| 317 |
* [settigs section - localization page] |
| 318 |
* @since 3.0 |
| 319 |
* @return array() |
| 320 |
****************************************************************/ |
| 321 |
function admin_options_localization($settings, $sections, $fields, $inputs, $help){ |
| 322 |
//global $wppizza_options; |
| 323 |
/* skip if not enabled */ |
| 324 |
//if(empty($wppizza_options[$this->settings_page]['repurchase'])){ |
| 325 |
// return $settings; |
| 326 |
//} |
| 327 |
/******************************** |
| 328 |
* [Labels] |
| 329 |
********************************/ |
| 330 |
/*sections*/ |
| 331 |
//if($sections){ |
| 332 |
// $add_settings['sections'][$this->section_key] = __('User Purchase History - Repurchasing', 'wppizza-admin'); |
| 333 |
//} |
| 334 |
/*fields*/ |
| 335 |
if($fields){ |
| 336 |
$field = 'free_delivery_for_orders_of'; |
| 337 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 338 |
'value_key'=>$field, |
| 339 |
'option_key'=>$this->localization_page, |
| 340 |
'label'=>__('Label Info: i.e. "free delivery for orders over"...', 'wppizza-admin') |
| 341 |
)); |
| 342 |
$field = 'minimum_order_delivery'; |
| 343 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 344 |
'value_key'=>$field, |
| 345 |
'option_key'=>$this->localization_page, |
| 346 |
'label'=>__('Label Info: required minimum order value for delivery (displayed if applicable)', 'wppizza-admin') |
| 347 |
)); |
| 348 |
$field = 'order_page_delivery_time'; |
| 349 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 350 |
'value_key'=>$field, |
| 351 |
'option_key'=>$this->localization_page, |
| 352 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 353 |
'label'=>__('Delivery Time: text on order page / email to indicate delivery times (if applicable) %s will be replaced by delivery times set in wppizza -> order settings', 'wppizza-admin') |
| 354 |
)); |
| 355 |
$field = 'generic_order_delivered_shortly'; |
| 356 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 357 |
'value_key'=>$field, |
| 358 |
'option_key'=>$this->localization_page, |
| 359 |
'label'=>__('Delivery: generic label that could be used (by 3rd party plugins) when order is about to be delivered', 'wppizza-admin') |
| 360 |
)); |
| 361 |
$field = 'generic_order_delivery_time'; |
| 362 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 363 |
'value_key'=>$field, |
| 364 |
'option_key'=>$this->localization_page, |
| 365 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 366 |
'label'=>__('Delivery: generic text that could be used (by 3rd party plugins) to indicate when an order will delivered [%s to be replaced with appropriate time]', 'wppizza-admin') |
| 367 |
)); |
| 368 |
$field = 'order_request_delivery'; |
| 369 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 370 |
'value_key'=>$field, |
| 371 |
'option_key'=>$this->localization_page, |
| 372 |
'label'=>__('Shoppingcart - Delivery: text next to checkbox under cart / on order page (if pickup is set to be the default)', 'wppizza-admin') |
| 373 |
)); |
| 374 |
|
| 375 |
$field = 'order_delivery_cartjs'; |
| 376 |
$settings['fields'][$this->localization_section_append][$field] = array( '', array( |
| 377 |
'value_key'=>$field, |
| 378 |
'option_key'=>$this->localization_page, |
| 379 |
'label'=>__('Delivery: javascript alert when customer selects delivery (if enabled)', 'wppizza-admin') |
| 380 |
)); |
| 381 |
|
| 382 |
} |
| 383 |
|
| 384 |
return $settings; |
| 385 |
} |
| 386 |
|
| 387 |
/*------------------------------------------------------------------------------ |
| 388 |
# [insert default option on install] |
| 389 |
# $parameter $options array() | filter passing on filtered options |
| 390 |
# @since 3.0 |
| 391 |
# @return array() |
| 392 |
------------------------------------------------------------------------------*/ |
| 393 |
function options_default($options){ |
| 394 |
/* |
| 395 |
settings page |
| 396 |
*/ |
| 397 |
$options[$this->settings_page]['delivery_selected'] = 'minimum_total'; |
| 398 |
$options[$this->settings_page]['order_min_for_delivery'] = 0; |
| 399 |
$options[$this->settings_page]['order_delivery_time'] = 45; |
| 400 |
$options[$this->settings_page]['order_min_for_pickup'] = 0; //to check. perhaps only relevant for updates from very old version --> !empty($options[$this->settings_page]['order_min_for_delivery']) ? $options[$this->settings_page]['order_min_for_delivery'] : 0 ;/**on updates, use order_min_for_delivery settings so as to not modify th ebehaviousr in the frontend**/ |
| 401 |
$options[$this->settings_page]['order_min_on_totals'] = false; |
| 402 |
$options[$this->settings_page]['order_min_exclude_delivery_charges'] = false; |
| 403 |
|
| 404 |
$options[$this->settings_page]['delivery'] = array( |
| 405 |
'no_delivery'=>'', |
| 406 |
'minimum_total'=>array('min_total'=>'12.5','deliver_below_total'=>true,'deliverycharges_below_total'=>'0'), |
| 407 |
'standard'=>array('delivery_charge'=>'12.5'), |
| 408 |
'per_item'=>array('delivery_charge_per_item'=>'1','delivery_per_item_free'=>'50') |
| 409 |
); |
| 410 |
$options[$this->settings_page]['delivery_calculation_exclude_item'] = array(); |
| 411 |
$options[$this->settings_page]['delivery_calculation_exclude_cat'] = array(); |
| 412 |
|
| 413 |
/* |
| 414 |
localization |
| 415 |
*/ |
| 416 |
$options[$this->localization_page]['free_delivery_for_orders_of'] = wppizza_textdomain('free delivery for orders over', 'wppizza'); |
| 417 |
$options[$this->localization_page]['minimum_order_delivery'] = wppizza_textdomain('minimum order for delivery', 'wppizza'); |
| 418 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 419 |
$options[$this->localization_page]['order_page_delivery_time'] = wppizza_textdomain('Please allow %s minutes for delivery.', 'wppizza'); |
| 420 |
$options[$this->localization_page]['generic_order_delivered_shortly'] = wppizza_textdomain('Your order is out for delivery and will arrive with you shortly.', 'wppizza'); |
| 421 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 422 |
$options[$this->localization_page]['generic_order_delivery_time'] = wppizza_textdomain('Your order will be delivered no later than %s.', 'wppizza'); |
| 423 |
$options[$this->localization_page]['order_request_delivery'] = wppizza_textdomain('I would like my order to be delivered', 'wppizza'); |
| 424 |
/* Translators: 1: %s should not be translated here but used literally */ |
| 425 |
$options[$this->localization_page]['order_delivery_cartjs'] = wppizza_textdomain('Please allow %s min. for us to deliver your order.', 'wppizza'); |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
return $options; |
| 430 |
} |
| 431 |
|
| 432 |
/*------------------------------------------------------------------------------ |
| 433 |
# [validate options on save/update] |
| 434 |
# |
| 435 |
# @since 3.0 |
| 436 |
# @return array() |
| 437 |
------------------------------------------------------------------------------*/ |
| 438 |
function options_validate($options, $input){ |
| 439 |
/**make sure we get the full array on install/update**/ |
| 440 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 441 |
return $input; |
| 442 |
} |
| 443 |
/******************************** |
| 444 |
* [validate] |
| 445 |
********************************/ |
| 446 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 447 |
|
| 448 |
$options[$this->settings_page]['delivery_selected'] = wppizza_validate_alpha_only($input[$this->settings_page]['delivery_selected']); |
| 449 |
$options[$this->settings_page]['order_min_for_delivery']=wppizza_validate_float_only($input[$this->settings_page]['order_min_for_delivery']); |
| 450 |
$options[$this->settings_page]['order_delivery_time']=wppizza_validate_int_only($input[$this->settings_page]['order_delivery_time']); |
| 451 |
$options[$this->settings_page]['order_min_for_pickup']=wppizza_validate_float_only($input[$this->settings_page]['order_min_for_pickup']); |
| 452 |
$options[$this->settings_page]['order_min_on_totals'] = !empty($input[$this->settings_page]['order_min_on_totals']) ? true : false; |
| 453 |
$options[$this->settings_page]['order_min_exclude_delivery_charges'] = !empty($input[$this->settings_page]['order_min_exclude_delivery_charges']) ? true : false; |
| 454 |
|
| 455 |
|
| 456 |
$options[$this->settings_page]['delivery'] = array(); |
| 457 |
foreach($input[$this->settings_page]['delivery'] as $k=>$v){ |
| 458 |
foreach($v as $l=>$m){ |
| 459 |
if($l!='deliver_below_total'){ |
| 460 |
$options[$this->settings_page]['delivery'][$k][$l]=wppizza_validate_float_only($m,2); |
| 461 |
} |
| 462 |
} |
| 463 |
if($k=='minimum_total'){ |
| 464 |
//allow n/a to alwasy apply delivery charges |
| 465 |
if($input[$this->settings_page]['delivery'][$k]['min_total'] == 'n/a'){ |
| 466 |
$options[$this->settings_page]['delivery'][$k]['min_total'] = 'n/a'; |
| 467 |
} |
| 468 |
$options[$this->settings_page]['delivery'][$k]['deliver_below_total']=!empty($input[$this->settings_page]['delivery'][$k]['deliver_below_total']) ? true : false; |
| 469 |
$options[$this->settings_page]['delivery'][$k]['deliverycharges_below_total']=wppizza_validate_float_only($input[$this->settings_page]['delivery'][$k]['deliverycharges_below_total']); |
| 470 |
} |
| 471 |
} |
| 472 |
/**hardcode no_delivery (as there are no submitted input values)*/ |
| 473 |
$options[$this->settings_page]['delivery']['no_delivery']=''; |
| 474 |
$options[$this->settings_page]['delivery_calculation_exclude_item'] = !empty($input[$this->settings_page]['delivery_calculation_exclude_item']) ? array_combine($input[$this->settings_page]['delivery_calculation_exclude_item'], $input[$this->settings_page]['delivery_calculation_exclude_item']) : array(); |
| 475 |
$options[$this->settings_page]['delivery_calculation_exclude_cat'] = !empty($input[$this->settings_page]['delivery_calculation_exclude_cat']) ? array_combine($input[$this->settings_page]['delivery_calculation_exclude_cat'],$input[$this->settings_page]['delivery_calculation_exclude_cat']) : array();/*makes keys == values*/ |
| 476 |
|
| 477 |
} |
| 478 |
return $options; |
| 479 |
} |
| 480 |
} |
| 481 |
/*************************************************************** |
| 482 |
* |
| 483 |
* [ini] |
| 484 |
* |
| 485 |
***************************************************************/ |
| 486 |
$WPPIZZA_MODULE_ORDER_SETTINGS_DELIVERY = new WPPIZZA_MODULE_ORDER_SETTINGS_DELIVERY(); |
| 487 |
?> |