Completed
Push — master ( 892e19...9033e6 )
by
unknown
21:32
created
includes/modules/wps_shipping/controller/wps_shipping_mode_ctr.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 class wps_shipping_mode_ctr {
3 3
 
4 4
 	/**
@@ -18,34 +18,34 @@  discard block
 block discarded – undo
18 18
 		/** Template Load **/
19 19
 	//	add_filter( 'wpshop_custom_template', array( $this, 'custom_template_load' ) );
20 20
 
21
-		add_action( 'admin_init', array( $this, 'migrate_default_shipping_mode' ) );
21
+		add_action('admin_init', array($this, 'migrate_default_shipping_mode'));
22 22
 
23 23
 		/**	Add module option to wpshop general options	*/
24
-		add_filter('wpshop_options', array( $this, 'add_options'), 9);
25
-		add_action('wsphop_options', array( $this, 'create_options'), 8);
24
+		add_filter('wpshop_options', array($this, 'add_options'), 9);
25
+		add_action('wsphop_options', array($this, 'create_options'), 8);
26 26
 
27 27
 		// Add files in back-office
28
-		add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_in_admin' ) );
28
+		add_action('admin_enqueue_scripts', array($this, 'add_scripts_in_admin'));
29 29
 		// Add files in front-office
30
-		add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') );
30
+		add_action('wp_enqueue_scripts', array($this, 'add_scripts'));
31 31
 
32 32
 		// Available Shortcodes
33
-		add_shortcode( 'wps_shipping_mode', array( &$this, 'display_shipping_mode') );
34
-		add_shortcode( 'wps_shipping_method', array( &$this, 'display_shipping_methods') );
35
-		add_shortcode( 'wps_shipping_summary', array( &$this, 'display_shipping_summary') );
33
+		add_shortcode('wps_shipping_mode', array(&$this, 'display_shipping_mode'));
34
+		add_shortcode('wps_shipping_method', array(&$this, 'display_shipping_methods'));
35
+		add_shortcode('wps_shipping_summary', array(&$this, 'display_shipping_summary'));
36 36
 
37
-		add_action( 'add_meta_boxes', array( $this, 'add_meta_box') );
37
+		add_action('add_meta_boxes', array($this, 'add_meta_box'));
38 38
 	}
39 39
 
40
-	function add_meta_box( $post_type, $post ) {
41
-		if ( WPSHOP_NEWTYPE_IDENTIFIER_ORDER == $post_type ) {
40
+	function add_meta_box($post_type, $post) {
41
+		if (WPSHOP_NEWTYPE_IDENTIFIER_ORDER == $post_type) {
42 42
 			/**	Box for shipping information	*/
43 43
 			$shipping_option = get_option('wpshop_shipping_address_choice');
44
-			$order_meta = get_post_meta( $post->ID, '_order_postmeta', true );
45
-			if (!in_array( $post->post_status, array( 'auto-draft' ) ) && ( !empty($shipping_option['activate']) && $shipping_option['activate'] && ( is_array( $order_meta ) && empty($order_meta['order_payment']['shipping_method'] ) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos' ) ) ) {
44
+			$order_meta = get_post_meta($post->ID, '_order_postmeta', true);
45
+			if (!in_array($post->post_status, array('auto-draft')) && (!empty($shipping_option['activate']) && $shipping_option['activate'] && (is_array($order_meta) && empty($order_meta['order_payment']['shipping_method']) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos'))) {
46 46
 				add_meta_box(
47 47
 				'wpshop_order_shipping',
48
-				'<span class="dashicons dashicons-palmtree"></span> '.__('Shipping', 'wpshop'),
48
+				'<span class="dashicons dashicons-palmtree"></span> ' . __('Shipping', 'wpshop'),
49 49
 				array($this, 'order_shipping_box'),
50 50
 				WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low'
51 51
 						);
@@ -58,29 +58,29 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	function add_scripts() {
60 60
 		//CSS files
61
-		wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/css/wps_shipping_mode.css', false );
62
-		wp_enqueue_style( 'wps_shipping_mode_css' );
61
+		wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/css/wps_shipping_mode.css', false);
62
+		wp_enqueue_style('wps_shipping_mode_css');
63 63
 		// Javascript Files
64
-		wp_enqueue_script( 'jquery' );
65
-		wp_enqueue_script( 'wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/js/shipping_method.js', false );
64
+		wp_enqueue_script('jquery');
65
+		wp_enqueue_script('wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/js/shipping_method.js', false);
66 66
 	}
67 67
 
68 68
 	/**
69 69
 	 * Add JS and CSS files in back-office
70 70
 	 */
71
-	function add_scripts_in_admin( $hook ) {
71
+	function add_scripts_in_admin($hook) {
72 72
 		global $current_screen;
73
-		if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) && $hook !== 'settings_page_wpshop_option' )
73
+		if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER), true) && $hook !== 'settings_page_wpshop_option')
74 74
 			return;
75 75
 
76 76
 		add_thickbox();
77 77
 		wp_enqueue_script('jquery');
78 78
 		wp_enqueue_script('jquery-ui-sortable');
79 79
 		// Javascript files
80
-		wp_enqueue_script( 'wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/js/wps_shipping_mode.js', false );
80
+		wp_enqueue_script('wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/js/wps_shipping_mode.js', false);
81 81
 		//CSS files
82
-		wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/css/wps_shipping_mode.css', false );
83
-		wp_enqueue_style( 'wps_shipping_mode_css' );
82
+		wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/css/wps_shipping_mode.css', false);
83
+		wp_enqueue_style('wps_shipping_mode_css');
84 84
 	}
85 85
 
86 86
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	/**
103 103
 	 * Declare option groups for the module
104 104
 	 */
105
-	function add_options( $option_group ) {
105
+	function add_options($option_group) {
106 106
 		$option_group['wpshop_shipping_option']['subgroups']['wps_shipping_mode']['class'] = ' wpshop_admin_box_options_shipping_mode';
107 107
 		return $option_group;
108 108
 	}
@@ -111,38 +111,38 @@  discard block
 block discarded – undo
111 111
 	 * Create Options
112 112
 	 **/
113 113
 	function create_options() {
114
-		add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>'.__('Shipping method', 'wpshop'), '', 'wps_shipping_mode');
115
-		register_setting('wpshop_options', 'wps_shipping_mode', array( $this, 'wpshop_options_validate_wps_shipping_mode'));
116
-		add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array( $this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode');
114
+		add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>' . __('Shipping method', 'wpshop'), '', 'wps_shipping_mode');
115
+		register_setting('wpshop_options', 'wps_shipping_mode', array($this, 'wpshop_options_validate_wps_shipping_mode'));
116
+		add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array($this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode');
117 117
 	}
118 118
 
119 119
 	/**
120 120
 	 * WPS Shipping mode Option Validator
121 121
 	 **/
122
-	function wpshop_options_validate_wps_shipping_mode( $input ) {
122
+	function wpshop_options_validate_wps_shipping_mode($input) {
123 123
 		$wps_shipping = new wps_shipping();
124
-		if ( !empty($input['modes']) ) {
125
-			foreach( $input['modes'] as $mode => $mode_det ) {
124
+		if (!empty($input['modes'])) {
125
+			foreach ($input['modes'] as $mode => $mode_det) {
126 126
 				/** Custom Shipping rules **/
127
-				$input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array( $input['modes'][$mode]['custom_shipping_rules']['fees'] );
127
+				$input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array($input['modes'][$mode]['custom_shipping_rules']['fees']);
128 128
 
129 129
 				/** Shipping Modes Logo Treatment **/
130
-				if ( !empty($_FILES[$mode.'_logo']['name']) && empty($_FILES[$mode.'_logo']['error']) ) {
131
-					$filename = $_FILES[$mode.'_logo'];
132
-					$upload  = wp_handle_upload($filename, array('test_form' => false));
133
-					$wp_filetype = wp_check_filetype(basename($filename['name']), null );
130
+				if (!empty($_FILES[$mode . '_logo']['name']) && empty($_FILES[$mode . '_logo']['error'])) {
131
+					$filename = $_FILES[$mode . '_logo'];
132
+					$upload = wp_handle_upload($filename, array('test_form' => false));
133
+					$wp_filetype = wp_check_filetype(basename($filename['name']), null);
134 134
 					$wp_upload_dir = wp_upload_dir();
135 135
 					$attachment = array(
136
-							'guid' => $wp_upload_dir['url'] . '/' . basename( $filename['name'] ),
136
+							'guid' => $wp_upload_dir['url'] . '/' . basename($filename['name']),
137 137
 							'post_mime_type' => $wp_filetype['type'],
138 138
 							'post_title' => preg_replace(' /\.[^.]+$/', '', basename($filename['name'])),
139 139
 							'post_content' => '',
140 140
 							'post_status' => 'inherit'
141 141
 					);
142
-					$attach_id = wp_insert_attachment( $attachment, $upload['file']);
142
+					$attach_id = wp_insert_attachment($attachment, $upload['file']);
143 143
 					require_once(ABSPATH . 'wp-admin/includes/image.php');
144
-					$attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] );
145
-					wp_update_attachment_metadata( $attach_id, $attach_data );
144
+					$attach_data = wp_generate_attachment_metadata($attach_id, $upload['file']);
145
+					wp_update_attachment_metadata($attach_id, $attach_data);
146 146
 
147 147
 					$input['modes'][$mode]['logo'] = $attach_id;
148 148
 				}
@@ -156,38 +156,38 @@  discard block
 block discarded – undo
156 156
 	 **/
157 157
 	function migrate_default_shipping_mode() {
158 158
 		$data = array();
159
-		$shipping_mode_option = get_option( 'wps_shipping_mode' );
160
-		if ( empty($shipping_mode_option) ) {
159
+		$shipping_mode_option = get_option('wps_shipping_mode');
160
+		if (empty($shipping_mode_option)) {
161 161
 			$data['modes']['default_shipping_mode']['active'] = 'on';
162 162
 			$data['modes']['default_shipping_mode']['name'] = __('Home Delivery', 'wpshop');
163 163
 			$data['modes']['default_shipping_mode']['explanation'] = __('Your purchase will be delivered directly to you at home', 'wpshop');
164 164
 			/** Check CUstom Shipping **/
165
-			$custom_shipping_option = get_option( 'wpshop_custom_shipping' );
166
-			if ( !empty($custom_shipping_option) ) {
165
+			$custom_shipping_option = get_option('wpshop_custom_shipping');
166
+			if (!empty($custom_shipping_option)) {
167 167
 				$data['modes']['default_shipping_mode']['custom_shipping_rules'] = $custom_shipping_option;
168 168
 			}
169 169
 			/** Check Country Limit **/
170
-			$limit_destination = get_option( 'wpshop_limit_shipping_destination' );
171
-			if ( !empty($custom_shipping_option) ) {
170
+			$limit_destination = get_option('wpshop_limit_shipping_destination');
171
+			if (!empty($custom_shipping_option)) {
172 172
 				$data['modes']['default_shipping_mode']['limit_destination'] = $limit_destination;
173 173
 			}
174 174
 
175 175
 			/** Check Others shipping configurations **/
176 176
 			$wpshop_shipping_rules_option = get_option('wpshop_shipping_rules');
177
-			if ( !empty($wpshop_shipping_rules_option) ){
178
-				if ( !empty($wpshop_shipping_rules_option['min_max']) ) {
177
+			if (!empty($wpshop_shipping_rules_option)) {
178
+				if (!empty($wpshop_shipping_rules_option['min_max'])) {
179 179
 					$data['modes']['default_shipping_mode']['min_max'] = $wpshop_shipping_rules_option['min_max'];
180 180
 				}
181
-				if ( !empty($wpshop_shipping_rules_option['free_from']) ) {
181
+				if (!empty($wpshop_shipping_rules_option['free_from'])) {
182 182
 					$data['modes']['default_shipping_mode']['free_from'] = $wpshop_shipping_rules_option['free_from'];
183 183
 				}
184
-				if ( !empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']) ) {
184
+				if (!empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping'])) {
185 185
 					$data['modes']['default_shipping_mode']['free_shipping'] = $wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping'];
186 186
 				}
187 187
 			}
188 188
 			$data['default_choice'] = 'default_shipping_mode';
189 189
 
190
-			update_option( 'wps_shipping_mode', $data );
190
+			update_option('wps_shipping_mode', $data);
191 191
 		}
192 192
 	}
193 193
 
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 *  Display the Admin Interface for Shipping Mode
196 196
 	 **/
197 197
 	function display_shipping_mode_in_admin() {
198
-		$shipping_mode_option = get_option( 'wps_shipping_mode' );
199
-		require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes") );
198
+		$shipping_mode_option = get_option('wps_shipping_mode');
199
+		require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes"));
200 200
 	}
201 201
 
202 202
 	/**
@@ -205,28 +205,28 @@  discard block
 block discarded – undo
205 205
 	 * @param array $shipping_mode
206 206
 	 * @return string
207 207
 	 */
208
-	function generate_shipping_mode_interface( $k, $shipping_mode ) {
208
+	function generate_shipping_mode_interface($k, $shipping_mode) {
209 209
 		global $wpdb;
210 210
 		$tpl_component = array();
211 211
 
212
-		$shipping_mode_option = get_option( 'wps_shipping_mode');
213
-		$default_shipping_mode = !empty( $shipping_mode_option['default_choice'] ) ? $shipping_mode_option['default_choice'] : '';
212
+		$shipping_mode_option = get_option('wps_shipping_mode');
213
+		$default_shipping_mode = !empty($shipping_mode_option['default_choice']) ? $shipping_mode_option['default_choice'] : '';
214 214
 
215 215
 		$countries = unserialize(WPSHOP_COUNTRY_LIST);
216 216
 
217 217
 		/** Default Weight Unity **/
218
-		$weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity');
219
-		$query = $wpdb->prepare('SELECT name FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
220
-		$unity = $wpdb->get_var( $query );
218
+		$weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity');
219
+		$query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
220
+		$unity = $wpdb->get_var($query);
221 221
 
222 222
 
223
-		$fees_data = ( !empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees']) ) ? $shipping_mode['custom_shipping_rules']['fees'] : array();
224
-		if(is_array($fees_data)) {
223
+		$fees_data = (!empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees'])) ? $shipping_mode['custom_shipping_rules']['fees'] : array();
224
+		if (is_array($fees_data)) {
225 225
 			$wps_shipping = new wps_shipping();
226 226
 			$fees_data = $wps_shipping->shipping_fees_array_2_string($fees_data);
227 227
 		}
228 228
 		ob_start();
229
-		require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface") );
229
+		require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface"));
230 230
 		$output = ob_get_contents();
231 231
 		ob_end_clean();
232 232
 
@@ -239,22 +239,22 @@  discard block
 block discarded – undo
239 239
 	 * @param array $fees_data
240 240
 	 * @param string $key
241 241
 	 */
242
-	function generate_shipping_rules_table( $fees_data, $shipping_mode_id ){
242
+	function generate_shipping_rules_table($fees_data, $shipping_mode_id) {
243 243
 		global $wpdb;
244 244
 		$result = '';
245
-		if ( !empty( $fees_data) ) {
245
+		if (!empty($fees_data)) {
246 246
 			$wps_shipping = new wps_shipping();
247
-			$shipping_rules =$wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) );
247
+			$shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data));
248 248
 			$result = '';
249
-			$tpl_component ='';
249
+			$tpl_component = '';
250 250
 			$tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = '';
251 251
 			$tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id;
252 252
 			$country_list = unserialize(WPSHOP_COUNTRY_LIST);
253
-			$weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity');
254
-			$query = $wpdb->prepare('SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
255
-			$unity = $wpdb->get_var( $query );
253
+			$weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity');
254
+			$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
255
+			$unity = $wpdb->get_var($query);
256 256
 			ob_start();
257
-			require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table") );
257
+			require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table"));
258 258
 			$result = ob_get_contents();
259 259
 			ob_end_clean();
260 260
 		}
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	function display_shipping_methods() {
276 276
 		$output = $shipping_methods = ''; $no_shipping_mode_for_area = false;
277
-		$shipping_modes = get_option( 'wps_shipping_mode' );
278
-		if( !empty($_SESSION['shipping_address']) ) {
279
-			$shipping_modes = $this->get_shipping_mode_for_address( $_SESSION['shipping_address'] );
280
-			if( empty($shipping_modes) ) {
277
+		$shipping_modes = get_option('wps_shipping_mode');
278
+		if (!empty($_SESSION['shipping_address'])) {
279
+			$shipping_modes = $this->get_shipping_mode_for_address($_SESSION['shipping_address']);
280
+			if (empty($shipping_modes)) {
281 281
 				$no_shipping_mode_for_area = true;
282 282
 			}
283 283
 		}
284
-		$shipping_modes = apply_filters( 'wps_filter_shipping_methods', $shipping_modes );
284
+		$shipping_modes = apply_filters('wps_filter_shipping_methods', $shipping_modes);
285 285
 		ob_start();
286
-		require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container") );
286
+		require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container"));
287 287
 		$output = ob_get_contents();
288 288
 		ob_end_clean();
289 289
 
@@ -296,24 +296,24 @@  discard block
 block discarded – undo
296 296
 	 */
297 297
 	function display_shipping_summary() {
298 298
 		$output = '';
299
-		$billing_address_id = ( !empty($_SESSION['billing_address']) ) ? $_SESSION['billing_address'] : null;
300
-		$shipping_address_id = ( !empty($_SESSION['shipping_address']) ) ? $_SESSION['shipping_address'] : null;
301
-		$shipping_mode = ( !empty($_SESSION['shipping_method']) ) ? $_SESSION['shipping_method'] : null;
299
+		$billing_address_id = (!empty($_SESSION['billing_address'])) ? $_SESSION['billing_address'] : null;
300
+		$shipping_address_id = (!empty($_SESSION['shipping_address'])) ? $_SESSION['shipping_address'] : null;
301
+		$shipping_mode = (!empty($_SESSION['shipping_method'])) ? $_SESSION['shipping_method'] : null;
302 302
 
303
-		if( !empty($billing_address_id)  ) {
303
+		if (!empty($billing_address_id)) {
304 304
 			$billing_infos = get_post_meta($billing_address_id, '_wpshop_address_metadata', true);
305
-			$billing_content = wps_address::display_an_address( $billing_infos, $billing_address_id);
305
+			$billing_content = wps_address::display_an_address($billing_infos, $billing_address_id);
306 306
 
307
-			if ( !empty($shipping_address_id) && !empty($shipping_mode) ) {
307
+			if (!empty($shipping_address_id) && !empty($shipping_mode)) {
308 308
 				$shipping_infos = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true);
309
-				$shipping_content = wps_address::display_an_address( $shipping_infos, $shipping_address_id);
309
+				$shipping_content = wps_address::display_an_address($shipping_infos, $shipping_address_id);
310 310
 
311
-				$shipping_mode_option = get_option( 'wps_shipping_mode' );
312
-				$shipping_mode = ( !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name']) ) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : '';
311
+				$shipping_mode_option = get_option('wps_shipping_mode');
312
+				$shipping_mode = (!empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name'])) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : '';
313 313
 			}
314 314
 
315 315
 			ob_start();
316
-			require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary") );
316
+			require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary"));
317 317
 			$output = ob_get_contents();
318 318
 			ob_end_clean();
319 319
 		}
@@ -327,42 +327,42 @@  discard block
 block discarded – undo
327 327
 	 * @param integer $address_id
328 328
 	 * @return string
329 329
 	 */
330
-	function get_shipping_mode_for_address( $address_id ) {
330
+	function get_shipping_mode_for_address($address_id) {
331 331
 		$shipping_modes_to_display = array();
332
-		if( !empty($address_id) ) {
333
-			$shipping_modes = get_option( 'wps_shipping_mode' );
334
-			$address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta( $address_id, '_wpshop_address_metadata', true);
335
-			if( !empty( $shipping_modes ) && !empty($shipping_modes['modes']) ){
336
-				foreach( $shipping_modes['modes'] as $k => $shipping_mode ) {
337
-					if ( !empty($shipping_mode) && !empty($shipping_mode['active']) ) {
332
+		if (!empty($address_id)) {
333
+			$shipping_modes = get_option('wps_shipping_mode');
334
+			$address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta($address_id, '_wpshop_address_metadata', true);
335
+			if (!empty($shipping_modes) && !empty($shipping_modes['modes'])) {
336
+				foreach ($shipping_modes['modes'] as $k => $shipping_mode) {
337
+					if (!empty($shipping_mode) && !empty($shipping_mode['active'])) {
338 338
 						/** Check Country Shipping Limitation **/
339
-						if ( empty($shipping_mode['limit_destination']) || ( !empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country']) ) || ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']) ) ) {
339
+						if (empty($shipping_mode['limit_destination']) || (!empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country'])) || (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']))) {
340 340
 							/** Check Limit Destination By Postcode **/
341 341
 							$visible = true;
342 342
 							/** Check Postcode limitation **/
343
-							if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode']) ) {
344
-								$postcodes = explode(',', $shipping_mode['limit_destination']['postcode'] );
345
-								foreach( $postcodes as $postcode_id => $postcode ) {
346
-									$postcodes[ $postcode_id ] = trim( str_replace( ' ', '', $postcode) );
343
+							if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode'])) {
344
+								$postcodes = explode(',', $shipping_mode['limit_destination']['postcode']);
345
+								foreach ($postcodes as $postcode_id => $postcode) {
346
+									$postcodes[$postcode_id] = trim(str_replace(' ', '', $postcode));
347 347
 								}
348
-								if ( !in_array($address_metadata['postcode'], $postcodes) ) {
348
+								if (!in_array($address_metadata['postcode'], $postcodes)) {
349 349
 									$visible = false;
350 350
 								}
351 351
 							}
352 352
 							/** Check Department limitation **/
353
-							$department = isset( $address_metadata['postcode'] ) ? substr( $address_metadata['postcode'], 0, 2 ) : '';
354
-							if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department']) ) {
355
-								$departments = explode(',', $shipping_mode['limit_destination']['department'] );
356
-								foreach( $departments as $department_id => $d ) {
357
-									$departments[ $department_id ] = trim( str_replace( ' ', '', $d) );
353
+							$department = isset($address_metadata['postcode']) ? substr($address_metadata['postcode'], 0, 2) : '';
354
+							if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department'])) {
355
+								$departments = explode(',', $shipping_mode['limit_destination']['department']);
356
+								foreach ($departments as $department_id => $d) {
357
+									$departments[$department_id] = trim(str_replace(' ', '', $d));
358 358
 								}
359 359
 
360
-								if ( !in_array($department, $departments) ) {
360
+								if (!in_array($department, $departments)) {
361 361
 									$visible = false;
362 362
 								}
363 363
 							}
364 364
 
365
-							if ( $visible ) {
365
+							if ($visible) {
366 366
 								$shipping_modes_to_display['modes'][$k] = $shipping_mode;
367 367
 							}
368 368
 						}
@@ -378,12 +378,12 @@  discard block
 block discarded – undo
378 378
 	 * Display shipping informations in order administration panel
379 379
 	 * @param object $order : Order post infos
380 380
 	 */
381
-	function order_shipping_box( $order ) {
382
-		$shipping_mode_option = get_option( 'wps_shipping_mode' );
381
+	function order_shipping_box($order) {
382
+		$shipping_mode_option = get_option('wps_shipping_mode');
383 383
 		$order_postmeta = get_post_meta($order->ID, '_order_postmeta', true);
384
-		$shipping_method_name = ( !empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ( (!empty($order_postmeta['order_payment']['shipping_method']) ) ? $order_postmeta['order_payment']['shipping_method'] : '' );
384
+		$shipping_method_name = (!empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ((!empty($order_postmeta['order_payment']['shipping_method'])) ? $order_postmeta['order_payment']['shipping_method'] : '');
385 385
 		ob_start();
386
-		require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos") );
386
+		require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos"));
387 387
 		$output = ob_get_contents();
388 388
 		ob_end_clean();
389 389
 		echo $output;
Please login to merge, or discard this patch.