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