|
1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
2
|
|
|
class wps_shipping_mode_ctr { |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Define the main directory containing the template for the current plugin |
|
6
|
|
|
* @var string |
|
7
|
|
|
*/ |
|
8
|
|
|
public $template_dir; |
|
9
|
|
|
/** |
|
10
|
|
|
* Define the directory name for the module in order to check into frontend |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
private $plugin_dirname = WPS_SHIPPING_MODE_DIR; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
function __construct() { |
|
|
|
|
|
|
16
|
|
|
$this->template_dir = WPS_SHIPPING_MODE_PATH . WPS_SHIPPING_MODE_DIR . "/templates/"; |
|
17
|
|
|
|
|
18
|
|
|
/** Template Load **/ |
|
19
|
|
|
// add_filter( 'wpshop_custom_template', array( $this, 'custom_template_load' ) ); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
add_action( 'admin_init', array( $this, 'migrate_default_shipping_mode' ) ); |
|
22
|
|
|
|
|
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); |
|
26
|
|
|
|
|
27
|
|
|
// Add files in back-office |
|
28
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_in_admin' ) ); |
|
29
|
|
|
// Add files in front-office |
|
30
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
31
|
|
|
|
|
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') ); |
|
36
|
|
|
|
|
37
|
|
|
add_action( 'add_meta_boxes', array( $this, 'add_meta_box'), 10, 2 ); |
|
38
|
|
|
|
|
39
|
|
|
add_shortcode( 'wps_product_shipping_cost', array( $this, 'get_shipping_cost_shortcode' ) ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function add_meta_box( $post_type, $post ) { |
|
|
|
|
|
|
43
|
|
|
if ( WPSHOP_NEWTYPE_IDENTIFIER_ORDER == $post_type ) { |
|
44
|
|
|
/** Box for shipping information */ |
|
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' ) ) ) { |
|
48
|
|
|
add_meta_box( |
|
49
|
|
|
'wpshop_order_shipping', |
|
50
|
|
|
'<span class="dashicons dashicons-palmtree"></span> '.__('Shipping', 'wpshop'), |
|
51
|
|
|
array($this, 'order_shipping_box'), |
|
52
|
|
|
WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low' |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Add CSS and JS files in front-office |
|
60
|
|
|
*/ |
|
61
|
|
|
function add_scripts() { |
|
|
|
|
|
|
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' ); |
|
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 ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Add JS and CSS files in back-office |
|
72
|
|
|
*/ |
|
73
|
|
|
function add_scripts_in_admin( $hook ) { |
|
|
|
|
|
|
74
|
|
|
global $current_screen; |
|
75
|
|
|
if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) && $hook !== 'settings_page_wpshop_option' ) |
|
76
|
|
|
return; |
|
77
|
|
|
|
|
78
|
|
|
add_thickbox(); |
|
79
|
|
|
wp_enqueue_script('jquery'); |
|
80
|
|
|
wp_enqueue_script('jquery-ui-sortable'); |
|
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 ); |
|
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' ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
/** Load module/addon automatically to existing template list |
|
90
|
|
|
* |
|
91
|
|
|
* @param array $templates The current template definition |
|
92
|
|
|
* |
|
93
|
|
|
* @return array The template with new elements |
|
94
|
|
|
*/ |
|
95
|
|
|
// function custom_template_load( $templates ) { |
|
|
|
|
|
|
96
|
|
|
// include($this->template_dir.'wpshop/main_elements.tpl.php'); |
|
97
|
|
|
// $wpshop_display = new wpshop_display(); |
|
98
|
|
|
// $templates = $wpshop_display->add_modules_template_to_internal( $tpl_element, $templates ); |
|
99
|
|
|
// unset($tpl_element); |
|
100
|
|
|
|
|
101
|
|
|
// return $templates; |
|
|
|
|
|
|
102
|
|
|
// } |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Declare option groups for the module |
|
106
|
|
|
*/ |
|
107
|
|
|
function add_options( $option_group ) { |
|
|
|
|
|
|
108
|
|
|
$option_group['wpshop_shipping_option']['subgroups']['wps_shipping_mode']['class'] = ' wpshop_admin_box_options_shipping_mode'; |
|
109
|
|
|
return $option_group; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Create Options |
|
114
|
|
|
**/ |
|
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'); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* WPS Shipping mode Option Validator |
|
123
|
|
|
**/ |
|
124
|
|
|
function wpshop_options_validate_wps_shipping_mode( $input ) { |
|
|
|
|
|
|
125
|
|
|
$wps_shipping = new wps_shipping(); |
|
126
|
|
|
if ( !empty($input['modes']) ) { |
|
127
|
|
|
foreach( $input['modes'] as $mode => $mode_det ) { |
|
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'] ); |
|
130
|
|
|
|
|
131
|
|
|
/** Shipping Modes Logo Treatment **/ |
|
132
|
|
View Code Duplication |
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
|
|
|
$wp_upload_dir = wp_upload_dir(); |
|
137
|
|
|
$attachment = array( |
|
138
|
|
|
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename['name'] ), |
|
139
|
|
|
'post_mime_type' => $wp_filetype['type'], |
|
140
|
|
|
'post_title' => preg_replace(' /\.[^.]+$/', '', basename($filename['name'])), |
|
141
|
|
|
'post_content' => '', |
|
142
|
|
|
'post_status' => 'inherit' |
|
143
|
|
|
); |
|
144
|
|
|
$attach_id = wp_insert_attachment( $attachment, $upload['file']); |
|
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 ); |
|
148
|
|
|
|
|
149
|
|
|
$input['modes'][$mode]['logo'] = $attach_id; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
return $input; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Migrate Old Shipping Mode to the new storage system |
|
158
|
|
|
**/ |
|
159
|
|
|
function migrate_default_shipping_mode() { |
|
|
|
|
|
|
160
|
|
|
$data = array(); |
|
161
|
|
|
$shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
162
|
|
|
if ( empty($shipping_mode_option) ) { |
|
163
|
|
|
$data['modes']['default_shipping_mode']['active'] = 'on'; |
|
164
|
|
|
$data['modes']['default_shipping_mode']['name'] = __('Home Delivery', 'wpshop'); |
|
165
|
|
|
$data['modes']['default_shipping_mode']['explanation'] = __('Your purchase will be delivered directly to you at home', 'wpshop'); |
|
166
|
|
|
/** Check CUstom Shipping **/ |
|
167
|
|
|
$custom_shipping_option = get_option( 'wpshop_custom_shipping' ); |
|
168
|
|
|
if ( !empty($custom_shipping_option) ) { |
|
169
|
|
|
$data['modes']['default_shipping_mode']['custom_shipping_rules'] = $custom_shipping_option; |
|
170
|
|
|
} |
|
171
|
|
|
/** Check Country Limit **/ |
|
172
|
|
|
$limit_destination = get_option( 'wpshop_limit_shipping_destination' ); |
|
173
|
|
|
if ( !empty($custom_shipping_option) ) { |
|
174
|
|
|
$data['modes']['default_shipping_mode']['limit_destination'] = $limit_destination; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** Check Others shipping configurations **/ |
|
178
|
|
|
$wpshop_shipping_rules_option = get_option('wpshop_shipping_rules'); |
|
179
|
|
|
if ( !empty($wpshop_shipping_rules_option) ){ |
|
180
|
|
View Code Duplication |
if ( !empty($wpshop_shipping_rules_option['min_max']) ) { |
|
|
|
|
|
|
181
|
|
|
$data['modes']['default_shipping_mode']['min_max'] = $wpshop_shipping_rules_option['min_max']; |
|
182
|
|
|
} |
|
183
|
|
View Code Duplication |
if ( !empty($wpshop_shipping_rules_option['free_from']) ) { |
|
|
|
|
|
|
184
|
|
|
$data['modes']['default_shipping_mode']['free_from'] = $wpshop_shipping_rules_option['free_from']; |
|
185
|
|
|
} |
|
186
|
|
|
if ( !empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']) ) { |
|
187
|
|
|
$data['modes']['default_shipping_mode']['free_shipping'] = $wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']; |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
$data['default_choice'] = 'default_shipping_mode'; |
|
191
|
|
|
|
|
192
|
|
|
update_option( 'wps_shipping_mode', $data ); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Display the Admin Interface for Shipping Mode |
|
198
|
|
|
**/ |
|
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") ); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Generate Shipping mode configuration back-office interface |
|
206
|
|
|
* @param string $key |
|
|
|
|
|
|
207
|
|
|
* @param array $shipping_mode |
|
208
|
|
|
* @return string |
|
209
|
|
|
*/ |
|
210
|
|
|
function generate_shipping_mode_interface( $k, $shipping_mode ) { |
|
|
|
|
|
|
211
|
|
|
global $wpdb; |
|
212
|
|
|
$tpl_component = array(); |
|
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'] : ''; |
|
216
|
|
|
|
|
217
|
|
|
$countries = unserialize(WPSHOP_COUNTRY_LIST); |
|
218
|
|
|
|
|
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 ); |
|
223
|
|
|
|
|
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)) { |
|
227
|
|
|
$wps_shipping = new wps_shipping(); |
|
228
|
|
|
$fees_data = $wps_shipping->shipping_fees_array_2_string($fees_data); |
|
229
|
|
|
} |
|
230
|
|
|
ob_start(); |
|
231
|
|
|
require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface") ); |
|
232
|
|
|
$output = ob_get_contents(); |
|
233
|
|
|
ob_end_clean(); |
|
234
|
|
|
|
|
235
|
|
|
return $output; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Generate cutom fees resume table |
|
241
|
|
|
* @param array $fees_data |
|
242
|
|
|
* @param string $key |
|
|
|
|
|
|
243
|
|
|
*/ |
|
244
|
|
|
function generate_shipping_rules_table( $fees_data, $shipping_mode_id ){ |
|
|
|
|
|
|
245
|
|
|
global $wpdb; |
|
246
|
|
|
$result = ''; |
|
247
|
|
|
if ( !empty( $fees_data) ) { |
|
248
|
|
|
$wps_shipping = new wps_shipping(); |
|
249
|
|
|
$shipping_rules =$wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
250
|
|
|
$result = ''; |
|
251
|
|
|
$tpl_component =''; |
|
252
|
|
|
$tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = ''; |
|
253
|
|
|
$tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id; |
|
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 ); |
|
258
|
|
|
ob_start(); |
|
259
|
|
|
require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table") ); |
|
260
|
|
|
$result = ob_get_contents(); |
|
261
|
|
|
ob_end_clean(); |
|
262
|
|
|
} |
|
263
|
|
|
return $result; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* *********************************************** |
|
269
|
|
|
* NEW CHECKOUT TUNNEL FUNCTIONS FOR SHIPPING STEP |
|
270
|
|
|
* *********************************************** |
|
271
|
|
|
*/ |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Display shipping modes |
|
275
|
|
|
* @return string |
|
276
|
|
|
*/ |
|
277
|
|
|
function display_shipping_methods() { |
|
|
|
|
|
|
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) ) { |
|
283
|
|
|
$no_shipping_mode_for_area = true; |
|
|
|
|
|
|
284
|
|
|
} |
|
285
|
|
|
} |
|
286
|
|
|
$shipping_modes = apply_filters( 'wps_filter_shipping_methods', $shipping_modes ); |
|
|
|
|
|
|
287
|
|
|
ob_start(); |
|
288
|
|
|
require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container") ); |
|
289
|
|
|
$output = ob_get_contents(); |
|
290
|
|
|
ob_end_clean(); |
|
291
|
|
|
|
|
292
|
|
|
return $output; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* Display a shipping summary( Choosen Shipping & billing address, choosen shipping mode ) |
|
297
|
|
|
* @return string |
|
298
|
|
|
*/ |
|
299
|
|
|
function display_shipping_summary() { |
|
|
|
|
|
|
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; |
|
304
|
|
|
|
|
305
|
|
|
if( !empty($billing_address_id) ) { |
|
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); |
|
308
|
|
|
|
|
309
|
|
|
if ( !empty($shipping_address_id) && !empty($shipping_mode) ) { |
|
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); |
|
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'] : ''; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
ob_start(); |
|
318
|
|
|
require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary") ); |
|
319
|
|
|
$output = ob_get_contents(); |
|
320
|
|
|
ob_end_clean(); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
|
|
324
|
|
|
return $output; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* Return alla availables shipping modes for an address |
|
329
|
|
|
* @param integer $address_id |
|
330
|
|
|
* @return string |
|
331
|
|
|
*/ |
|
332
|
|
|
function get_shipping_mode_for_address( $address_id ) { |
|
|
|
|
|
|
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']) ) { |
|
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']) ) ) { |
|
342
|
|
|
/** Check Limit Destination By Postcode **/ |
|
343
|
|
|
$visible = true; |
|
344
|
|
|
/** Check Postcode limitation **/ |
|
345
|
|
View Code Duplication |
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
|
|
|
} |
|
350
|
|
|
if ( !in_array($address_metadata['postcode'], $postcodes) ) { |
|
351
|
|
|
$visible = false; |
|
352
|
|
|
} |
|
353
|
|
|
} |
|
354
|
|
|
/** Check Department limitation **/ |
|
355
|
|
|
$department = isset( $address_metadata['postcode'] ) ? substr( $address_metadata['postcode'], 0, 2 ) : ''; |
|
356
|
|
View Code Duplication |
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
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
if ( !in_array($department, $departments) ) { |
|
363
|
|
|
$visible = false; |
|
364
|
|
|
} |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
if ( $visible ) { |
|
368
|
|
|
$shipping_modes_to_display['modes'][$k] = $shipping_mode; |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
} |
|
375
|
|
|
return $shipping_modes_to_display; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* Display shipping informations in order administration panel |
|
381
|
|
|
* @param object $order : Order post infos |
|
382
|
|
|
*/ |
|
383
|
|
|
function order_shipping_box( $order ) { |
|
|
|
|
|
|
384
|
|
|
$shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
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'] : '' ); |
|
387
|
|
|
ob_start(); |
|
388
|
|
|
require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos") ); |
|
389
|
|
|
$output = ob_get_contents(); |
|
390
|
|
|
ob_end_clean(); |
|
391
|
|
|
echo $output; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* Shortcode to display efficient shipping. |
|
396
|
|
|
* @param array $atts Attributes : pid, shipping_mode. |
|
397
|
|
|
* @return float Shipping cost for product. |
|
398
|
|
|
*/ |
|
399
|
|
|
function get_shipping_cost_shortcode( $atts ) { |
|
|
|
|
|
|
400
|
|
|
$shipping_modes = get_option( 'wps_shipping_mode' ); |
|
|
|
|
|
|
401
|
|
|
$atts = shortcode_atts( array( |
|
402
|
|
|
'pid' => get_the_ID(), |
|
403
|
|
|
'shipping_mode' => '', |
|
404
|
|
|
), $atts, 'wps_product_shipping_cost' ); |
|
405
|
|
|
$atts['pid'] = intval( $atts['pid'] ); |
|
406
|
|
|
$wps_shipping = new wps_shipping(); |
|
407
|
|
|
$items = array( |
|
408
|
|
|
$atts['pid'] => array( |
|
409
|
|
|
'item_id' => $atts['pid'], |
|
410
|
|
|
'item_qty' => 1, |
|
411
|
|
|
), |
|
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'] ) ); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
} |
|
419
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.