| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_ORDER_SETTINGS_GLOBAL Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_ORDER_SETTINGS_GLOBAL |
| 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_GLOBAL{ |
| 24 |
|
| 25 |
private $settings_page = 'order_settings';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
private $section_key = 'global';/* 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'), 10, 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 default options **/ |
| 40 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 41 |
/**validate options**/ |
| 42 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 43 |
} |
| 44 |
/********************************************************** |
| 45 |
[filter/actions depending on settings] |
| 46 |
***********************************************************/ |
| 47 |
/***exclude selected order page from navigation */ |
| 48 |
add_filter('get_pages', array($this,'exclude_order_page_from_navigation')); |
| 49 |
/****filter transaction id's******/ |
| 50 |
add_filter( 'wppizza_filter_transaction_id', array( $this, 'filter_transaction_id'),10,2); |
| 51 |
/****show order on thank you page ******/ |
| 52 |
add_filter('wppizza_filter_showorder_on_thankyou', array($this,'showorder_on_thankyou')); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
/******************************************************************************************************************************************************* |
| 57 |
* |
| 58 |
* |
| 59 |
* |
| 60 |
* [frontend filters] |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
********************************************************************************************************************************************************/ |
| 65 |
/********************************************************* |
| 66 |
* |
| 67 |
* [exclude_order_page_from_navigation - frontend only ] |
| 68 |
* |
| 69 |
*********************************************************/ |
| 70 |
function exclude_order_page_from_navigation($pages) { |
| 71 |
if(is_admin()){return $pages;} |
| 72 |
|
| 73 |
global $wppizza_options; |
| 74 |
if($wppizza_options[$this->settings_page]['orderpage_exclude']){ |
| 75 |
$pageCount = count($pages); |
| 76 |
for ( $i=0; $i<$pageCount; $i++ ) { |
| 77 |
$page = & $pages[$i]; |
| 78 |
|
| 79 |
/**wpml select of order page**/ |
| 80 |
if(function_exists('icl_object_id')) { |
| 81 |
$wppizza_options[$this->settings_page]['orderpage']=icl_object_id($wppizza_options[$this->settings_page]['orderpage'],'page'); |
| 82 |
} |
| 83 |
|
| 84 |
if ($page->ID==$wppizza_options[$this->settings_page]['orderpage']) { |
| 85 |
unset( $pages[$i] );/*unset the order page*/ |
| 86 |
} |
| 87 |
} |
| 88 |
if ( ! is_array( $pages ) ) $pages = (array) $pages; |
| 89 |
$pages = array_values( $pages ); |
| 90 |
} |
| 91 |
return $pages; |
| 92 |
} |
| 93 |
/******************************************************************************* |
| 94 |
* |
| 95 |
* |
| 96 |
* filter transaction id |
| 97 |
* |
| 98 |
* |
| 99 |
*******************************************************************************/ |
| 100 |
function filter_transaction_id($transaction_id, $order_id){ |
| 101 |
global $wppizza_options; |
| 102 |
/**allow custom filter**/ |
| 103 |
$transaction_id = apply_filters('wppizza_custom_transaction_id', $transaction_id, $order_id); |
| 104 |
/**add id to end**/ |
| 105 |
if($wppizza_options[$this->settings_page]['append_internal_id_to_transaction_id']){ |
| 106 |
$transaction_id.='/'.$order_id.''; |
| 107 |
} |
| 108 |
return $transaction_id; |
| 109 |
} |
| 110 |
|
| 111 |
/********************************************************* |
| 112 |
* |
| 113 |
* [showorder_on_thankyou] |
| 114 |
* |
| 115 |
*********************************************************/ |
| 116 |
function showorder_on_thankyou($bool){ |
| 117 |
global $wppizza_options; |
| 118 |
$bool = !empty($wppizza_options[$this->settings_page]['gateway_showorder_on_thankyou']) ? true : false; |
| 119 |
return $bool; |
| 120 |
} |
| 121 |
|
| 122 |
/******************************************************************************************************************************************************* |
| 123 |
* |
| 124 |
* |
| 125 |
* |
| 126 |
* [add admin page options] |
| 127 |
* |
| 128 |
* |
| 129 |
* |
| 130 |
********************************************************************************************************************************************************/ |
| 131 |
|
| 132 |
/*------------------------------------------------------------------------------ |
| 133 |
# |
| 134 |
# |
| 135 |
# [settings page] |
| 136 |
# |
| 137 |
# |
| 138 |
------------------------------------------------------------------------------*/ |
| 139 |
|
| 140 |
/*------------------------------------------------------------------------------ |
| 141 |
# [settings section - setting page] |
| 142 |
# @since 3.0 |
| 143 |
# @return array() |
| 144 |
------------------------------------------------------------------------------*/ |
| 145 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 146 |
|
| 147 |
/*section*/ |
| 148 |
if($sections){ |
| 149 |
$settings['sections'][$this->section_key] = __('Global', 'wppizza-admin'); |
| 150 |
} |
| 151 |
/*help*/ |
| 152 |
if($help){ |
| 153 |
$settings['help'][$this->section_key][] = array( |
| 154 |
'label'=>__('Currency', 'wppizza-admin'), |
| 155 |
'description'=>array( |
| 156 |
__('Set the currency you want to use throughout', 'wppizza-admin') |
| 157 |
) |
| 158 |
); |
| 159 |
$settings['help'][$this->section_key][] = array( |
| 160 |
'label'=>__('Order Page', 'wppizza-admin'), |
| 161 |
'description'=>array( |
| 162 |
__('You probably do NOT want to display the shopping cart on this page (although it won\'t break things if you do)', 'wppizza-admin') |
| 163 |
) |
| 164 |
); |
| 165 |
$settings['help'][$this->section_key][] = array( |
| 166 |
'label'=>__('Exclude Order Page', 'wppizza-admin'), |
| 167 |
'description'=>array( |
| 168 |
__('Excludes the set order page from any of your navigation menus (unless you specifically add it)', 'wppizza-admin') |
| 169 |
) |
| 170 |
); |
| 171 |
$settings['help'][$this->section_key][] = array( |
| 172 |
'label'=>__('Append internal ID', 'wppizza-admin'), |
| 173 |
'description'=>array( |
| 174 |
__('If you enable this option, the internal order ID of the database table will be appended to the transaction ID [e.g COD13966037358 will become COD13966037358/123 where 123 = internal id of order table]', 'wppizza-admin') |
| 175 |
) |
| 176 |
); |
| 177 |
$settings['help'][$this->section_key][] = array( |
| 178 |
'label'=>__('Show Order Details on "Thank You" page', 'wppizza-admin'), |
| 179 |
'description'=>array( |
| 180 |
__('Enable to show full order details on "thank you" page after payment', 'wppizza-admin') |
| 181 |
) |
| 182 |
); |
| 183 |
$settings['help'][$this->section_key][] = array( |
| 184 |
'label'=>__('Delivery or Pickup by url parameter', 'wppizza-admin'), |
| 185 |
'description'=>array( |
| 186 |
__('You can override the default \'pickup\' and \'delivery\' parameters by setting the \'WPPIZZA_GET_PICKUP\' and \'WPPIZZA_GET_DELIVERY\' constants as required.', 'wppizza-admin') |
| 187 |
) |
| 188 |
); |
| 189 |
} |
| 190 |
/*fields*/ |
| 191 |
if($fields){ |
| 192 |
$field = 'currency'; |
| 193 |
$settings['fields'][$this->section_key][$field] = array( __('Currency', 'wppizza-admin'), array( |
| 194 |
'value_key'=>$field, |
| 195 |
'option_key'=>$this->settings_page, |
| 196 |
'label'=>__('set to --none-- to have no currency displayed anywhere', 'wppizza-admin') . ' <span style="color:red;">' . __('Note: A currency must be set if you want to accept online payments', 'wppizza-admin') .'</span>' , |
| 197 |
'description'=>array() |
| 198 |
)); |
| 199 |
$field = 'orderpage'; |
| 200 |
$settings['fields'][$this->section_key][$field] = array( __('Order Page', 'wppizza-admin'), array( |
| 201 |
'value_key'=>$field, |
| 202 |
'option_key'=>$this->settings_page, |
| 203 |
'label'=>__('ensure the page includes [wppizza type="orderpage"] or the widget equivalent.', 'wppizza-admin'), |
| 204 |
'description'=>array() |
| 205 |
)); |
| 206 |
$field = 'orderpage_exclude'; |
| 207 |
$settings['fields'][$this->section_key][$field] = array( __('Exclude "Order Page" from menu', 'wppizza-admin'), array( |
| 208 |
'value_key'=>$field, |
| 209 |
'option_key'=>$this->settings_page, |
| 210 |
'label'=>__('To exclude this page from your navigation menu, check this option.', 'wppizza-admin'), |
| 211 |
'description'=>array() |
| 212 |
)); |
| 213 |
$field = 'append_internal_id_to_transaction_id'; |
| 214 |
$settings['fields'][$this->section_key][$field] = array( __('Append internal ID', 'wppizza-admin'), array( |
| 215 |
'value_key'=>$field, |
| 216 |
'option_key'=>$this->settings_page, |
| 217 |
'label'=>__('Append internal database ID to transaction ID', 'wppizza-admin'), |
| 218 |
'description'=>array() |
| 219 |
)); |
| 220 |
$field = 'gateway_showorder_on_thankyou'; |
| 221 |
$settings['fields'][$this->section_key][$field] = array( __('Show Order Details on "Thank You" page', 'wppizza-admin'), array( |
| 222 |
'value_key'=>$field, |
| 223 |
'option_key'=>$this->settings_page, |
| 224 |
'label'=>__('Will add any order details after your thank you text on successful order.', 'wppizza-admin'), |
| 225 |
'description'=>array() |
| 226 |
)); |
| 227 |
$field = 'getvar_pickup_choice'; |
| 228 |
$settings['fields'][$this->section_key][$field] = array( __('Delivery or Pickup by parameter', 'wppizza-admin'), array( |
| 229 |
'value_key'=>$field, |
| 230 |
'option_key'=>$this->settings_page, |
| 231 |
'label'=>__('Enable delivery/pickup to be selected by appending \'?delivery\' or \'?pickup\' parameter to a URL.', 'wppizza-admin'), |
| 232 |
'description'=>array() |
| 233 |
)); |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
return $settings; |
| 238 |
} |
| 239 |
/*------------------------------------------------------------------------------ |
| 240 |
# [output option fields - setting page] |
| 241 |
# @since 3.0 |
| 242 |
# @return array() |
| 243 |
------------------------------------------------------------------------------*/ |
| 244 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 245 |
/******************************** |
| 246 |
* [currency / order page / Add internal ID to transaction ID] |
| 247 |
********************************/ |
| 248 |
if($field=='currency'){ |
| 249 |
echo "<label>"; |
| 250 |
echo "<select name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' class='wppizza_".$field."'>"; |
| 251 |
foreach(wppizza_currencies($wppizza_options[$options_key][$field]) as $l=>$m){ |
| 252 |
$currencyLabel = $m['id'] == '---none---' ? '--- '.__('None', 'wppizza-admin').' ---' : "".$m['id']." - ".$m['value'].""; |
| 253 |
echo "<option value='".$m['id']."' ".$m['selected'].">".$currencyLabel."</option>"; |
| 254 |
} |
| 255 |
echo "</select>"; |
| 256 |
echo "".$label.""; |
| 257 |
echo "</label>"; |
| 258 |
echo"".$description.""; |
| 259 |
} |
| 260 |
if($field=='orderpage'){ |
| 261 |
echo "<label>"; |
| 262 |
wp_dropdown_pages('name='.WPPIZZA_SLUG.'['.$options_key.']['.$field.']&selected='.$wppizza_options[$options_key][$field].'&show_option_none='.__('select your orderpage', 'wppizza-admin').'&class=wppizza_'.$field.''); |
| 263 |
echo "".$label.""; |
| 264 |
echo "</label>"; |
| 265 |
echo"".$description.""; |
| 266 |
} |
| 267 |
|
| 268 |
if($field=='orderpage_exclude'){ |
| 269 |
echo "<label>"; |
| 270 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 271 |
echo "".$label.""; |
| 272 |
echo "</label>"; |
| 273 |
echo"".$description.""; |
| 274 |
} |
| 275 |
|
| 276 |
if($field=='append_internal_id_to_transaction_id'){ |
| 277 |
echo "<label>"; |
| 278 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 279 |
echo "".$label.""; |
| 280 |
echo "</label>"; |
| 281 |
echo"".$description.""; |
| 282 |
} |
| 283 |
|
| 284 |
if($field=='gateway_showorder_on_thankyou'){ |
| 285 |
echo "<label>"; |
| 286 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 287 |
echo "".$label.""; |
| 288 |
echo "</label>"; |
| 289 |
echo"".$description.""; |
| 290 |
} |
| 291 |
|
| 292 |
if($field=='getvar_pickup_choice'){ |
| 293 |
echo "<label>"; |
| 294 |
echo "<input name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 295 |
echo "".$label.""; |
| 296 |
echo "</label>"; |
| 297 |
echo"".$description.""; |
| 298 |
} |
| 299 |
} |
| 300 |
/*------------------------------------------------------------------------------ |
| 301 |
# [insert default option on install] |
| 302 |
# $parameter $options array() | filter passing on filtered options |
| 303 |
# @since 3.0 |
| 304 |
# @return array() |
| 305 |
------------------------------------------------------------------------------*/ |
| 306 |
function options_default($options){ |
| 307 |
|
| 308 |
$options[$this->settings_page]['currency'] = 'GBP'; |
| 309 |
$options[$this->settings_page]['currency_symbol'] = '£'; |
| 310 |
$options[$this->settings_page]['orderpage'] = ''; /*set to empty initially, install class will overwrite if orderpage is installed/created*/ |
| 311 |
$options[$this->settings_page]['orderpage_exclude'] = true; |
| 312 |
$options[$this->settings_page]['append_internal_id_to_transaction_id'] = false; |
| 313 |
$options[$this->settings_page]['gateway_showorder_on_thankyou'] = true; |
| 314 |
$options[$this->settings_page]['getvar_pickup_choice'] = false; |
| 315 |
|
| 316 |
return $options; |
| 317 |
} |
| 318 |
|
| 319 |
/*------------------------------------------------------------------------------ |
| 320 |
# [validate options on save/update] |
| 321 |
# |
| 322 |
# @since 3.0 |
| 323 |
# @return array() |
| 324 |
------------------------------------------------------------------------------*/ |
| 325 |
function options_validate($options, $input){ |
| 326 |
/**make sure we get the full array on install/update**/ |
| 327 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 328 |
return $input; |
| 329 |
} |
| 330 |
/******************************** |
| 331 |
* [validate] |
| 332 |
********************************/ |
| 333 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 334 |
$options[$this->settings_page]['currency'] = strtoupper($input[$this->settings_page]['currency']); |
| 335 |
$currency_symbol = wppizza_currencies($input[$this->settings_page]['currency'],true); |
| 336 |
$options[$this->settings_page]['currency_symbol'] = $currency_symbol['val']; |
| 337 |
$options[$this->settings_page]['orderpage'] = !empty($input[$this->settings_page]['orderpage']) ? (int)$input[$this->settings_page]['orderpage'] : false; |
| 338 |
$options[$this->settings_page]['orderpage_exclude']=!empty($input[$this->settings_page]['orderpage_exclude']) ? true : false; |
| 339 |
$options[$this->settings_page]['append_internal_id_to_transaction_id'] = !empty($input[$this->settings_page]['append_internal_id_to_transaction_id']) ? true : false; |
| 340 |
$options[$this->settings_page]['gateway_showorder_on_thankyou'] = !empty($input[$this->settings_page]['gateway_showorder_on_thankyou']) ? true : false; |
| 341 |
$options[$this->settings_page]['getvar_pickup_choice'] = !empty($input[$this->settings_page]['getvar_pickup_choice']) ? true : false; |
| 342 |
} |
| 343 |
return $options; |
| 344 |
} |
| 345 |
} |
| 346 |
/*************************************************************** |
| 347 |
* |
| 348 |
* [ini] |
| 349 |
* |
| 350 |
***************************************************************/ |
| 351 |
$WPPIZZA_MODULE_ORDER_SETTINGS_GLOBAL = new WPPIZZA_MODULE_ORDER_SETTINGS_GLOBAL(); |
| 352 |
?> |