PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
← All changes | functions/template_func.php +4321 -2221 1.3.172.12.4 View file →
@@ -1,154 +1,498 @@
1 1 <?php
2 -function usces_guid_tax( $out = '' ){
2 +/**
3 + * Template functions
4 + *
5 + * @package Welcart
6 + */
7 +
8 +/**
9 + * Tax guid
10 + *
11 + * @param string $out Return value or echo.
12 + * @param bool $tag HTML tag.
13 + * @return string|void
14 + */
15 +function usces_guid_tax( $out = '', $tag = true ) {
3 16 global $usces;
4 17
5 - if( $out == 'return' ){
6 - return $usces->getGuidTax();
7 - }else{
8 - echo $usces->getGuidTax();
18 + $guid_tax = '';
19 + if ( $tag ) {
20 + $guid_tax = $usces->getGuidTax();
21 + } else {
22 + if ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) {
23 + $guid_tax = '';
24 + } else {
25 + $tax_rate = (int) $usces->options['tax_rate'];
26 + if ( isset( $usces->options['tax_mode'] ) ) {
27 + if ( 'exclude' === $usces->options['tax_mode'] ) {
28 + $guid_tax = __( '(Excl. Tax)', 'usces' );
29 + } else {
30 + $guid_tax = __( '(Incl. Tax)', 'usces' );
31 + }
32 + } else {
33 + if ( 0 < $tax_rate ) {
34 + $guid_tax = __( '(Excl. Tax)', 'usces' );
35 + } else {
36 + $guid_tax = __( '(Incl. Tax)', 'usces' );
37 + }
38 + }
39 + }
9 40 }
41 +
42 + $guid_tax = apply_filters( 'usces_filter_guid_tax', $guid_tax );
43 +
44 + if ( 'return' === $out ) {
45 + return wel_esc_script( $guid_tax );
46 + } else {
47 + wel_esc_script_e( $guid_tax );
48 + }
10 49 }
11 50
51 +/**
52 + * Tax label
53 + *
54 + * @param array $data Order data.
55 + * @param string $out Return value or echo.
56 + * @return string|void
57 + */
58 +function usces_tax_label( $data = array(), $out = '' ) {
59 + global $usces;
60 +
61 + if ( empty( $data ) || ! array_key_exists( 'order_condition', $data ) ) {
62 + $condition = $usces->get_condition();
63 + $tax_mode = $usces->options['tax_mode'];
64 + } else {
65 + $condition = wel_safe_maybe_unserialize( $data['order_condition'] );
66 + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : $usces->options['tax_mode'];
67 + }
68 + if ( 'exclude' === $tax_mode ) {
69 + $label = __( 'consumption tax', 'usces' );
70 + } else {
71 + if ( isset( $condition['tax_mode'] ) && ! empty( $data['ID'] ) ) {
72 + $materials = array(
73 + 'total_items_price' => $data['order_item_total_price'],
74 + 'discount' => $data['order_discount'],
75 + 'shipping_charge' => $data['order_shipping_charge'],
76 + 'cod_fee' => $data['order_cod_fee'],
77 + 'use_point' => $data['order_usedpoint'],
78 + 'carts' => usces_get_ordercartdata( $data['ID'] ),
79 + 'condition' => $condition,
80 + 'order_id' => $data['ID'],
81 + );
82 + $label = __( 'Internal tax', 'usces' ) . '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
83 + } else {
84 + $label = __( 'Internal tax', 'usces' );
85 + }
86 + }
87 + $label = apply_filters( 'usces_filter_tax_label', $label );
88 +
89 + if ( 'return' === $out ) {
90 + return wel_esc_script( $label );
91 + } else {
92 + wel_esc_script_e( $label );
93 + }
94 +}
95 +
96 +/**
97 + * Tax Calculation
98 + *
99 + * @param array $data When the 'order' key in $data exist, entry data, unless order data.
100 + * @param string $out Return value or echo.
101 + * @return string|void
102 + */
103 +function usces_tax( $data, $out = '' ) {
104 + global $usces;
105 +
106 + if ( empty( $data ) || ! array_key_exists( 'order_condition', $data ) ) {
107 + $condition = $usces->get_condition();
108 + $tax_mode = $usces->options['tax_mode'];
109 + } else {
110 + $condition = wel_safe_maybe_unserialize( $data['order_condition'] );
111 + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : $usces->options['tax_mode'];
112 + }
113 +
114 + if ( ! usces_is_tax_display() ) {
115 + $tax_str = '';
116 + } else {
117 + if ( 'exclude' === $tax_mode ) {
118 + if ( array_key_exists( 'order', $data ) && array_key_exists( 'tax', $data['order'] ) ) { /* from Entry */
119 + $tax = $data['order']['tax'];
120 + } elseif ( array_key_exists( 'order_tax', $data ) ) { /* from Order Data */
121 + $tax = $data['order_tax'];
122 + } elseif ( array_key_exists( 'tax', $data ) ) {
123 + $tax = $data['tax'];
124 + } else {
125 + $tax = 0;
126 + }
127 + $tax_str = usces_crform( $tax, true, false, 'return' );
128 + } else {
129 + if ( array_key_exists( 'order', $data ) ) { /* from Entry */
130 + $materials = array(
131 + 'total_items_price' => $data['order']['total_items_price'],
132 + 'discount' => ( isset( $data['order']['discount'] ) ) ? $data['order']['discount'] : 0,
133 + 'shipping_charge' => ( isset( $data['order']['shipping_charge'] ) ) ? $data['order']['shipping_charge'] : 0,
134 + 'cod_fee' => ( isset( $data['order']['cod_fee'] ) ) ? $data['order']['cod_fee'] : 0,
135 + 'use_point' => ( isset( $data['order']['use_point'] ) ) ? $data['order']['use_point'] : 0,
136 + );
137 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
138 + } elseif ( array_key_exists( 'order_tax', $data ) ) { /* from Order Data */
139 + $materials = array(
140 + 'total_items_price' => $data['order_item_total_price'],
141 + 'discount' => $data['order_discount'],
142 + 'shipping_charge' => $data['order_shipping_charge'],
143 + 'cod_fee' => $data['order_cod_fee'],
144 + 'use_point' => $data['order_usedpoint'],
145 + 'carts' => usces_get_ordercartdata( $data['ID'] ),
146 + 'condition' => wel_safe_unserialize( $data['order_condition'] ),
147 + );
148 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
149 + } elseif ( array_key_exists( 'tax', $data ) ) {
150 + $item_total_price = $usces->get_total_price( $data['cart'] );
151 + $materials = array(
152 + 'total_items_price' => $item_total_price,
153 + 'discount' => ( isset( $data['discount'] ) ) ? $data['discount'] : 0,
154 + 'shipping_charge' => ( isset( $data['shipping_charge'] ) ) ? $data['shipping_charge'] : 0,
155 + 'cod_fee' => ( isset( $data['cod_fee'] ) ) ? $data['cod_fee'] : 0,
156 + 'use_point' => ( isset( $data['usedpoint'] ) ) ? $data['usedpoint'] : 0,
157 + 'carts' => $data['cart'],
158 + );
159 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
160 + } else {
161 + $materials = array();
162 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
163 + }
164 + }
165 + $tax_str = apply_filters( 'usces_filter_tax', $tax_str );
166 + }
167 +
168 + if ( 'return' === $out ) {
169 + return wel_esc_script( $tax_str );
170 + } else {
171 + wel_esc_script_e( $tax_str );
172 + }
173 +}
174 +
175 +/**
176 + * Order data tax
177 + *
178 + * @param array $data Order data.
179 + * @param string $tax_mode 'exclude' or 'include'.
180 + * @return string
181 + */
182 +function usces_order_history_tax( $data, $tax_mode ) {
183 + global $usces;
184 +
185 + if ( 'exclude' === $tax_mode ) {
186 + $tax_str = usces_crform( $data['tax'], true, false, 'return' );
187 + } else {
188 + $materials = array(
189 + 'total_items_price' => $data['total_items_price'],
190 + 'discount' => $data['discount'],
191 + 'shipping_charge' => $data['shipping_charge'],
192 + 'cod_fee' => $data['cod_fee'],
193 + 'use_point' => $data['usedpoint'],
194 + 'carts' => $data['cart'],
195 + 'condition' => $data['condition'],
196 + );
197 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
198 + }
199 + $tax_str = apply_filters( 'usces_filter_order_history_tax', $tax_str, $data, $tax_mode );
200 + return $tax_str;
201 +}
202 +
203 +/**
204 + * Tax-inclusive Calculation
205 + *
206 + * @param array $materials Breakdown of Amounts.
207 + * @param string $out Return value or echo.
208 + * @return string|void
209 + */
210 +function usces_internal_tax( $materials, $out = '' ) {
211 + global $usces;
212 +
213 + if ( ! usces_is_tax_display() ) {
214 + $tax = 0;
215 + } else {
216 + if ( ! empty( $materials['condition'] ) ) {
217 + $condition = $materials['condition'];
218 + } else {
219 + $condition = $usces->get_condition();
220 + }
221 + $reduced_taxrate = ( isset( $condition['applicable_taxrate'] ) && 'reduced' === $condition['applicable_taxrate'] ) ? true : false;
222 + if ( $reduced_taxrate ) {
223 + $usces_tax = Welcart_Tax::get_instance();
224 + $usces_tax->get_order_tax( $materials );
225 + $tax = apply_filters( 'usces_filter_internal_tax', $usces_tax->tax, $materials );
226 + } else {
227 + if ( 1 === (int) usces_point_coverage() ) {
228 + if ( 'products' === $condition['tax_target'] ) {
229 + $total = $materials['total_items_price'] + $materials['discount'];
230 + } else {
231 + $total = $materials['total_items_price'] + $materials['discount'] + $materials['shipping_charge'] + $materials['cod_fee'];
232 + }
233 + } else {
234 + if ( 'products' === $condition['tax_target'] ) {
235 + $total = $materials['total_items_price'] + $materials['discount'];
236 + } else {
237 + $use_point = ( empty( $materials['use_point'] ) ) ? 0 : $materials['use_point'];
238 + $total = $materials['total_items_price'] + $materials['discount'] - $use_point + $materials['shipping_charge'] + $materials['cod_fee'];
239 + }
240 + }
241 + $total = apply_filters( 'usces_filter_internal_tax_total', $total, $materials );
242 + $tax_rate = (float) $condition['tax_rate'];
243 + $tax_method = ( isset( $condition['tax_method'] ) ) ? $condition['tax_method'] : $usces->options['tax_method'];
244 + $tax = $total * $tax_rate / 100;
245 + $tax = $total - $total / ( 1 + ( $tax_rate / 100 ) );
246 + $tax = usces_tax_rounding_off( $tax, $tax_method );
247 + $tax = apply_filters( 'usces_filter_internal_tax', $tax, $materials );
248 + }
249 + }
250 +
251 + if ( 'return' === $out ) {
252 + return wel_esc_script( $tax );
253 + } else {
254 + wel_esc_script_e( $tax );
255 + }
256 +}
257 +
258 +/**
259 + * Currency Symbol
260 + *
261 + * @param string $out Return value or echo.
262 + * @return string|void
263 + */
12 264 function usces_currency_symbol( $out = '' ) {
13 265 global $usces;
14 266
15 - if( $out == 'return' ){
267 + if ( 'return' === $out ) {
16 268 return $usces->getCurrencySymbol();
17 - }else{
18 - echo esc_html($usces->getCurrencySymbol());
269 + } else {
270 + echo esc_html( $usces->getCurrencySymbol() );
19 271 }
20 272 }
21 273
274 +/**
275 + * Error Verification
276 + *
277 + * @return bool
278 + */
22 279 function usces_is_error_message() {
23 280 global $usces;
24 - if ( $usces->error_message != '' )
281 +
282 + if ( '' !== $usces->error_message ) {
25 283 return true;
26 - else
284 + } else {
27 285 return false;
286 + }
28 287 }
29 288
30 -function usces_is_item( $post_id = NULL ) {
31 - if( NULL == $post_id ){
289 +/**
290 + * Is item
291 + *
292 + * @param int $post_id Post ID.
293 + * @return bool
294 + */
295 +function usces_is_item( $post_id = null ) {
296 + if ( null === $post_id ) {
32 297 global $post;
33 - }else{
34 - $post = get_post($post_id);
298 + if ( empty( $post->ID ) ) {
299 + return false;
300 + }
301 + $post_id = $post->ID;
35 302 }
36 - if ( isset($post->post_mime_type) && $post->post_mime_type == 'item' )
303 + $product = wel_get_product( $post_id );
304 + if ( isset( $product['_pst'] ) && 'item' === $product['_pst']->post_mime_type ) {
37 305 return true;
38 - else
306 + } else {
39 307 return false;
308 + }
40 309 }
41 310
311 +/**
312 + * Item code
313 + *
314 + * @param string $out Return value or echo.
315 + * @return string|void
316 + */
42 317 function usces_the_itemCode( $out = '' ) {
43 318 global $post;
44 - $post_id = $post->ID;
45 319
46 - $str = get_post_meta($post_id, '_itemCode', true);
47 -
48 - if( $out == 'return' ){
320 + $product = wel_get_product( $post->ID );
321 + $str = $product['itemCode'];
322 +
323 + if ( 'return' === $out ) {
49 324 return $str;
50 - }else{
51 - echo esc_html($str);
325 + } else {
326 + echo esc_html( $str );
52 327 }
53 328 }
54 329
55 -function usces_the_itemName( $out = '', $post = NULL ) {
56 - if($post == NULL)
330 +/**
331 + * Item name
332 + *
333 + * @param string $out Return value or echo.
334 + * @param object $post Post data.
335 + * @return string|void
336 + */
337 +function usces_the_itemName( $out = '', $post = null ) {
338 + if ( null === $post ) {
57 339 global $post;
58 -
59 - $post_id = $post->ID;
340 + }
60 341
61 - $str = get_post_meta($post_id, '_itemName', true);
62 -
63 - if( $out == 'return' ){
342 + $product = wel_get_product( $post );
343 + $str = $product['itemName'];
344 +
345 + if ( 'return' === $out ) {
64 346 return $str;
65 - }else{
66 - echo esc_html($str);
347 + } else {
348 + echo esc_html( $str );
67 349 }
68 350 }
69 351
70 -function usces_the_point_rate( $out = '' ){
352 +/**
353 + * Point rate
354 + *
355 + * @param string $out Return value or echo.
356 + * @return string|void
357 + */
358 +function usces_the_point_rate( $out = '' ) {
71 359 global $post;
72 - $post_id = $post->ID;
73 360
74 - $str = get_post_meta($post_id, '_itemPointrate', true);
75 - $rate = (int)$str;
76 -
77 - if( $out == 'return' ){
361 + $product = wel_get_product( $post );
362 + $str = $product['itemPointrate'];
363 + $rate = (int) $str;
364 +
365 + if ( 'return' === $out ) {
78 366 return $rate;
79 - }else{
80 - echo esc_html($rate);
367 + } else {
368 + echo esc_html( $rate );
81 369 }
82 370 }
83 371
84 -function usces_the_shipment_aim( $out = '' ){
372 +/**
373 + * Shipment
374 + *
375 + * @param string $out Return value or echo.
376 + * @return string|void
377 + */
378 +function usces_the_shipment_aim( $out = '' ) {
85 379 global $post;
86 - $post_id = $post->ID;
87 380
88 - $str = get_post_meta($post_id, '_itemShipping', true);
89 - $no = (int)$str;
90 - if( 0 === $no ) return;
91 -
92 - $rules = get_option('usces_shipping_rule');
93 -
94 - if( $out == 'return' ){
95 - return $rules[$no];
96 - }else{
97 - echo esc_html($rules[$no]);
381 + $product = wel_get_product( $post );
382 + $str = $product['itemShipping'];
383 + $no = (int) $str;
384 + if ( 0 === $no ) {
385 + return '';
98 386 }
387 + $rules = get_option( 'usces_shipping_rule', array() );
388 +
389 + if ( 'return' === $out ) {
390 + return $rules[ $no ];
391 + } else {
392 + echo esc_html( $rules[ $no ] );
393 + }
99 394 }
100 395
101 -function usces_the_item(){
396 +/**
397 + * Current item
398 + */
399 +function usces_the_item() {
102 400 global $usces, $post;
103 -
104 - $usces->itemskus = $usces->get_skus($post->ID, 'sort');
105 - $usces->itemopts = usces_get_opts($post->ID, 'sort');
106 -
401 +
402 + $usces->itemskus = wel_get_skus( $post );
403 + $usces->current_itemsku = -1;
404 + $usces->itemopts = wel_get_opts( $post );
405 + $usces->current_itemopt = -1;
406 +
107 407 return;
108 408 }
109 409
110 -function usces_get_itemMeta($metakey, $post_id, $out = ''){
111 - $str = get_post_meta($post_id, $metakey, true);
112 - $value = $str;
113 -
114 - if( $out == 'return' ){
410 +/**
411 + * Get item meta
412 + *
413 + * @param string $metakey Meta key.
414 + * @param int $post_id Post ID.
415 + * @param string $out Return value or echo.
416 + * @return string|void
417 + */
418 +function usces_get_itemMeta( $metakey, $post_id, $out = '' ) {
419 + $product = wel_get_product( $post_id );
420 + $reserved_key = ltrim( $metakey, '_' );
421 +
422 + if ( array_key_exists( $reserved_key, $product ) ) {
423 + $meta = $product[ $reserved_key ];
424 + } else {
425 + $meta = $product[ $metakey ];
426 + }
427 + if ( is_array( $meta ) ) {
428 + $value = $meta[0];
429 + } else {
430 + $value = $meta;
431 + }
432 +
433 + if ( 'return' === $out ) {
115 434 return $value;
116 - }else{
117 - echo esc_html($value);
435 + } else {
436 + echo esc_html( $value );
118 437 }
119 438 }
120 439
440 +/**
441 + * Count SKU
442 + *
443 + * @return int
444 + */
121 445 function usces_sku_num() {
122 446 global $usces;
123 -
124 - return count($usces->itemskus);
447 +
448 + $sku_num = ( ! empty( $usces->itemskus ) && is_array( $usces->itemskus ) ) ? count( $usces->itemskus ) : 0;
449 + return $sku_num;
125 450 }
126 451
452 +/**
453 + * Is SKU
454 + *
455 + * @return bool
456 + */
127 457 function usces_is_skus() {
128 458 global $usces;
129 -
130 - if( 0 < count($usces->itemskus) ){
131 - reset($usces->itemskus);
459 +
460 + if ( ! empty( $usces->itemskus ) && is_array( $usces->itemskus ) && 0 < count( $usces->itemskus ) ) {
461 + $usces->current_itemsku = -1;
462 + reset( $usces->itemskus );
132 463 $usces->itemsku = array();
133 464 return true;
134 - }else{
465 + } else {
135 466 return false;
136 467 }
137 468 }
138 469
470 +/**
471 + * Reset SKU
472 + */
139 473 function usces_reset_skus() {
140 474 global $usces;
141 -
142 - reset($usces->itemskus);
475 +
476 + $usces->current_itemsku = -1;
477 + reset( $usces->itemskus );
143 478 }
144 479
480 +/**
481 + * Have SKU
482 + *
483 + * @return bool
484 + */
145 485 function usces_have_skus() {
146 486 global $usces;
147 -
148 - $res_each = each($usces->itemskus);
149 - $usces->itemsku = $res_each['value'];
150 - if($usces->itemsku) {
487 +
488 + if ( null === $usces->current_itemsku ) {
489 + $usces->current_itemsku = -1;
490 + }
491 +
492 + if ( $usces->current_itemsku + 1 < usces_sku_num() ) {
493 + $usces->current_itemsku++;
494 + $usces->itemsku = $usces->itemskus[ $usces->current_itemsku ];
151 495 return true;
152 496 } else {
153 497 return false;
154 498 }
@@ -153,695 +497,1251 @@
153 497 return false;
154 498 }
155 499 }
156 500
157 -function usces_the_itemSku($out = '') {
501 +/**
502 + * SKU data
503 + *
504 + * @param string $out Return value or echo.
505 + * @return string|void
506 + */
507 +function usces_the_itemSku( $out = '' ) {
158 508 global $usces;
159 509
160 - if($out == 'return'){
161 - return $usces->itemsku['code'];
162 - }else{
163 - echo esc_attr($usces->itemsku['code']);
510 + $skucode = isset( $usces->itemsku['code'] ) ? $usces->itemsku['code'] : '';
511 + if ( 'return' === $out ) {
512 + return $skucode;
513 + } else {
514 + echo esc_attr( $skucode );
164 515 }
165 516 }
166 517
167 -function usces_the_itemPrice($out = '') {
518 +/**
519 + * SKU price
520 + *
521 + * @param string $out Return value or echo.
522 + * @return int|void
523 + */
524 +function usces_the_itemPrice( $out = '' ) {
168 525 global $usces;
169 - if($out == 'return'){
526 +
527 + if ( 'return' === $out ) {
170 528 return $usces->itemsku['price'];
171 - }else{
172 - echo number_format($usces->itemsku['price']);
529 + } else {
530 + echo number_format( $usces->itemsku['price'] );
173 531 }
174 532 }
175 533
176 -function usces_the_itemCprice($out = '') {
534 +/**
535 + * SKU normal price
536 + *
537 + * @param string $out Return value or echo.
538 + * @return int|void
539 + */
540 +function usces_the_itemCprice( $out = '' ) {
177 541 global $usces;
178 - if($out == 'return'){
542 +
543 + if ( 'return' === $out ) {
179 544 return $usces->itemsku['cprice'];
180 - }else{
181 - echo number_format($usces->itemsku['cprice']);
545 + } else {
546 + echo number_format( $usces->itemsku['cprice'] );
182 547 }
183 548 }
184 549
185 -function usces_the_itemPriceCr($out = '') {
550 +/**
551 + * Formatted SKU price
552 + *
553 + * @param string $out Return value or echo.
554 + * @return string|void
555 + */
556 +function usces_the_itemPriceCr( $out = '' ) {
186 557 global $usces;
187 - $res = esc_html($usces->get_currency($usces->itemsku['price'], true, false ));
188 558
189 - if($out == 'return'){
559 + $res = $usces->get_currency( $usces->itemsku['price'], true, false );
560 + $res = apply_filters( 'usces_filter_the_item_price_cr', $res, $usces->itemsku['price'], $out );
561 +
562 + if ( 'return' === $out ) {
190 563 return $res;
191 - }else{
192 - echo $res;
564 + } else {
565 + echo esc_html( $res );
193 566 }
194 567 }
195 568
196 -function usces_the_itemCpriceCr($out = '') {
569 +/**
570 + * Formatted normal SKU price
571 + *
572 + * @param string $out Return value or echo.
573 + * @return string|void
574 + */
575 +function usces_the_itemCpriceCr( $out = '' ) {
197 576 global $usces;
198 - $res = esc_html($usces->get_currency($usces->itemsku['cprice'], true, false ));
199 577
200 - if($out == 'return'){
578 + $res = $usces->get_currency( $usces->itemsku['cprice'], true, false );
579 + $res = apply_filters( 'usces_filter_the_item_cprice_cr', $res, $usces->itemsku['cprice'], $out );
580 +
581 + if ( 'return' === $out ) {
201 582 return $res;
202 - }else{
203 - echo $res;
583 + } else {
584 + echo esc_html( $res );
204 585 }
205 586 }
206 587
588 +/**
589 + * Currency code
590 + *
591 + * @param string $out Return value or echo.
592 + * @return string|void
593 + */
207 594 function usces_crcode( $out = '' ) {
208 595 global $usces;
209 - $res = esc_html($usces->get_currency_code());
210 -
211 - if($out == 'return'){
596 +
597 + $res = esc_html( $usces->get_currency_code() );
598 +
599 + if ( 'return' === $out ) {
212 600 return $res;
213 - }else{
214 - echo __($res, 'usces');
601 + } else {
602 + echo __( $res, 'usces' );
215 603 }
216 604 }
217 605
218 -function usces_crsymbol( $out = '', $js = NULL ) {
606 +/**
607 + * Currency symbol code
608 + *
609 + * @param string $out Return value or echo.
610 + * @param string $js Use js.
611 + * @return string|void
612 + */
613 +function usces_crsymbol( $out = '', $js = '' ) {
219 614 global $usces;
615 +
220 616 $res = $usces->getCurrencySymbol();
221 - if( 'js' === $js && '&yen;' == $res ){
222 - $res = mb_convert_encoding($res, 'UTF-8', 'HTML-ENTITIES');
617 + if ( 'js' === $js && '&yen;' == $res ) {
618 + $res = mb_convert_encoding( $res, 'UTF-8', 'HTML-ENTITIES' );
223 619 }
224 -
225 - if($out == 'return'){
620 + if ( 'return' === $out ) {
226 621 return $res;
227 - }else{
228 - echo esc_html($res);
622 + } else {
623 + echo esc_html( $res );
229 624 }
230 625 }
231 626
627 +/**
628 + * Stock
629 + *
630 + * @param string $out Return value or echo.
631 + * @return string|void
632 + */
232 633 function usces_the_itemZaiko( $out = '' ) {
233 - global $usces;
234 - $num = (int)$usces->itemsku['stock'];
235 -
236 - if( 1 < $num || ( 0 === (int)$usces->itemsku['stocknum'] && !WCUtils::is_blank($usces->itemsku['stocknum']) ) ){
237 - $res = $usces->zaiko_status[$num];
238 - }elseif( 1 >= $num && ( 0 === (int)$usces->itemsku['stocknum'] && !WCUtils::is_blank($usces->itemsku['stocknum']) ) ){
239 - $res = $usces->zaiko_status[2];
240 - }else{
241 - $res = $usces->zaiko_status[$num];
634 + global $usces, $post;
635 +
636 + $item_order_acceptable = $usces->getItemOrderAcceptable( $post->ID );
637 + $num = (int) $usces->itemsku['stock'];
638 + $stocknum = $usces->itemsku['stocknum'];
639 +
640 + if ( 1 !== $item_order_acceptable || WCUtils::is_blank( $stocknum ) ) {
641 + if ( 1 < $num || ( 0 === (int) $usces->itemsku['stocknum'] && ! WCUtils::is_blank( $usces->itemsku['stocknum'] ) ) ) {
642 + $res = $usces->zaiko_status[ $num ];
643 + } elseif ( 1 >= $num && ( 0 === (int) $usces->itemsku['stocknum'] && ! WCUtils::is_blank( $usces->itemsku['stocknum'] ) ) ) {
644 + $res = $usces->zaiko_status[2];
645 + } else {
646 + $res = $usces->zaiko_status[ $num ];
647 + }
648 + } else {
649 + if ( 1 < $num ) {
650 + $res = $usces->zaiko_status[ $num ];
651 + } elseif ( 1 >= $num && 0 >= (int) $stocknum ) {
652 + $res = ( ! empty( $usces->options['order_acceptable_label'] ) ) ? $usces->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
653 + } else {
654 + $res = $usces->zaiko_status[ $num ];
655 + }
242 656 }
243 -
244 - if( $out == 'return' ){
657 +
658 + if ( 'return' === $out ) {
245 659 return $res;
246 - }else{
247 - echo esc_html($res);
660 + } else {
661 + echo esc_html( $res );
248 662 }
249 663 }
250 664
665 +/**
666 + * Stock status
667 + *
668 + * @param string $out Return value or echo.
669 + * @return string|void
670 + */
251 671 function usces_the_itemZaikoStatus( $out = '' ) {
252 672 global $usces;
253 -
254 - if( $out == 'return' ){
673 +
674 + if ( 'return' === $out ) {
255 675 return usces_get_itemZaiko( 'name' );
256 - }else{
257 - echo esc_html(usces_get_itemZaiko( 'name' ));
676 + } else {
677 + echo esc_html( usces_get_itemZaiko( 'name' ) );
258 678 }
259 679 }
260 680
261 -function usces_get_itemZaiko( $field = 'name', $post_id=NULL, $sku=NULL ) {
681 +/**
682 + * SKU stock
683 + *
684 + * @param string $field Key.
685 + * @param int $post_id Post ID.
686 + * @param string $sku SKU code.
687 + * @return string
688 + */
689 +function usces_get_itemZaiko( $field = 'name', $post_id = null, $sku = null ) {
262 690 global $usces;
263 - if( empty($sku) ){
264 - $num = (int)$usces->itemsku['stock'];
265 - }else{
266 - $skus = $usces->get_skus( $post_id, 'code' );
267 - $num = (int)$skus[$sku]['stock'];
691 +
692 + if ( null === $post_id ) {
693 + global $post;
694 + $post_id = $post->ID;
268 695 }
269 -
270 - if( 'id' == $field ){
696 +
697 + if ( empty( $sku ) && ! empty( $usces->itemsku ) ) {
698 + $num = (int) $usces->itemsku['stock'];
699 + $stocknum = $usces->itemsku['stocknum'];
700 + } else {
701 + $skus = wel_get_skus( $post_id, 'code' );
702 + if ( null === $skus || ! isset( $skus[ $sku ] ) ) {
703 + return false;
704 + }
705 + $num = (int) $skus[ $sku ]['stock'];
706 + $stocknum = $skus[ $sku ]['stocknum'];
707 + }
708 +
709 + if ( 'id' === $field ) {
271 710 $res = $num;
272 - }else{
273 - $res = $usces->zaiko_status[$num];
711 + } else {
712 + $item_order_acceptable = $usces->getItemOrderAcceptable( $post_id );
713 + if ( 1 !== (int) $item_order_acceptable || WCUtils::is_blank( $stocknum ) ) {
714 + $res = $usces->zaiko_status[ $num ];
715 + } else {
716 + if ( 2 > $num && 0 >= (int) $stocknum ) {
717 + $res = ( ! empty( $usces->options['order_acceptable_label'] ) ) ? $usces->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
718 + } else {
719 + $res = $usces->zaiko_status[ $num ];
720 + }
721 + }
274 722 }
275 723 return $res;
276 724 }
277 725
726 +/**
727 + * SKU stock
728 + *
729 + * @param string $out Return value or echo.
730 + * @return int|void
731 + */
278 732 function usces_the_itemZaikoNum( $out = '' ) {
279 733 global $usces;
734 +
735 + if ( ! isset( $usces->itemsku['stocknum'] ) ) {
736 + return false;
737 + }
738 +
280 739 $num = $usces->itemsku['stocknum'];
281 -
282 - if( $out == 'return' ){
740 + if ( '' !== $num ) {
741 + $num = (int) $num;
742 + }
743 +
744 + if ( 'return' === $out ) {
283 745 return $num;
284 - }else{
285 - echo number_format($num);
746 + } else {
747 + echo number_format( $num );
286 748 }
287 749 }
288 750
751 +/**
752 + * SKU title
753 + *
754 + * @param string $out Return value or echo.
755 + * @return string|void
756 + */
289 757 function usces_the_itemSkuDisp( $out = '' ) {
290 758 global $usces;
291 -
292 - if( $out == 'return' ){
759 +
760 + if ( ! isset( $usces->itemsku['name'] ) ) {
761 + return false;
762 + }
763 +
764 + if ( 'return' === $out ) {
293 765 return $usces->itemsku['name'];
294 - }else{
295 - echo esc_html($usces->itemsku['name']);
766 + } else {
767 + echo esc_html( $usces->itemsku['name'] );
296 768 }
297 769 }
298 770
771 +/**
772 + * SKU unit
773 + *
774 + * @param string $out Return value or echo.
775 + * @return string|void
776 + */
299 777 function usces_the_itemSkuUnit( $out = '' ) {
300 778 global $usces;
301 -
302 - if( $out == 'return' ){
779 +
780 + if ( ! isset( $usces->itemsku['unit'] ) ) {
781 + return false;
782 + }
783 +
784 + if ( 'return' === $out ) {
303 785 return $usces->itemsku['unit'];
304 - }else{
305 - echo esc_html($usces->itemsku['unit']);
786 + } else {
787 + echo esc_html( $usces->itemsku['unit'] );
306 788 }
307 789 }
308 790
791 +/**
792 + * Top SKU code
793 + *
794 + * @param string $out Return value or echo.
795 + * @return string|void
796 + */
309 797 function usces_the_firstSku( $out = '' ) {
310 798 global $post, $usces;
799 +
311 800 $post_id = $post->ID;
312 -
313 -
314 - $skus = $usces->get_skus( $post_id );
315 -
801 + $skus = wel_get_skus( $post_id );
316 802
317 - if($out == 'return'){
803 + if ( null === $skus || ! isset( $skus[0]['code'] ) ) {
804 + return false;
805 + }
806 +
807 + if ( 'return' === $out ) {
318 808 return $skus[0]['code'];
319 - }else{
320 - echo esc_html($skus[0]['code']);
809 + } else {
810 + echo esc_html( $skus[0]['code'] );
321 811 }
322 812 }
323 813
324 -function usces_the_firstPrice( $out = '', $post = NULL ) {
814 +/**
815 + * Top SKU price
816 + *
817 + * @param string $out Return value or echo.
818 + * @param object $post Post data.
819 + * @return string|void
820 + */
821 +function usces_the_firstPrice( $out = '', $post = null ) {
325 822 global $usces;
326 - if($post == NULL)
823 +
824 + if ( null === $post ) {
327 825 global $post;
826 + }
328 827 $post_id = $post->ID;
329 -
330 - $skus = $usces->get_skus( $post_id );
331 -
332 - if($out == 'return'){
333 - return $skus[0]['price'];
334 - }else{
335 - echo number_format($skus[0]['price']);
828 + $skus = wel_get_skus( $post_id );
829 +
830 + if ( empty( $skus ) ) {
831 + $price = null;
832 + } else {
833 + $price = $skus[0]['price'];
336 834 }
835 +
836 + $price = apply_filters( 'usces_filter_the_first_price', $price, $post_id, $skus, $out );
837 +
838 + if ( 'return' === $out ) {
839 + return $price;
840 + } else {
841 + echo number_format( $price );
842 + }
337 843 }
338 844
339 -function usces_the_firstCprice( $out = '', $post = NULL ) {
845 +/**
846 + * Top SKU normal price
847 + *
848 + * @param string $out Return value or echo.
849 + * @param object $post Post data.
850 + * @return string|void
851 + */
852 +function usces_the_firstCprice( $out = '', $post = null ) {
340 853 global $usces;
341 - if($post == NULL)
854 +
855 + if ( null === $post ) {
342 856 global $post;
857 + }
343 858 $post_id = $post->ID;
344 -
345 - $skus = $usces->get_skus( $post_id );
346 -
347 - if($out == 'return'){
859 + $skus = wel_get_skus( $post_id );
860 +
861 + if ( null === $skus || ! isset( $skus[0]['cprice'] ) ) {
862 + return false;
863 + }
864 +
865 + if ( 'return' === $out ) {
348 866 return $skus[0]['cprice'];
349 - }else{
350 - echo number_format($skus[0]['cprice']);
867 + } else {
868 + echo number_format( $skus[0]['cprice'] );
351 869 }
352 870 }
353 871
354 -function usces_the_firstPriceCr( $out = '', $post = NULL ) {
872 +/**
873 + * Formatted top SKU price
874 + *
875 + * @param string $out Return value or echo.
876 + * @param object $post Post data.
877 + * @return string|void
878 + */
879 +function usces_the_firstPriceCr( $out = '', $post = null ) {
355 880 global $usces;
356 - if($post == NULL)
881 +
882 + if ( null === $post ) {
357 883 global $post;
884 + }
358 885 $post_id = $post->ID;
359 -
360 - $skus = $usces->get_skus( $post_id );
361 - $res = esc_html($usces->get_currency($skus[0]['price'], true, false ));
886 + $skus = wel_get_skus( $post_id );
887 + if ( isset( $skus[0]['price'] ) ) {
888 + $res = $usces->get_currency( $skus[0]['price'], true, false );
889 + $price = apply_filters( 'usces_filter_the_first_price_cr', $res, $skus[0]['price'], $post_id, $skus, $out );
890 + } else {
891 + $price = apply_filters( 'usces_filter_the_first_price_cr', '', null, $post_id, $skus, $out );
892 + }
362 893
363 - if($out == 'return'){
364 - return $res;
365 - }else{
366 - echo $res;
894 + if ( 'return' === $out ) {
895 + return $price;
896 + } else {
897 + echo esc_html( $price );
367 898 }
368 899 }
369 900
370 -function usces_the_firstCpriceCr( $out = '', $post = NULL ) {
901 +/**
902 + * Formatted top SKU normal price
903 + *
904 + * @param string $out Return value or echo.
905 + * @param object $post Post data.
906 + * @return string|void
907 + */
908 +function usces_the_firstCpriceCr( $out = '', $post = null ) {
371 909 global $usces;
372 - if($post == NULL)
910 +
911 + if ( null === $post ) {
373 912 global $post;
913 + }
374 914 $post_id = $post->ID;
375 -
376 - $skus = $usces->get_skus( $post_id );
377 - $res = esc_html($usces->get_currency($skus[0]['cprice'], true, false ));
915 + $skus = wel_get_skus( $post_id );
916 + if ( isset( $skus[0]['cprice'] ) ) {
917 + $res = $usces->get_currency( $skus[0]['cprice'], true, false );
918 + $cprice = apply_filters( 'usces_filter_the_first_cprice_cr', $res, $skus[0]['cprice'], $post_id, $skus, $out );
919 + } else {
920 + $cprice = apply_filters( 'usces_filter_the_first_cprice_cr', '', null, $post_id, $skus, $out );
921 + }
378 922
379 - if($out == 'return'){
380 - return $res;
381 - }else{
382 - echo $res;
923 + if ( 'return' === $out ) {
924 + return $cprice;
925 + } else {
926 + echo esc_html( $cprice );
383 927 }
384 928 }
385 929
386 -function usces_the_firstZaiko( $out = '' ) {
387 - global $post, $usces;
930 +/**
931 + * Top SKU stock
932 + *
933 + * @param string $out Return value or echo.
934 + * @param object $post Post data.
935 + * @return string|void
936 + */
937 +function usces_the_firstZaiko( $out = '', $post = null ) {
938 + global $usces;
939 +
940 + if ( null === $post ) {
941 + global $post;
942 + }
388 943 $post_id = $post->ID;
389 -
390 -
391 - $skus = $usces->get_skus( $post_id );
392 -
393 - if($out == 'return'){
944 + $skus = wel_get_skus( $post_id );
945 +
946 + if ( 'return' === $out ) {
394 947 return $skus[0]['stock'];
395 - }else{
396 - echo esc_html($skus[0]['stock']);
948 + } else {
949 + echo esc_html( $skus[0]['stock'] );
397 950 }
398 951 }
399 952
400 -function usces_the_lastSku( $out = '' ) {
401 - global $post, $usces;
953 +/**
954 + * Last SKU
955 + *
956 + * @param string $out Return value or echo.
957 + * @param object $post Post data.
958 + * @return string|void
959 + */
960 +function usces_the_lastSku( $out = '', $post = null ) {
961 + global $usces;
962 +
963 + if ( null === $post ) {
964 + global $post;
965 + }
402 966 $post_id = $post->ID;
403 -
404 -
405 - $skus = $usces->get_skus( $post_id );
406 - $sku = end($skus);
967 + $skus = wel_get_skus( $post_id );
968 + $sku = end( $skus );
407 969
408 - if($out == 'return'){
970 + if ( 'return' === $out ) {
409 971 return $sku['code'];
410 - }else{
411 - echo esc_html($sku['code']);
972 + } else {
973 + echo esc_html( $sku['code'] );
412 974 }
413 975 }
414 976
415 -function usces_the_lastPrice( $out = '' ) {
416 - global $post, $usces;
977 +/**
978 + * Last SKU price
979 + *
980 + * @param string $out Return value or echo.
981 + * @param object $post Post data.
982 + * @return string|void
983 + */
984 +function usces_the_lastPrice( $out = '', $post = null ) {
985 + global $usces;
986 +
987 + if ( null === $post ) {
988 + global $post;
989 + }
417 990 $post_id = $post->ID;
418 -
419 -
420 - $skus = $usces->get_skus( $post_id );
421 - $sku = end($skus);
422 -
423 - if($out == 'return'){
991 + $skus = wel_get_skus( $post_id );
992 + $sku = end( $skus );
993 +
994 + if ( 'return' === $out ) {
424 995 return $sku['price'];
425 - }else{
426 - echo number_format($sku['price']);
996 + } else {
997 + echo number_format( $sku['price'] );
427 998 }
428 999 }
429 1000
430 -function usces_the_lastZaiko( $out = '' ) {
431 - global $post, $usces;
1001 +/**
1002 + * Last SKU stock
1003 + *
1004 + * @param string $out Return value or echo.
1005 + * @param object $post Post data.
1006 + * @return string|void
1007 + */
1008 +function usces_the_lastZaiko( $out = '', $post = null ) {
1009 + global $usces;
1010 +
1011 + if ( null === $post ) {
1012 + global $post;
1013 + }
432 1014 $post_id = $post->ID;
433 -
434 -
435 - $skus = $usces->get_skus( $post_id );
436 - $sku = end($skus);
437 -
438 - if($out == 'return'){
1015 + $skus = wel_get_skus( $post_id );
1016 + $sku = end( $skus );
1017 +
1018 + if ( 'return' === $out ) {
439 1019 return $sku['stock'];
440 - }else{
441 - echo esc_html($sku['stock']);
1020 + } else {
1021 + echo esc_html( $sku['stock'] );
442 1022 }
443 1023 }
444 1024
445 -function usces_have_zaiko(){
1025 +/**
1026 + * In stock
1027 + *
1028 + * @return bool
1029 + */
1030 +function usces_have_zaiko() {
446 1031 global $post, $usces;
447 - return $usces->is_item_zaiko( $post->ID, $usces->itemsku['code'] );
1032 +
1033 + $post_id = isset( $post->ID ) ? $post->ID : 0;
1034 + $sku_code = isset( $usces->itemsku['code'] ) ? $usces->itemsku['code'] : '';
1035 +
1036 + return $usces->is_item_zaiko( $post_id, $sku_code );
448 1037 }
449 1038
450 -function usces_have_zaiko_anyone( $post_id = NULL ){
451 - global $post, $usces;
452 - if( NULL == $post_id ) $post_id = $post->ID;
453 -
454 - $skus = $usces->get_skus($post_id);
1039 +/**
1040 + * In stock
1041 + *
1042 + * @param int $post_id Post ID.
1043 + * @return bool
1044 + */
1045 +function usces_have_zaiko_anyone( $post_id = null ) {
1046 + global $post, $usces;
1047 +
1048 + if ( null === $post_id ) {
1049 + $post_id = $post->ID;
1050 + }
1051 +
1052 + $skus = wel_get_skus( $post_id );
455 1053 $status = false;
456 - foreach($skus as $sku){
457 - if( (WCUtils::is_blank($sku['stocknum']) || 0 < (int)$sku['stocknum']) && 2 > (int)$sku['stock']) {
1054 +
1055 + foreach ( $skus as $sku ) {
1056 + if ( $usces->is_item_zaiko( $post_id, $sku['code'] ) ) {
458 1057 $status = true;
459 1058 break;
460 1059 }
461 1060 }
462 - return $status;
1061 + return apply_filters( 'usces_have_zaiko_anyone', $status, $post_id, $skus );
463 1062 }
464 1063
465 -function usces_is_gptekiyo( $post_id, $sku, $quant ){
1064 +/**
1065 + * Low or not stock
1066 + *
1067 + * @param int $post_id Post ID.
1068 + * @return bool
1069 + */
1070 +function usces_have_fewstock( $post_id = null ) {
1071 + global $post, $usces;
1072 +
1073 + if ( null === $post_id ) {
1074 + $post_id = $post->ID;
1075 + }
1076 +
1077 + $skus = wel_get_skus( $post_id );
1078 + $res = false;
1079 + foreach ( $skus as $sku ) {
1080 + if ( 1 === (int) $sku['stock'] ) {
1081 + $res = true;
1082 + break;
1083 + }
1084 + }
1085 + return $res;
1086 +}
1087 +
1088 +/**
1089 + * Is applied large-lot discount
1090 + *
1091 + * @param int $post_id Post ID.
1092 + * @param string $sku SKU code.
1093 + * @param int $quant Quantity.
1094 + * @return bool
1095 + */
1096 +function usces_is_gptekiyo( $post_id, $sku, $quant ) {
466 1097 global $usces;
467 1098 return $usces->is_gptekiyo( $post_id, $sku, $quant );
468 1099 }
1100 +
1101 +/**
1102 + * Large-lot discount
1103 + *
1104 + * @param string $out Return value or echo.
1105 + * @return string|void
1106 + */
469 1107 function usces_the_itemGpExp( $out = '' ) {
470 1108 global $post, $usces;
1109 +
471 1110 $post_id = $post->ID;
472 - $sku = $usces->itemsku['code'];
473 - $GpN1 = $usces->getItemGpNum1($post_id);
474 - $GpN2 = $usces->getItemGpNum2($post_id);
475 - $GpN3 = $usces->getItemGpNum3($post_id);
476 - $GpD1 = $usces->getItemGpDis1($post_id);
477 - $GpD2 = $usces->getItemGpDis2($post_id);
478 - $GpD3 = $usces->getItemGpDis3($post_id);
479 - $unit = $usces->getItemSkuUnit($post_id, $sku);
480 - $price = $usces->getItemPrice($post_id, $sku);
1111 + $sku = $usces->itemsku['code'];
1112 + $gpn1 = $usces->getItemGpNum1( $post_id );
1113 + $gpn2 = $usces->getItemGpNum2( $post_id );
1114 + $gpn3 = $usces->getItemGpNum3( $post_id );
1115 + $gpd1 = $usces->getItemGpDis1( $post_id );
1116 + $gpd2 = $usces->getItemGpDis2( $post_id );
1117 + $gpd3 = $usces->getItemGpDis3( $post_id );
1118 + $unit = $usces->getItemSkuUnit( $post_id, $sku );
1119 + $price = $usces->getItemPrice( $post_id, $sku );
481 1120
482 - if( ($usces->itemsku['gp'] == 0) || empty($GpN1) || empty($GpD1) ){
1121 + if ( ( 0 === (int) $usces->itemsku['gp'] ) || empty( $gpn1 ) || empty( $gpd1 ) ) {
483 1122 return;
484 1123 }
485 - $html = "<dl class='itemGpExp'>\n<dt>" . apply_filters( 'usces_filter_itemGpExp_title', __('Business package discount','usces')) . "</dt>\n<dd>\n<ul>\n";
486 - if(!empty($GpN1) && !empty($GpD1)) {
487 - if(empty($GpN2) || empty($GpD2)) {
488 - $html .= "<li>";
489 - $html .= sprintf( __('<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces'),
490 - $usces->get_currency(round($price * (100 - $GpD1) / 100), true, false ),
491 - $usces->getGuidTax(),
492 - esc_html($unit),
493 - $GpN1,
494 - "'price'"
495 - );
1124 +
1125 + if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
1126 + $tax_rate = 0;
1127 + } else {
1128 + $usces_tax = Welcart_Tax::get_instance();
1129 + $tax_rate = $usces_tax->get_sku_tax_rate( $post_id, $sku );
1130 + }
1131 +
1132 + $html = "<dl class='itemGpExp'>\n<dt>" . apply_filters( 'usces_filter_itemGpExp_title', __( 'Business package discount', 'usces' ) ) . "</dt>\n<dd>\n<ul>\n";
1133 + if ( ! empty( $gpn1 ) && ! empty( $gpd1 ) ) {
1134 + if ( empty( $gpn2 ) || empty( $gpd2 ) ) {
1135 + $price1 = wel_gp_price_discount( $price, $gpd1 );
1136 + $html .= '<li>';
1137 + $html .= sprintf( __( '<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces' ),
1138 + $usces->get_currency( $price1, true, false ),
1139 + $usces->getGuidTax(),
1140 + esc_html( $unit ),
1141 + $gpn1,
1142 + "'price'"
1143 + );
1144 + if ( 0 < $tax_rate ) {
1145 + $html .= usces_crform_the_itemGpExp_taxincluded( $price1, $tax_rate );
1146 + }
496 1147 $html .= "</li>\n";
497 1148 } else {
498 -
499 - $html .= "<li>";
500 - $html .= sprintf( __('<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces'),
501 - $usces->get_currency(round($price * (100 - $GpD1) / 100), true, false ),
502 - $usces->getGuidTax(),
503 - esc_html($unit),
504 - $GpN1,
505 - $GpN2-1,
506 - "'price'"
507 - );
1149 + $price1 = wel_gp_price_discount( $price, $gpd1 );
1150 + $html .= '<li>';
1151 + $html .= sprintf( __( '<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces' ),
1152 + $usces->get_currency( $price1, true, false ),
1153 + $usces->getGuidTax(),
1154 + esc_html( $unit ),
1155 + $gpn1,
1156 + $gpn2 - 1,
1157 + "'price'"
1158 + );
1159 + if ( 0 < $tax_rate ) {
1160 + $html .= usces_crform_the_itemGpExp_taxincluded( $price1, $tax_rate );
1161 + }
508 1162 $html .= "</li>\n";
509 - if(empty($GpN3) || empty($GpD3)) {
510 - //$html .= "<li>" . $GpN2 . $unit . __('for more than ','usces') . "1" . $unit . __('par','usces') . "<span class='price'>" . __('$', 'usces') . number_format(round($price * (100 - $GpD2) / 100)) . $usces->getGuidTax() . "</span></li>\n";
511 - $html .= "<li>";
512 - $html .= sprintf( __('<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces'),
513 - $usces->get_currency(round($price * (100 - $GpD2) / 100), true, false ),
514 - $usces->getGuidTax(),
515 - esc_html($unit),
516 - $GpN2,
517 - "'price'"
518 - );
1163 + if ( empty( $gpn3 ) || empty( $gpd3 ) ) {
1164 + $price2 = wel_gp_price_discount( $price, $gpd2 );
1165 + $html .= '<li>';
1166 + $html .= sprintf( __( '<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces' ),
1167 + $usces->get_currency( $price2, true, false ),
1168 + $usces->getGuidTax(),
1169 + esc_html( $unit ),
1170 + $gpn2,
1171 + "'price'"
1172 + );
1173 + if ( 0 < $tax_rate ) {
1174 + $html .= usces_crform_the_itemGpExp_taxincluded( $price2, $tax_rate );
1175 + }
519 1176 $html .= "</li>\n";
520 1177 } else {
521 - $html .= "<li>";
522 - $html .= sprintf( __('<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces'),
523 - $usces->get_currency(round($price * (100 - $GpD2) / 100), true, false ),
524 - $usces->getGuidTax(),
525 - esc_html($unit),
526 - $GpN2,
527 - $GpN3-1,
528 - "'price'"
529 - );
1178 + $price2 = wel_gp_price_discount( $price, $gpd2 );
1179 + $html .= '<li>';
1180 + $html .= sprintf( __( '<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces' ),
1181 + $usces->get_currency( $price2, true, false ),
1182 + $usces->getGuidTax(),
1183 + esc_html( $unit ),
1184 + $gpn2,
1185 + $gpn3 - 1,
1186 + "'price'"
1187 + );
1188 + if ( 0 < $tax_rate ) {
1189 + $html .= usces_crform_the_itemGpExp_taxincluded( $price2, $tax_rate );
1190 + }
1191 + $html .= "</li>\n";
1192 + $price3 = wel_gp_price_discount( $price, $gpd3 );
1193 + $html .= '<li>';
1194 + $html .= sprintf( __( '<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces' ),
1195 + $usces->get_currency( $price3, true, false ),
1196 + $usces->getGuidTax(),
1197 + esc_html( $unit ),
1198 + $gpn3,
1199 + "'price'"
1200 + );
1201 + if ( 0 < $tax_rate ) {
1202 + $html .= usces_crform_the_itemGpExp_taxincluded( $price3, $tax_rate );
1203 + }
530 1204 $html .= "</li>\n";
531 - $html .= "<li>";
532 - $html .= sprintf( __('<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces'),
533 - $usces->get_currency(round($price * (100 - $GpD3) / 100), true, false ),
534 - $usces->getGuidTax(),
535 - esc_html($unit),
536 - $GpN3,
537 - "'price'"
538 - );
539 - $html .= "</li>\n";
540 1205 }
541 1206 }
542 1207 }
543 - $html .= "</ul></dd></dl>";
544 -
545 - $html = apply_filters('usces_filter_itemGpExp', $html);
546 -
547 - if( $out == 'return' ){
1208 + $html .= '</ul></dd></dl>';
1209 +
1210 + $html = apply_filters( 'usces_filter_itemGpExp', $html );
1211 +
1212 + if ( 'return' === $out ) {
548 1213 return $html;
549 - }else{
550 - echo $html;
1214 + } else {
1215 + echo $html; // no escape due to filter.
551 1216 }
552 1217 }
553 1218
1219 +/**
1220 + * Calculation of the discount based on the unit price per float.
1221 + *
1222 + * @param float $price Price.
1223 + * @param int $rate Discount rate.
1224 + * @return float
1225 + */
1226 +function wel_gp_price_discount( $price, $rate ) {
1227 + global $usces;
1228 +
1229 + $decimal = $usces->get_currency_decimal();
1230 + if ( 0 === (int) $decimal ) {
1231 + $discount = round( $price * ( 100 - $rate ) / 100 );
1232 + } else {
1233 + $discount = (float) sprintf( "%.{$decimal}f", (float) $price * ( 100 - $rate ) / 100 );
1234 + }
1235 + return $discount;
1236 +}
1237 +
1238 +/**
1239 + * Formatted tax included amount
1240 + *
1241 + * @param float $price Price.
1242 + * @param float $tax_rate Tax rate.
1243 + * @param bool $label_pre Forward label.
1244 + * @param string $label Label.
1245 + * @param string $start_tag Start tag.
1246 + * @param string $end_tag End tag.
1247 + * @param bool $symbol_pre Forward symbol.
1248 + * @param bool $symbol_post Backward symbol.
1249 + * @param bool $seperator_flag Seperator.
1250 + * @return string
1251 + */
1252 +function usces_crform_the_itemGpExp_taxincluded( $price, $tax_rate, $label_pre = true, $label = '', $start_tag = '', $end_tag = '', $symbol_pre = true, $symbol_post = false, $seperator_flag = true ) {
1253 + global $usces;
1254 +
1255 + if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
1256 + $res = '';
1257 + } else {
1258 + $tax = (float) sprintf( '%.3f', (float) $price * (float) $tax_rate / 100 );
1259 + $tax = usces_tax_rounding_off( $tax );
1260 + $price_gpexp = esc_html( $usces->get_currency( $price + $tax, $symbol_pre, $symbol_post, $seperator_flag ) );
1261 + if ( empty( $label ) ) {
1262 + $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
1263 + } else {
1264 + $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
1265 + }
1266 + if ( empty( $start_tag ) ) {
1267 + $start_tag = '<span class="tax_inc_block">( ';
1268 + }
1269 + if ( $label_pre ) {
1270 + $start_tag = $start_tag . $label_tag;
1271 + }
1272 + if ( empty( $end_tag ) ) {
1273 + $end_tag = ' )</span>';
1274 + }
1275 + if ( true !== $label_pre ) {
1276 + $end_tag = $label_tag . $end_tag;
1277 + }
1278 + $res = apply_filters( 'usces_filter_crform_the_itemGpExp_taxincluded', $start_tag . $price_gpexp . $end_tag, $price, $tax_rate, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
1279 + }
1280 + return $res;
1281 +}
1282 +
1283 +/**
1284 + * Quantity field
1285 + *
1286 + * @param string $out Return value or echo.
1287 + * @return string|void
1288 + */
554 1289 function usces_the_itemQuant( $out = '' ) {
555 1290 global $usces, $post;
1291 +
556 1292 $post_id = $post->ID;
557 - $sku = esc_attr(urlencode($usces->itemsku['code']));
558 - $value = isset( $_SESSION['usces_singleitem']['quant'][$post_id][$sku] ) ? $_SESSION['usces_singleitem']['quant'][$post_id][$sku] : 1;
559 - $quant = "<input name=\"quant[{$post_id}][" . $sku . "]\" type=\"text\" id=\"quant[{$post_id}][" . $sku . "]\" class=\"skuquantity\" value=\"" . $value . "\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" />";
560 - $html = apply_filters('usces_filter_the_itemQuant', $quant, $post);
561 -
562 - if( $out == 'return' ){
1293 + $sku = urlencode( $usces->itemsku['code'] );
1294 + $value = isset( $_SESSION['usces_singleitem']['quant'][ $post_id ][ $sku ] ) ? $_SESSION['usces_singleitem']['quant'][ $post_id ][ $sku ] : 1;
1295 + $quant = "<input name=\"quant[{$post_id}][" . $sku . "]\" type=\"text\" id=\"quant[{$post_id}][" . $sku . "]\" class=\"skuquantity\" value=\"" . esc_attr( $value ) . "\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" />";
1296 + $html = apply_filters( 'usces_filter_the_itemQuant', $quant, $post );
1297 +
1298 + if ( 'return' === $out ) {
563 1299 return $html;
564 - }else{
565 - echo $html;
1300 + } else {
1301 + echo $html; // no escape due to filter.
566 1302 }
567 1303 }
568 1304
569 -function usces_the_itemSkuButton($value, $type=0, $out = '') {
1305 +/**
1306 + * Add to Cart
1307 + *
1308 + * @param mixed $value Value.
1309 + * @param int $type Submit or button.
1310 + * @param string $out Return value or echo.
1311 + * @return string|void
1312 + */
1313 +function usces_the_itemSkuButton( $value, $type = 0, $out = '' ) {
570 1314 global $usces, $post;
571 - $post_id = $post->ID;
572 - $zaikonum = $usces->itemsku['stocknum'];
573 - $zaiko_status = $usces->itemsku['stock'];
574 - $gptekiyo = $usces->itemsku['gp'];
575 - $skuPrice = $usces->getItemPrice($post_id, $usces->itemsku['code']);
576 - $value = esc_attr(apply_filters( 'usces_filter_incart_button_label', $value));
577 - $sku = esc_attr(urlencode($usces->itemsku['code']));
578 -
579 - if($type == 1)
1315 +
1316 + $post_id = (int) $post->ID;
1317 + $zaikonum = esc_attr( $usces->itemsku['stocknum'] );
1318 + $zaiko_status = esc_attr( $usces->itemsku['stock'] );
1319 + $gptekiyo = esc_attr( $usces->itemsku['gp'] );
1320 + $skuprice = esc_attr( $usces->getItemPrice( $post_id, $usces->itemsku['code'] ) );
1321 + $value = esc_attr( apply_filters( 'usces_filter_incart_button_label', $value ) );
1322 + $sku = esc_attr( urlencode( $usces->itemsku['code'] ) );
1323 +
1324 + if ( 1 === (int) $type ) {
580 1325 $type = 'button';
581 - else
1326 + } else {
582 1327 $type = 'submit';
583 -
584 - $html = "<input name=\"zaikonum[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku}]\" value=\"{$zaikonum}\" />\n";
1328 + }
1329 + $html = "<input name=\"zaikonum[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku}]\" value=\"{$zaikonum}\" />\n";
585 1330 $html .= "<input name=\"zaiko[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku}]\" value=\"{$zaiko_status}\" />\n";
586 1331 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku}]\" value=\"{$gptekiyo}\" />\n";
587 - $html .= "<input name=\"skuPrice[{$post_id}][{$sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku}]\" value=\"{$skuPrice}\" />\n";
588 - if( $usces->use_js ){
589 - $html .= "<input name=\"inCart[{$post_id}][{$sku}]\" type=\"{$type}\" id=\"inCart[{$post_id}][{$sku}]\" class=\"skubutton\" value=\"{$value}\" onclick=\"return uscesCart.intoCart('{$post_id}','{$sku}')\" />";
590 - }else{
1332 + $html .= "<input name=\"skuPrice[{$post_id}][{$sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku}]\" value=\"{$skuprice}\" />\n";
1333 + if ( $usces->use_js ) {
1334 + $html .= "<input name=\"inCart[{$post_id}][{$sku}]\" type=\"{$type}\" id=\"inCart[{$post_id}][{$sku}]\" class=\"skubutton\" value=\"{$value}\" onclick=\"return uscesCart.intoCart( '{$post_id}','{$sku}' )\" />";
1335 + } else {
591 1336 $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$sku}]\" type=\"{$type}\" id=\"inCart[{$post_id}][{$sku}]\" class=\"skubutton\" value=\"{$value}\" />";
592 1337 }
593 - $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . $_SERVER['REQUEST_URI'] . "\" />\n";
1338 + $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
1339 + $html = apply_filters( 'usces_filter_item_sku_button', $html, $value, $type );
594 1340
595 - if( $out == 'return' ){
1341 + if ( 'return' === $out ) {
596 1342 return $html;
597 - }else{
598 - echo $html;
1343 + } else {
1344 + echo $html; // no escape due to filter.
599 1345 }
600 1346 }
601 -
602 -function usces_direct_intoCart($post_id, $sku, $force=false, $value=NULL, $options=NULL, $out = '') {
1347 +
1348 +/**
1349 + * Add to Cart ( direct mode )
1350 + *
1351 + * @param int $post_id Post ID.
1352 + * @param string $sku SKU code.
1353 + * @param bool $force Force.
1354 + * @param mixed $value Value.
1355 + * @param bool $options Have options.
1356 + * @param string $out Return value or echo.
1357 + * @return string|void
1358 + */
1359 +function usces_direct_intoCart( $post_id, $sku, $force = false, $value = null, $options = null, $out = '' ) {
603 1360 global $usces;
604 - if( empty($value) )
605 - $value = __('Add To Cart', 'usces');
606 - $skus = $usces->get_skus( $post_id, 'code' );
607 - $zaikonum = $skus[$sku]['stocknum'];
608 - $zaiko = $skus[$sku]['stock'];
609 - $gptekiyo = $skus[$sku]['gp'];
610 - $skuPrice = $skus[$sku]['price'];
611 - $enc_sku = urlencode($sku);
612 1361
613 - $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\" name=\"" . $post_id."-". $enc_sku . "\">\n";
614 - $html .= "<input name=\"zaikonum[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$enc_sku}]\" value=\"{$zaikonum}\" />\n";
615 - $html .= "<input name=\"zaiko[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$enc_sku}]\" value=\"{$zaiko}\" />\n";
616 - $html .= "<input name=\"gptekiyo[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$enc_sku}]\" value=\"{$gptekiyo}\" />\n";
617 - $html .= "<input name=\"skuPrice[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$enc_sku}]\" value=\"{$skuPrice}\" />\n";
618 - $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$enc_sku}]\" type=\"submit\" id=\"inCart[{$post_id}][{$enc_sku}]\" class=\"skubutton\" value=\"{$value}\" " . apply_filters('usces_filter_direct_intocart_button', NULL, $post_id, $sku, $force, $options) . " />";
619 - $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . $_SERVER['REQUEST_URI'] . "\" />\n";
620 - if( $force )
1362 + if ( empty( $value ) ) {
1363 + $value = __( 'Add To Cart', 'usces' );
1364 + }
1365 + $skus = wel_get_skus( $post_id, 'code' );
1366 +
1367 + $zaikonum = $skus[ $sku ]['stocknum'];
1368 + $zaiko = $skus[ $sku ]['stock'];
1369 + $gptekiyo = $skus[ $sku ]['gp'];
1370 + $skuprice = $skus[ $sku ]['price'];
1371 + $enc_sku = urlencode( $sku );
1372 +
1373 + $usces->itemopts = wel_get_opts( $post_id, 'sort' );
1374 + $usces->current_itemopt = -1;
1375 +
1376 + $usces->itemsku = $skus[ $sku ];
1377 +
1378 + $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\" name=\"" . $post_id . '-' . $enc_sku . "\">\n";
1379 + $html .= "<input name=\"zaikonum[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $zaikonum ) . "\" />\n";
1380 + $html .= "<input name=\"zaiko[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $zaiko ) . "\" />\n";
1381 + $html .= "<input name=\"gptekiyo[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $gptekiyo ) . "\" />\n";
1382 + $html .= "<input name=\"skuPrice[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $skuprice ) . "\" />\n";
1383 +
1384 + if ( $options && usces_is_options() ) {
1385 + while ( usces_have_options() ) {
1386 + $html .= '<div class="itemopt_row">' . usces_get_itemopt_filed( $post_id, $sku, $usces->itemopt ) . "</div>\n";
1387 + }
1388 + }
1389 +
1390 + $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$enc_sku}]\" type=\"submit\" id=\"inCart[{$post_id}][{$enc_sku}]\" class=\"skubutton\" value=\"" . esc_attr( $value ) . "\" " . apply_filters( 'usces_filter_direct_intocart_button', null, $post_id, $sku, $force, $options ) . ' />';
1391 + $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
1392 + if ( $force ) {
621 1393 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
622 - $html = apply_filters('usces_filter_single_item_inform', $html);
623 - $html .= "</form>";
624 - $html .= '<div class="direct_error_message">' . usces_singleitem_error_message($post_id, $sku, 'return') . '</div>'."\n";
1394 + }
1395 + $html = apply_filters( 'usces_filter_single_item_inform', $html );
625 1396
626 - if( $out == 'return' ){
1397 + $html .= '</form>';
1398 + $html .= '<div class="direct_error_message">' . usces_singleitem_error_message( $post_id, $sku, 'return' ) . '</div>' . "\n";
1399 +
1400 + if ( 'return' === $out ) {
627 1401 return $html;
628 - }else{
629 - echo $html;
1402 + } else {
1403 + echo $html; // no escape due to filter.
630 1404 }
631 1405 }
632 1406
633 -
634 -function usces_the_itemImage($number = 0, $width = 60, $height = 60, $post = '', $out = '', $media = 'item' ) {
1407 +/**
1408 + * Product Image
1409 + *
1410 + * @param int $number Image number.
1411 + * @param int $width Width.
1412 + * @param int $height Height.
1413 + * @param object $post Post data.
1414 + * @param string $out Return value or echo.
1415 + * @param string $media Media.
1416 + * @return string|void
1417 + */
1418 +function usces_the_itemImage( $number = 0, $width = 60, $height = 60, $post = '', $out = '', $media = 'item' ) {
635 1419 global $usces;
636 - $ptitle = $number;
637 - if($post == '') global $post;
638 1420
1421 + if ( '' === $post ) {
1422 + global $post;
1423 + }
639 1424 $post_id = $post->ID;
640 -
641 - if( $ptitle && 0 == (int)$number ){
642 1425
643 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
644 - $pictid = empty($picposts) ? 0 : $picposts[0]->ID;
645 - $html = wp_get_attachment_image( $pictid, array($width, $height), false );
646 - if( 'item' == $media ){
647 - $alt = 'alt="'.esc_attr($code[0]).'"';
648 - $alt = apply_filters('usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height);
649 - $html = preg_replace('/alt=\"[^\"]*\"/', $alt, $html);
650 - $title = 'title="'.esc_attr($name[0]).'"';
651 - $title = apply_filters('usces_filter_img_title', $title, $post_id, $pictid, $width, $height);
652 - $html = preg_replace('/title=\"[^\"]+\"/', $title, $html);
653 - $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height);
1426 + $ptitle = '';
1427 + if ( is_string( $number ) ) {
1428 + $ptitle = $number;
1429 + }
1430 + if ( $ptitle ) {
1431 +
1432 + $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1433 + $pictid = ( $picposts->have_posts() ) ? $picposts[0]->ID : 0;
1434 + $html = wp_get_attachment_image( $pictid, array( $width, $height ), false );
1435 + if ( 'item' === $media ) {
1436 + $product = wel_get_product( $post_id );
1437 + $code = $product['itemCode'];
1438 + if ( ! $code ) {
1439 + return false;
1440 + }
1441 + $name = $product['itemName'];
1442 +
1443 + $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1444 + if ( empty( $alt ) ) {
1445 + $alt = $code;
1446 + }
1447 + $alt = 'alt="' . esc_attr( $alt ) . '"';
1448 + $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1449 +
1450 + $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1451 +
1452 + $title = 'title="' . esc_attr( $name ) . '"';
1453 + $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1454 +
1455 + $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1456 + $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height );
654 1457 }
655 1458
656 - }else{
1459 + } else {
657 1460
658 -
659 - $code = get_post_meta($post_id, '_itemCode', true);
660 - if(!$code) return false;
661 -
662 - $name = get_post_meta($post_id, '_itemName', true);
663 -
664 - if( 0 == $number ){
665 - $pictid = (int)$usces->get_mainpictid($code);
666 - $html = wp_get_attachment_image( $pictid, array($width, $height), true );//'<img src="#" height="60" width="60" alt="" />';
667 - if( 'item' == $media ){
668 - $alt = 'alt="'.esc_attr($code).'"';
669 - $alt = apply_filters('usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height);
670 - $html = preg_replace('/alt=\"[^\"]*\"/', $alt, $html);
671 - $title = 'title="'.esc_attr($name).'"';
672 - $title = apply_filters('usces_filter_img_title', $title, $post_id, $pictid, $width, $height);
673 - $html = preg_replace('/title=\"[^\"]+\"/', $title, $html);
674 - $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height);
1461 + $product = wel_get_product( $post_id );
1462 + $code = $product['itemCode'];
1463 + if ( ! $code ) {
1464 + return false;
1465 + }
1466 + $name = $product['itemName'];
1467 +
1468 + if ( 0 === (int) $number ) {
1469 +
1470 + $pictid = (int) $usces->get_mainpictid( $code );
1471 + $html = wp_get_attachment_image( $pictid, array( $width, $height ), true );/* '<img src="#" height="60" width="60" alt="" />'; */
1472 + if ( 'item' === $media ) {
1473 + $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1474 + if ( empty( $alt ) ) {
1475 + $alt = $code;
1476 + }
1477 + $alt = 'alt="' . esc_attr( $alt ) . '"';
1478 + $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1479 +
1480 + $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1481 +
1482 + $title = 'title="' . esc_attr( $name ) . '"';
1483 + $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1484 +
1485 + $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1486 + $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height );
675 1487 }
676 - }else{
677 - $pictids = $usces->get_pictids($code);
678 - $ind = $number - 1;
679 - $pictid = ( isset($pictids[$ind]) && (int)$pictids[$ind] ) ? $pictids[$ind] : 0;
680 - $html = wp_get_attachment_image( $pictid, array($width, $height), false );//'<img src="#" height="60" width="60" alt="" />';
681 - if( 'item' == $media ){
682 - $alt = 'alt="'.esc_attr($code).'"';
683 - $alt = apply_filters('usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height);
684 - $html = preg_replace('/alt=\"[^\"]*\"/', $alt, $html);
685 - $title = 'title="'.esc_attr($name).'"';
686 - $title = apply_filters('usces_filter_img_title', $title, $post_id, $pictid, $width, $height);
687 - $html = preg_replace('/title=\"[^\"]+\"/', $title, $html);
688 - $html = apply_filters( 'usces_filter_sub_img', $html, $post_id, $pictid, $width, $height);
1488 +
1489 + } else {
1490 +
1491 + $pictids = $usces->get_pictids( $code );
1492 + $ind = $number - 1;
1493 + $pictid = ( isset( $pictids[ $ind ] ) && (int) $pictids[ $ind ] ) ? $pictids[ $ind ] : 0;
1494 + $html = wp_get_attachment_image( $pictid, array( $width, $height ), false );/* '<img src="#" height="60" width="60" alt="" />'; */
1495 + if ( 'item' === $media ) {
1496 + $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1497 + if ( empty( $alt ) ) {
1498 + $alt = $code;
1499 + }
1500 + $alt = 'alt="' . esc_attr( $alt ) . '"';
1501 + $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1502 +
1503 + $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1504 +
1505 + $title = 'title="' . esc_attr( $name ) . '"';
1506 + $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1507 +
1508 + $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1509 + $html = apply_filters( 'usces_filter_sub_img', $html, $post_id, $pictid, $width, $height );
689 1510 }
690 1511 }
691 1512 }
692 -
693 - if($out == 'return'){
694 - return $html;
695 - }else{
696 - echo $html;
1513 +
1514 + if ( 'return' === $out ) {
1515 + return wel_esc_script( $html );
1516 + } else {
1517 + wel_esc_script_e( $html );
697 1518 }
698 1519 }
699 1520
700 -function usces_the_itemImageURL($number = 0, $out = '', $post = '' ) {
1521 +/**
1522 + * Product Image URL
1523 + *
1524 + * @param int $number Image number.
1525 + * @param string $out Return value or echo.
1526 + * @param object $post Post data.
1527 + * @return string|void
1528 + */
1529 +function usces_the_itemImageURL( $number = 0, $out = '', $post = '' ) {
701 1530 global $usces;
1531 +
702 1532 $ptitle = $number;
703 -
704 - if( $ptitle && is_string($number) ){
705 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
706 - $pictid = empty($picposts) ? 0 : $picposts[0]->ID;
707 - $pictid = $picposts[0]->ID;
708 - $html = wp_get_attachment_url( $pictid );
709 - }else{
710 -
711 - if($post == '') global $post;
1533 + if ( $ptitle && is_string( $number ) ) {
1534 +
1535 + $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1536 + $pictid = ( $picposts->have_posts() ) ? $picposts[0]->ID : 0;
1537 + $html = wp_get_attachment_url( $pictid );
1538 +
1539 + } else {
1540 +
1541 + if ( '' === $post ) {
1542 + global $post;
1543 + }
712 1544 $post_id = $post->ID;
713 -
714 - $code = get_post_meta($post_id, '_itemCode', true);
715 - if(!$code) return false;
716 - $name = get_post_meta($post_id, '_itemName', true);
717 - if( 0 == $number ){
718 - $pictid = (int)$usces->get_mainpictid($code);
719 - $html = wp_get_attachment_url( $pictid );
720 - }else{
721 - $pictids = $usces->get_pictids($code);
722 - $ind = $number - 1;
723 - $pictid = ( isset($pictids[$ind]) && (int)$pictids[$ind] ) ? $pictids[$ind] : 0;
724 - $html = wp_get_attachment_url( $pictid );
1545 + $product = wel_get_product( $post_id );
1546 + $code = $product['itemCode'];
1547 + if ( ! $code ) {
1548 + return false;
725 1549 }
1550 + $name = $product['itemName'];
1551 + if ( 0 === (int) $number ) {
1552 + $pictid = (int) $usces->get_mainpictid( $code );
1553 + $html = wp_get_attachment_url( $pictid );
1554 + } else {
1555 + $pictids = $usces->get_pictids( $code );
1556 + $ind = $number - 1;
1557 + $pictid = ( isset( $pictids[ $ind ] ) && (int) $pictids[ $ind ] ) ? $pictids[ $ind ] : 0;
1558 + $html = wp_get_attachment_url( $pictid );
1559 + }
726 1560 }
727 -
728 - if($out == 'return'){
729 - return $html;
730 - }else{
731 - echo $html;
1561 +
1562 + if ( 'return' === $out ) {
1563 + return wel_esc_script( $html );
1564 + } else {
1565 + wel_esc_script_e( $html );
732 1566 }
733 1567 }
734 1568
735 -function usces_the_itemImageCaption($number = 0, $post = '', $out = '' ) {
1569 +/**
1570 + * Product Image caption
1571 + *
1572 + * @param int $number Image number.
1573 + * @param object $post Post data.
1574 + * @param string $out Return value or echo.
1575 + * @return string|void
1576 + */
1577 +function usces_the_itemImageCaption( $number = 0, $post = '', $out = '' ) {
736 1578 global $usces;
1579 +
737 1580 $ptitle = $number;
738 -
739 - if( $ptitle && 0 == (int)$number ){
740 -
741 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
742 - $excerpt = empty($picposts) ? '' : $picposts[0]->post_excerpt;
743 -
744 - }else{
745 -
746 - if($post == '') global $post;
747 -
1581 + if ( $ptitle && 0 === (int) $number ) {
1582 +
1583 + $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1584 + $excerpt = ( $picposts->have_posts() ) ? $picposts[0]->post_excerpt : '';
1585 +
1586 + } else {
1587 +
1588 + if ( '' === $post ) {
1589 + global $post;
1590 + }
748 1591 $post_id = $post->ID;
749 -
750 - $code = get_post_meta($post_id, '_itemCode', true);
751 - if(!$code) return false;
752 -
753 - $name = get_post_meta($post_id, '_itemName', true);
754 -
755 - if( 0 == $number ){
756 - $pictid = $usces->get_mainpictid($code);
757 - $attach_ob = get_post($pictid);
758 - }else{
759 - $pictids = $usces->get_pictids($code);
760 - $ind = $number - 1;
761 - $attach_ob = get_post($pictids[$ind]);
1592 + $product = wel_get_product( $post_id );
1593 +
1594 + $code = $product['itemCode'];
1595 + if ( ! $code ) {
1596 + return false;
762 1597 }
763 - $excerpt = $attach_ob->post_excerpt;
1598 + $name = $product['itemName'];
1599 +
1600 + if ( 0 === (int) $number ) {
1601 + $pictid = $usces->get_mainpictid( $code );
1602 + if ( $pictid ) {
1603 + $attach_ob = get_post( $pictid );
1604 + $excerpt = ( isset( $attach_ob->post_excerpt ) ) ? $attach_ob->post_excerpt : '';
1605 + } else {
1606 + $excerpt = '';
1607 + }
1608 + } else {
1609 + $pictids = $usces->get_pictids( $code );
1610 + $ind = $number - 1;
1611 + if ( isset( $pictids[ $ind ] ) ) {
1612 + $attach_ob = get_post( $pictids[ $ind ] );
1613 + $excerpt = ( isset( $attach_ob->post_excerpt ) ) ? $attach_ob->post_excerpt : '';
1614 + } else {
1615 + $excerpt = '';
1616 + }
1617 + }
764 1618 }
765 1619
766 - if($out == 'return'){
1620 + if ( 'return' === $out ) {
767 1621 return $excerpt;
768 - }else{
769 - echo esc_html($excerpt);
1622 + } else {
1623 + echo esc_html( $excerpt );
770 1624 }
771 1625 }
772 1626
773 -function usces_the_itemImageDescription($number = 0, $post = '', $out = '' ) {
1627 +/**
1628 + * Product Image description
1629 + *
1630 + * @param int $number Image number.
1631 + * @param object $post Post data.
1632 + * @param string $out Return value or echo.
1633 + * @return string|void
1634 + */
1635 +function usces_the_itemImageDescription( $number = 0, $post = '', $out = '' ) {
774 1636 global $usces;
1637 +
775 1638 $ptitle = $number;
776 -
777 - if( $ptitle && 0 == (int)$number ){
778 -
779 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
780 - $excerpt = empty($picposts) ? '' : $picposts[0]->post_content;
781 -
782 - }else{
1639 + if ( $ptitle && 0 === (int) $number ) {
783 1640
784 - if($post == '') global $post;
785 -
1641 + $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1642 + $description = ( $picposts->have_posts() ) ? $picposts[0]->post_content : '';
1643 +
1644 + } else {
1645 +
1646 + if ( '' === $post ) {
1647 + global $post;
1648 + }
786 1649 $post_id = $post->ID;
787 -
788 - $code = get_post_meta($post_id, '_itemCode', true);
789 - if(!$code) return false;
790 -
791 - $name = get_post_meta($post_id, '_itemName', true);
792 -
793 - if( 0 == $number ){
794 - $pictid = $usces->get_mainpictid($code);
795 - $attach_ob = get_post($pictid);
796 - }else{
797 - $pictids = $usces->get_pictids($code);
798 - $ind = $number - 1;
799 - $attach_ob = get_post($pictids[$ind]);
1650 + $product = wel_get_product( $post_id );
1651 +
1652 + $code = $product['itemCode'];
1653 + if ( ! $code ) {
1654 + return false;
800 1655 }
801 - $excerpt = $attach_ob->post_content;
1656 + $name = $product['itemName'];
1657 +
1658 + if ( 0 === (int) $number ) {
1659 + $pictid = $usces->get_mainpictid( $code );
1660 + if ( $pictid ) {
1661 + $attach_ob = get_post( $pictid );
1662 + $description = ( isset( $attach_ob->post_content ) ) ? $attach_ob->post_content : '';
1663 + } else {
1664 + $description = '';
1665 + }
1666 + } else {
1667 + $pictids = $usces->get_pictids( $code );
1668 + $ind = $number - 1;
1669 + if ( isset( $pictids[ $ind ] ) ) {
1670 + $attach_ob = get_post( $pictids[ $ind ] );
1671 + $description = ( isset( $attach_ob->post_content ) ) ? $attach_ob->post_content : '';
1672 + } else {
1673 + $description = '';
1674 + }
1675 + }
802 1676 }
803 1677
804 - if($out == 'return'){
805 - return $excerpt;
806 - }else{
807 - echo esc_html($excerpt);
1678 + if ( 'return' === $out ) {
1679 + return $description;
1680 + } else {
1681 + echo esc_html( $description );
808 1682 }
809 1683 }
810 1684
1685 +/**
1686 + * Product sub image
1687 + *
1688 + * @return array
1689 + */
811 1690 function usces_get_itemSubImageNums() {
812 1691 global $post, $usces;
1692 +
813 1693 $post_id = $post->ID;
814 - $res = array();
815 -
816 - $code = get_post_meta($post_id, '_itemCode', true);
817 - if(!$code) return false;
818 - $name = get_post_meta($post_id, '_itemName', true);
819 - $pictids = $usces->get_pictids($code);
820 - for($i=1; $i<=count($pictids); $i++){
1694 + $res = array();
1695 +
1696 + $product = wel_get_product( $post_id );
1697 + $code = $product['itemCode'];
1698 + if ( ! $code ) {
1699 + return false;
1700 + }
1701 + $name = $product['itemName'];
1702 +
1703 + $pictids = $usces->get_pictids( $code );
1704 + $pictids_count = ( $pictids && is_array( $pictids ) ) ? count( $pictids ) : 0;
1705 + for ( $i = 1; $i <= $pictids_count; $i++ ) {
821 1706 $res[] = $i;
822 1707 }
823 - return $res;
1708 + return $res;
824 1709 }
825 1710
1711 +/**
1712 + * Is item option
1713 + *
1714 + * @return bool
1715 + */
826 1716 function usces_is_options() {
827 1717 global $usces;
828 -
829 - if( 0 < count($usces->itemopts) ){
830 - reset($usces->itemopts);
831 - $usces->itemopt = array();
1718 +
1719 + if ( ! empty( $usces->itemopts ) && is_array( $usces->itemopts ) && 0 < count( $usces->itemopts ) ) {
1720 + reset( $usces->itemopts );
1721 + $usces->itemopt = array();
1722 + $usces->current_itemopt = -1;
832 1723 return true;
833 - }else{
1724 + } else {
834 1725 return false;
835 1726 }
836 1727 }
837 1728
1729 +/**
1730 + * Have item option
1731 + *
1732 + * @return bool
1733 + */
838 1734 function usces_have_options() {
839 1735 global $usces;
840 -
841 - $res_each = each($usces->itemopts);
842 - $usces->itemopt = $res_each['value'];
843 - if($usces->itemopt) {
1736 +
1737 + if ( null === $usces->current_itemopt ) {
1738 + $usces->current_itemopt = -1;
1739 + }
1740 +
1741 + if ( ! empty( $usces->itemopts ) && is_array( $usces->itemopts ) && ( $usces->current_itemopt + 1 < count( $usces->itemopts ) ) ) {
1742 + $usces->current_itemopt++;
1743 + $usces->itemopt = ( isset( $usces->itemopts[ $usces->current_itemopt ] ) ) ? $usces->itemopts[ $usces->current_itemopt ] : array();
844 1744 return true;
845 1745 } else {
846 1746 return false;
847 1747 }
@@ -846,785 +1746,1133 @@
846 1746 return false;
847 1747 }
848 1748 }
849 1749
1750 +/**
1751 + * Item option name
1752 + *
1753 + * @return string
1754 + */
850 1755 function usces_getItemOptName() {
851 1756 global $usces;
852 1757 return $usces->itemopt['name'];
853 1758 }
854 1759
855 -function usces_the_itemOptName($out = '') {
1760 +/**
1761 + * Item option name
1762 + *
1763 + * @param string $out Return value or echo.
1764 + * @return string|void
1765 + */
1766 +function usces_the_itemOptName( $out = '' ) {
856 1767 global $usces;
857 1768
858 - if($out == 'return'){
1769 + if ( 'return' === $out ) {
859 1770 return $usces->itemopt['name'];
860 - }else{
861 - echo esc_html($usces->itemopt['name']);
1771 + } else {
1772 + echo esc_html( $usces->itemopt['name'] );
862 1773 }
863 1774 }
864 1775
1776 +/**
1777 + * Item option field
1778 + *
1779 + * @param string $name Option name.
1780 + * @param string $label Label.
1781 + * @param string $out Return value or echo.
1782 + * @return string|void
1783 + */
865 1784 function usces_the_itemOption( $name, $label = '#default#', $out = '' ) {
866 1785 global $post, $usces;
867 1786 $post_id = $post->ID;
868 -
869 - if($label == '#default#')
1787 +
1788 + if ( '#default#' === $label ) {
870 1789 $label = $name;
1790 + }
871 1791
872 - $opts = usces_get_opts($post_id, 'name');
873 - if(!$opts)
1792 + $opts = wel_get_opts( $post_id, 'name' );
1793 + if ( ! $opts || ! isset( $opts[ $name ] ) ) {
874 1794 return false;
875 -
876 - $opt = $opts[$name];
877 - $means = (int)$opt['means'];
878 - $essential = (int)$opt['essential'];
1795 + }
879 1796
880 - $html = '';
881 - $sku = esc_attr(urlencode($usces->itemsku['code']));
882 - $optcode = esc_attr(urlencode($name));
883 - $name = esc_attr($name);
884 - $label = esc_attr($label);
885 - $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] ) ? $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] : NULL;
886 -//20110715ysk start 0000208
1797 + $opt = $opts[ $name ];
1798 + $opt['value'] = usces_change_line_break( $opt['value'] );
1799 + $means = (int) $opt['means'];
1800 + $essential = (int) $opt['essential'];
1801 +
1802 + $sku = esc_attr( urlencode( $usces->itemsku['code'] ) );
1803 + $optcode = esc_attr( urlencode( $name ) );
1804 + $name = esc_attr( $name );
1805 + $label = esc_attr( $label );
1806 +
1807 + $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] ) ? $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] : null;
1808 +
1809 + $html = '';
887 1810 $html .= "\n<label for='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_label'>{$label}</label>\n";
888 -//20110715ysk end
889 -//20100914ysk start
890 - //if($means < 2){
891 - switch($means) {
892 - case 0://Single-select
893 - case 1://Multi-select
894 -//20100914ysk end
895 - $selects = explode("\n", $opt['value']);
896 - $multiple = ($means === 0) ? '' : ' multiple';
897 - $multiple_array = ($means == 0) ? '' : '[]';//20110629ysk 0000190
898 - //$html .= "\n<label for='itemOption[{$post_id}][{$sku}][{$name}]' class='iopt_label'>{$label}</label>\n";
899 -//20110629ysk start 0000190
900 - //$html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$name}]' id='itemOption[{$post_id}][{$sku}][{$name}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
901 - $html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$optcode}]{$multiple_array}' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
902 -//20110629ysk end
903 - if($essential == 1){
904 - if( '#NONE#' == $session_value || NULL == $session_value )
905 - $selected = ' selected="selected"';
906 - else
907 - $selected = '';
908 - $html .= "\t<option value='#NONE#'{$selected}>" . __('Choose','usces') . "</option>\n";
909 - }
910 - $i=0;
911 - foreach($selects as $v) {
912 - $v = trim($v);
913 - if( ($i == 0 && $essential == 0 && NULL == $session_value) || esc_attr($v) == $session_value )
914 - $selected = ' selected="selected"';
915 - else
916 - $selected = '';
917 - $html .= "\t<option value='" . esc_attr($v) . "'{$selected}>" . esc_attr($v) . "</option>\n";
918 - $i++;
919 - }
920 - $html .= "</select>\n";
921 -//20100914ysk start
922 - //}else{
923 - break;
924 - case 2://Text
925 -//20100914ysk end
926 - $html .= "\n<input name='itemOption[{$post_id}][{$sku}][{$optcode}]' type='text' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"" . esc_attr($session_value) . "\" />\n";
927 -//20100914ysk start
928 - break;
929 - case 5://Text-area
930 - $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr($session_value) . "</textarea>\n";
931 - break;
932 -//20100914ysk end
1811 +
1812 + switch ( $means ) {
1813 + case 0: // Single-select.
1814 + case 1: // Multi-select.
1815 + $selects = explode( "\n", $opt['value'] );
1816 + $multiple = ( 0 === $means ) ? '' : ' multiple';
1817 + $multiple_array = ( 0 === $means ) ? '' : '[]';
1818 +
1819 + $html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$optcode}]{$multiple_array}' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
1820 + if ( 1 === $essential ) {
1821 + if ( 0 === $means && ( '#NONE#' === $session_value || null === $session_value ) ) {
1822 + $selected = ' selected="selected"';
1823 + } else {
1824 + $selected = '';
1825 + }
1826 + $html .= "\t<option value='#NONE#'{$selected}>" . __( 'Choose', 'usces' ) . "</option>\n";
1827 + }
1828 + $i = 0;
1829 + foreach ( (array) $selects as $v ) {
1830 + $v = trim( $v );
1831 + if ( ( 0 === $i && 0 === $essential && null === $session_value ) || esc_attr( $v ) === $session_value ) {
1832 + $selected = ' selected="selected"';
1833 + } else {
1834 + $selected = '';
1835 + }
1836 + $html .= "\t<option value='" . esc_attr( $v ) . "'{$selected}>" . esc_attr( $v ) . "</option>\n";
1837 + $i++;
1838 + }
1839 + $html .= "</select>\n";
1840 + break;
1841 + case 2: // Text.
1842 + $html .= "\n<input name='itemOption[{$post_id}][{$sku}][{$optcode}]' type='text' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"" . esc_attr( $session_value ) . "\" />\n";
1843 + break;
1844 + case 3: // Radio-button.
1845 + $selects = explode( "\n", $opt['value'] );
1846 + $i = 0;
1847 + foreach ( (array) $selects as $v ) {
1848 + $v = trim( $v );
1849 + if ( $v === $session_value ) {
1850 + $checked = ' checked="checked"';
1851 + } else {
1852 + $checked = '';
1853 + }
1854 + $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio' type='radio' value='" . urlencode( $v ) . "'{$checked}>" . esc_html( $v ) . "</label>\n";
1855 + $i++;
1856 + }
1857 + break;
1858 + case 4: // Check-box.
1859 + $selects = explode( "\n", $opt['value'] );
1860 + $i = 0;
1861 + foreach ( (array) $selects as $v ) {
1862 + $v = trim( $v );
1863 + if ( $v === $session_value ) {
1864 + $checked = ' checked="checked"';
1865 + } else {
1866 + $checked = '';
1867 + }
1868 + $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}][]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox' type='checkbox' value='" . urlencode( $v ) . "'{$checked}>" . esc_html( $v ) . "</label><br />\n";
1869 + $i++;
1870 + }
1871 + break;
1872 + case 5: // Text-area.
1873 + $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr( $session_value ) . "</textarea>\n";
1874 + break;
933 1875 }
934 -
935 - $html = apply_filters('usces_filter_the_itemOption', $html, $opts, $name, $label, $post_id, $usces->itemsku['code']);
936 -
937 - if( $out == 'return' ){
1876 +
1877 + $html = apply_filters( 'usces_filter_the_itemOption', $html, $opts, $name, $label, $post_id, $usces->itemsku['code'] );
1878 +
1879 + if ( 'return' === $out ) {
938 1880 return $html;
939 - }else{
940 - echo $html;
1881 + } else {
1882 + echo $html; // no escape due to filter.
941 1883 }
942 1884 }
943 1885
1886 +/**
1887 + * Display cart
1888 + */
944 1889 function usces_the_cart() {
945 1890 global $usces;
946 -
947 1891 $usces->display_cart();
948 -
949 1892 }
950 1893
1894 +/**
1895 + * Is cart page
1896 + *
1897 + * @return bool
1898 + */
1899 +function usces_is_cart_page() {
1900 + global $usces;
1901 +
1902 + if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
1903 + if ( 'cart' === $usces->page ) {
1904 + return true;
1905 + }
1906 + if ( 'customer' !== $usces->page && 'delivery' !== $usces->page && 'confirm' !== $usces->page && 'ordercompletion' !== $usces->page && 'error' !== $usces->page && 'search_item' !== $usces->page ) {
1907 + return true;
1908 + }
1909 + }
1910 + return false;
1911 +}
1912 +
1913 +/**
1914 + * Is cart
1915 + *
1916 + * @return bool
1917 + */
951 1918 function usces_is_cart() {
952 1919 global $usces;
953 -
954 - if($usces->cart->num_row() > 0)
955 - if( apply_filters('usces_is_cart_check', true) ) {
1920 +
1921 + if ( 0 < $usces->cart->num_row() ) {
1922 + if ( apply_filters( 'usces_is_cart_check', true ) ) {
956 1923 return true;
957 - }else{
1924 + } else {
958 1925 return false;
959 1926 }
960 - else
1927 + } else {
961 1928 return false;
962 -
1929 + }
963 1930 }
964 1931
1932 +/**
1933 + * Is category
1934 + *
1935 + * @param string $str categpry slug.
1936 + * @return bool
1937 + */
965 1938 function usces_is_category( $str ) {
966 - global $post;
967 1939
968 - //if( $post->post_type != 'post' ) return false;
969 -
970 - $cat = get_the_category();
1940 + $cat = get_the_category();
971 1941 $slugs = array();
972 - foreach($cat as $value){
1942 + foreach ( $cat as $value ) {
973 1943 $slugs[] = $value->slug;
974 1944 }
975 -
976 - $str = utf8_uri_encode($str);
977 -
978 - if( in_array( $str, $slugs) )
1945 +
1946 + $str = utf8_uri_encode( $str );
1947 +
1948 + if ( in_array( $str, $slugs, true ) ) {
979 1949 return true;
980 - else
1950 + } else {
981 1951 return false;
1952 + }
982 1953 }
983 1954
984 -function usces_the_pref( $flag, $out = '' ){
1955 +/**
1956 + * Pref field
1957 + *
1958 + * @param string $flag Member or not.
1959 + * @param string $out Return value or echo.
1960 + * @return string|void
1961 + */
1962 +function usces_the_pref( $flag, $out = '' ) {
985 1963 global $usces;
986 -
987 - $usces_members = $usces->get_member();
1964 +
988 1965 $usces_entries = $usces->cart->get_entry();
989 - $name = esc_attr($flag) . '[pref]';
990 - $pref = $usces_entries[$flag]['pref'];
991 - if( 'member' == $flag)
992 - $pref = $usces_members['pref'];
993 -
994 - $html = "<select name='" . esc_attr($name) . "' id='pref' class='pref'>\n";
995 -// $prefs = get_option('usces_pref');
996 -//20110331ysk start
997 - //$prefs = $usces->options['province'];
998 - $prefs = get_usces_states(usces_get_local_addressform());
999 -//20110331ysk end
1000 - foreach($prefs as $value) {
1001 - $selected = ($pref == $value) ? ' selected="selected"' : '';
1002 - $html .= "\t<option value='" . esc_attr($value) . "'{$selected}>" . esc_html($value) . "</option>\n";
1966 + $name = esc_attr( $flag ) . '[pref]';
1967 + $pref = $usces_entries[ $flag ]['pref'];
1968 + if ( 'member' === $flag ) {
1969 + $usces_members = $usces->get_member();
1970 + $pref = $usces_members['pref'];
1003 1971 }
1972 + $html = "<select name=\"" . esc_attr( $name ) . "\" id=\"pref\" class=\"pref\">\n";
1973 + $prefs = get_usces_states( usces_get_local_addressform() );
1974 + foreach ( $prefs as $value ) {
1975 + $selected = ( $pref === $value ) ? ' selected="selected"' : '';
1976 + $html .= "\t<option value=\"" . esc_attr( $value ) . "\"{$selected}>" . esc_html( $value ) . "</option>\n";
1977 + }
1004 1978 $html .= "</select>\n";
1005 -
1006 - if( $out == 'return' ){
1007 - return $html;
1008 - }else{
1009 - echo $html;
1979 +
1980 + if ( 'return' === $out ) {
1981 + return wel_esc_script( $html );
1982 + } else {
1983 + wel_esc_script_e( $html );
1010 1984 }
1011 1985 }
1012 1986
1013 -function usces_the_company_name(){
1987 +/**
1988 + * Company name
1989 + */
1990 +function usces_the_company_name() {
1014 1991 global $usces;
1015 - echo esc_html($usces->options['company_name']);
1992 + echo esc_html( $usces->options['company_name'] );
1016 1993 }
1017 1994
1018 -function usces_the_zip_code(){
1995 +/**
1996 + * Zip code
1997 + */
1998 +function usces_the_zip_code() {
1019 1999 global $usces;
1020 - echo esc_html($usces->options['zip_code']);
2000 + echo esc_html( $usces->options['zip_code'] );
1021 2001 }
1022 2002
1023 -function usces_the_address1(){
2003 +/**
2004 + * Address1
2005 + */
2006 +function usces_the_address1() {
1024 2007 global $usces;
1025 - echo esc_html($usces->options['address1']);
2008 + echo esc_html( $usces->options['address1'] );
1026 2009 }
1027 2010
1028 -function usces_the_address2(){
2011 +/**
2012 + * Address2
2013 + */
2014 +function usces_the_address2() {
1029 2015 global $usces;
1030 - echo esc_html($usces->options['address2']);
2016 + echo esc_html( $usces->options['address2'] );
1031 2017 }
1032 2018
1033 -function usces_the_tel_number(){
2019 +/**
2020 + * Tel number
2021 + */
2022 +function usces_the_tel_number() {
1034 2023 global $usces;
1035 - echo esc_html($usces->options['tel_number']);
2024 + echo esc_html( $usces->options['tel_number'] );
1036 2025 }
1037 2026
1038 -function usces_the_fax_number(){
2027 +/**
2028 + * Fax number
2029 + */
2030 +function usces_the_fax_number() {
1039 2031 global $usces;
1040 - echo esc_html($usces->options['fax_number']);
2032 + echo esc_html( $usces->options['fax_number'] );
1041 2033 }
1042 2034
1043 -function usces_the_inquiry_mail(){
2035 +/**
2036 + * Inquiry email address
2037 + */
2038 +function usces_the_inquiry_mail() {
1044 2039 global $usces;
1045 - echo esc_html($usces->options['inquiry_mail']);
2040 + echo esc_html( $usces->options['inquiry_mail'] );
1046 2041 }
1047 2042
1048 -function usces_the_postage_privilege(){
2043 +/**
2044 + * Postage privilege
2045 + */
2046 +function usces_the_postage_privilege() {
1049 2047 global $usces;
1050 - echo esc_html($usces->options['postage_privilege']);
2048 + echo esc_html( $usces->options['postage_privilege'] );
1051 2049 }
1052 2050
1053 -function usces_the_start_point(){
2051 +/**
2052 + * Initial point
2053 + */
2054 +function usces_the_start_point() {
1054 2055 global $usces;
1055 - echo esc_html($usces->options['start_point']);
2056 + echo esc_html( $usces->options['start_point'] );
1056 2057 }
1057 2058
1058 -function usces_point_rate( $post_id = NULL, $out = '' ){
2059 +/**
2060 + * Point rate
2061 + *
2062 + * @param int $post_id Post ID.
2063 + * @param string $out Return value or echo.
2064 + * @return string|void
2065 + */
2066 +function usces_point_rate( $post_id = null, $out = '' ) {
1059 2067 global $usces;
1060 - if( $post_id == NULL ){
2068 +
2069 + if ( null === $post_id ) {
1061 2070 $rate = $usces->options['point_rate'];
1062 - }else{
1063 - $str = get_post_meta($post_id, '_itemPointrate', true);
1064 - $rate = (int)$str;
2071 + } else {
2072 + $product = wel_get_product( $post_id );
2073 + $str = $product['itemPointrate'];
2074 + $rate = (int) $str;
1065 2075 }
1066 - if( $out == 'return' ){
1067 - return $rate;
1068 - }else{
1069 - echo $rate;
2076 + if ( 'return' === $out ) {
2077 + return wel_esc_script( $rate );
2078 + } else {
2079 + wel_esc_script_e( $rate );
1070 2080 }
1071 2081 }
1072 2082
1073 -function usces_point_rate_discount( $post_id = NULL, $out = '' ) {
2083 +/**
2084 + * Point discount
2085 + *
2086 + * @param int $post_id Post ID.
2087 + * @param string $out Return value or echo.
2088 + * @return string|void
2089 + */
2090 +function usces_point_rate_discount( $post_id = null, $out = '' ) {
1074 2091 global $post, $usces;
1075 - if( $post_id == NULL )
2092 +
2093 + if ( null === $post_id ) {
1076 2094 $post_id = $post->ID;
2095 + }
1077 2096
1078 - $str = get_post_meta( $post_id, '_itemPointrate', true );
1079 - $rate = (int)$str;
1080 - if( $usces->options['campaign_privilege'] == 'point' ) {
1081 - if( in_category((int)$usces->options['campaign_category'], $post_id) ) {
2097 + $product = wel_get_product( $post_id );
2098 + $str = $product['itemPointrate'];
2099 + $rate = (int) $str;
2100 + if ( 'point' === $usces->options['campaign_privilege'] ) {
2101 + if ( in_category( (int) $usces->options['campaign_category'], $post_id ) ) {
1082 2102 $rate *= $usces->options['privilege_point'];
1083 2103 }
1084 2104 }
1085 - if( $out == 'return' ) {
1086 - return $rate;
2105 + if ( 'return' === $out ) {
2106 + return wel_esc_script( $rate );
1087 2107 } else {
1088 - echo $rate;
2108 + wel_esc_script_e( $rate );
1089 2109 }
1090 2110 }
1091 2111
1092 -function usces_get_point( $post_id, $sku_code ){
2112 +/**
2113 + * Item point
2114 + *
2115 + * @param int $post_id Post ID.
2116 + * @param string $sku_code SKU code.
2117 + * @return int
2118 + */
2119 +function usces_get_point( $post_id, $sku_code ) {
1093 2120 global $usces;
1094 - if( $post_id == NULL ){
2121 +
2122 + if ( null === $post_id ) {
1095 2123 $rate = $usces->options['point_rate'];
1096 - }else{
1097 - $str = get_post_meta($post_id, '_itemPointrate', true);
1098 - $rate = (int)$str;
2124 + } else {
2125 + $product = wel_get_product( $post_id );
2126 + $str = $product['itemPointrate'];
2127 + $rate = (int) $str;
1099 2128 }
1100 -
1101 - $skus = $usces->get_skus($post_id, 'code');
1102 - $point = ceil($skus[$sku_code]['price'] * $rate / 100);
1103 -
2129 +
2130 + $skus = wel_get_skus( $post_id, 'code' );
2131 + $point = ceil( $skus[ $sku_code ]['price'] * $rate / 100 );
2132 +
1104 2133 return $point;
1105 2134 }
1106 2135
1107 -function usces_the_payment_method( $value = '', $out = '' ){
2136 +/**
2137 + * Payment method field
2138 + *
2139 + * @param string $value Value.
2140 + * @param string $out Return value or echo.
2141 + * @return string|void
2142 + */
2143 +function usces_the_payment_method( $value = '', $out = '' ) {
1108 2144 global $usces;
2145 +
1109 2146 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
1110 - $payments = apply_filters('usces_fiter_the_payment_method', $payments, $value);
1111 - //if( empty($payments) ) return; 20120328ysk 0000454
1112 -
1113 - $cart = $usces->cart->get_cart();
1114 - //$charging_type = $usces->getItemChargingType($cart[0]['post_id']);
1115 - $charging_type = $usces->getItemChargingType($cart[0]['post_id'], $cart);
1116 - $html = "<dl>\n";
1117 - $list = '';
1118 - $payment_ct = count($payments);
1119 -//20120328ysk start 0000454
1120 - //foreach ($payments as $id => $payment) {
1121 - foreach ((array)$payments as $id => $payment) {
1122 -//20120328ysk end
1123 - if( 'continue' == $charging_type ){
1124 - //if( 'acting' != substr($payments['settlement'], 0, 6) )
1125 -//20110412ysk start
1126 - //if( 'acting_remise_card' != $payment['settlement'] && 'acting_paypal_ec' != $payment['settlement']) {
1127 - $continue_payment_method = apply_filters( 'usces_filter_the_continue_payment_method', array( 'acting_remise_card', 'acting_paypal_ec' ) );
1128 - if( !in_array( $payment['settlement'], $continue_payment_method ) ) {
1129 - $payment_ct--;
1130 - continue;
2147 + $payments = apply_filters( 'usces_fiter_the_payment_method', $payments, $value );
2148 +
2149 + if ( defined( 'WCEX_DLSELLER_VERSION' ) && version_compare( WCEX_DLSELLER_VERSION, '2.2-beta', '<=' ) ) {
2150 + $cart = $usces->cart->get_cart();
2151 + $have_continue_charge = usces_have_continue_charge( $cart );
2152 + $continue_payment_method = apply_filters( 'usces_filter_the_continue_payment_method', array( 'acting_remise_card', 'acting_paypal_ec' ) );
2153 + }
2154 +
2155 + $list = '';
2156 + $payment_ct = ( $payments && is_array( $payments ) ) ? count( $payments ) : 0;
2157 + foreach ( (array) $payments as $id => $payment ) {
2158 + if ( defined( 'WCEX_DLSELLER_VERSION' ) && version_compare( WCEX_DLSELLER_VERSION, '2.2-beta', '<=' ) ) {
2159 + if ( $have_continue_charge ) {
2160 + if ( ! in_array( $payment['settlement'], $continue_payment_method, true ) ) {
2161 + $payment_ct--;
2162 + continue;
2163 + }
2164 + if ( isset( $usces->options['acting_settings']['remise']['continuation'] ) && 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' === $payment['settlement'] ) {
2165 + $payment_ct--;
2166 + continue;
2167 + } elseif ( isset( $usces->options['acting_settings']['paypal']['continuation'] ) && 'on' !== $usces->options['acting_settings']['paypal']['continuation'] && 'acting_paypal_ec' === $payment['settlement'] ) {
2168 + $payment_ct--;
2169 + continue;
2170 + }
1131 2171 }
1132 - //if( 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' == $payment['settlement'])
1133 - // continue;
1134 - if( 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' == $payment['settlement']) {
1135 - $payment_ct--;
1136 - continue;
1137 - } elseif( 'on' !== $usces->options['acting_settings']['paypal']['continuation'] && 'acting_paypal_ec' == $payment['settlement']) {
1138 - $payment_ct--;
1139 - continue;
1140 - }
1141 -//20110412ysk end
1142 2172 }
1143 - if( $payment['name'] != '' and $payment['use'] != 'deactivate' ) {
1144 - $module = trim($payment['module']);
1145 - if( !WCUtils::is_blank($value) ){
1146 - $checked = ($payment['name'] == $value) ? ' checked' : '';
1147 - }else if( 1 == $payment_ct ){//0000428
2173 + if ( '' !== $payment['name'] && 'deactivate' !== $payment['use'] ) {
2174 + $module = trim( $payment['module'] );
2175 + if ( ! WCUtils::is_blank( $value ) ) {
2176 + $checked = ( $payment['name'] === $value ) ? ' checked' : '';
2177 + } elseif ( 1 === $payment_ct ) {
1148 2178 $checked = ' checked';
1149 - }else{
2179 + } else {
1150 2180 $checked = '';
1151 2181 }
1152 - if( (empty($module) || !file_exists($usces->options['settlement_path'] . $module)) && $payment['settlement'] == 'acting' ) {
1153 - $checked = '';
1154 - $list .= "\t".'<dt class="payment_'.$id.'"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="'.esc_attr($payment['name']).'"' . $checked . ' disabled onKeyDown="if (event.keyCode == 13) {return false;}" />'.esc_attr($payment['name'])."</label> <b> (" . __('cannot use this payment method now.','usces') . ") </b></dt>\n";
1155 - }else{
1156 - $list .= "\t".'<dt class="payment_'.$id.'"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="'.esc_attr($payment['name']).'"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}" />'.esc_attr($payment['name'])."</label></dt>\n";
2182 + $payment_row = '';
2183 + $checked = apply_filters( 'usces_fiter_the_payment_method_checked', $checked, $payment, $value );
2184 + $explanation = apply_filters( 'usces_fiter_the_payment_method_explanation', $payment['explanation'], $payment, $value );
2185 + if ( ( empty( $module ) || ! file_exists( $usces->options['settlement_path'] . $module ) ) && 'acting' === $payment['settlement'] ) {
2186 + $checked = '';
2187 + $payment_row .= '<dt class="payment_' . $id . '"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="' . esc_attr( $payment['name'] ) . '"' . $checked . ' disabled onKeyDown="if (event.keyCode == 13) {return false;}" />' . esc_attr( $payment['name'] ) . '</label> <b>(' . __( 'cannot use this payment method now.', 'usces' ) . ')</b></dt>';
2188 + } else {
2189 + $payment_row .= '<dt class="payment_' . $id . '"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="' . esc_attr( $payment['name'] ) . '"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}" />' . esc_attr( $payment['name'] ) . '</label></dt>';
1157 2190 }
1158 - $list .= "\t".'<dd class="payment_'.$id.'">'.$payment['explanation'].'</dd>'."\n";
2191 + if ( ! empty( $explanation ) ) {
2192 + $explanation = wel_esc_script( $explanation );
2193 + $payment_row .= '<dd class="payment_' . $id . '">' . $explanation . '</dd>';
2194 + }
2195 + $payment_row = apply_filters( 'usces_filter_the_payment_method_row', $payment_row, $id, $payment, $checked, $module, $value, $explanation );
2196 + if ( ! empty( $payment_row ) ) {
2197 + $list .= $payment_row;
2198 + }
1159 2199 }
1160 2200 }
1161 2201
1162 - $html .= $list . "</dl>\n";
1163 -
1164 - if( empty($list) )
1165 - $html = __('Not yet ready for the payment method. Please refer to a manager.', 'usces')."\n";
1166 -
1167 - if( $out == 'return' ){
2202 + if ( ! empty( $list ) ) {
2203 + $html = '<dl>' . $list . '</dl>';
2204 + } else {
2205 + $html = '<div>' . __( 'Not yet ready for the payment method. Please refer to a manager.', 'usces' ) . '</div>';
2206 + }
2207 +
2208 + $html = apply_filters( 'usces_filter_the_payment_method_choices', $html, $payments );
2209 + if ( 'return' === $out ) {
1168 2210 return $html;
1169 - }else{
1170 - echo $html;
2211 + } else {
2212 + echo $html; // no escape due to filter.
1171 2213 }
1172 2214 }
1173 2215
1174 -function usces_get_payments_by_name( $name ){
1175 - global $usces;
2216 +/**
2217 + * Payment method
2218 + *
2219 + * @param string $name Payment method name.
2220 + * @return array
2221 + */
2222 +function usces_get_payments_by_name( $name ) {
2223 +
2224 + $init = array(
2225 + 'id' => null,
2226 + 'name' => null,
2227 + 'explanation' => null,
2228 + 'settlement' => null,
2229 + 'module' => null,
2230 + 'sort' => null,
2231 + 'use' => null,
2232 + );
1176 2233 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
1177 - if( empty($payments) ) return false;
1178 -
1179 - if( isset($payments[$name]) ) {
1180 - return $payments[$name];
2234 + if ( empty( $payments ) ) {
2235 + return $init;
1181 2236 }
2237 + if ( isset( $payments[ $name ] ) ) {
2238 + return $payments[ $name ];
2239 + }
1182 2240
1183 - return false;
2241 + return $init;
1184 2242 }
1185 2243
1186 -function usces_the_delivery_method( $value = '', $out = '' ){
2244 +/**
2245 + * Delivery method field
2246 + *
2247 + * @param string $value Value.
2248 + * @param string $out Return value or echo.
2249 + * @return string|void
2250 + */
2251 +function usces_the_delivery_method( $value = '', $out = '' ) {
1187 2252 global $usces;
1188 - $deli_id = apply_filters('usces_filter_get_available_delivery_method', $usces->get_available_delivery_method());
1189 - if( empty($deli_id) ){
1190 - $html = '<p>' . __('No valid shipping methods.', 'usces') . '</p>';
1191 - }else{
1192 - $cdeliid = count($deli_id);
1193 - $html = '<select name="offer[delivery_method]" id="delivery_method_select" class="delivery_time" onKeyDown="if (event.keyCode == 13) {return false;}">'."\n";
1194 - foreach ($deli_id as $id) {
1195 - $index = $usces->get_delivery_method_index($id);
1196 - $selected = ($id == $value || 1 === $cdeliid) ? ' selected="selected"' : '';
1197 - $html .= "\t<option value='{$id}'{$selected}>" . esc_html($usces->options['delivery_method'][$index]['name']) . "</option>\n";
2253 +
2254 + $deli_id = apply_filters( 'usces_filter_get_available_delivery_method', $usces->get_available_delivery_method() );
2255 + if ( empty( $deli_id ) ) {
2256 + $html = '<p>' . __( 'No valid shipping methods.', 'usces' ) . '</p>';
2257 + } else {
2258 + $cdeliid = ( is_array( $deli_id ) ) ? count( $deli_id ) : 0;
2259 + $html = '<select name="offer[delivery_method]" id="delivery_method_select" class="delivery_time" onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
2260 + foreach ( (array) $deli_id as $id ) {
2261 + $index = $usces->get_delivery_method_index( $id );
2262 + if ( 0 <= $index ) {
2263 + $selected = ( (string) $id === (string) $value || 1 === $cdeliid ) ? ' selected="selected"' : '';
2264 + $html .= "\t<option value=\"{$id}\"{$selected}>" . esc_html( $usces->options['delivery_method'][ $index ]['name'] ) . "</option>\n";
2265 + }
1198 2266 }
1199 -
1200 2267 $html .= "</select>\n";
1201 2268 }
1202 -
1203 - if( $out == 'return' ){
2269 +
2270 + $html = apply_filters( 'usces_filter_the_delivery_method', $html, $deli_id );
2271 +
2272 + if ( 'return' === $out ) {
1204 2273 return $html;
1205 - }else{
1206 - echo $html;
2274 + } else {
2275 + echo $html; // no escape due to filter.
1207 2276 }
1208 2277 }
1209 -//20101208ysk start
1210 -function usces_the_delivery_date( $value = '', $out = '' ){
1211 - global $usces;
1212 2278
1213 - $html = "<select name='offer[delivery_date]' id='delivery_date_select' class='delivery_date'>\n";
2279 +/**
2280 + * Delivery date field
2281 + *
2282 + * @param string $value Value.
2283 + * @param string $out Return value or echo.
2284 + * @return string|void
2285 + */
2286 +function usces_the_delivery_date( $value = '', $out = '' ) {
2287 +
2288 + $html = "<select name=\"offer[delivery_date]\" id=\"delivery_date_select\" class=\"delivery_date\">\n";
1214 2289 $html .= "</select>\n";
2290 + $html = apply_filters( 'the_delivery_date', $html );
1215 2291
1216 - if( $out == 'return' ){
2292 + if ( 'return' === $out ) {
1217 2293 return $html;
1218 - }else{
1219 - echo $html;
2294 + } else {
2295 + echo $html; // no escape due to filter.
1220 2296 }
1221 2297 }
1222 -//20101208ysk end
1223 -function usces_the_delivery_time( $value = '', $out = '' ){
1224 - global $usces;
1225 -
1226 -//20101208ysk start
1227 - //$html = "<select name='offer[delivery_time]' id='delivery_time_select' class='delivery_time'>\n";
1228 - $html = "<div id='delivery_time_limit_message'></div>\n";
1229 - $html .= "<select name='offer[delivery_time]' id='delivery_time_select' class='delivery_time'>\n";
1230 -//20101208ysk end
1231 2298
2299 +/**
2300 + * Delivery time field
2301 + *
2302 + * @param string $value Value.
2303 + * @param string $out Return value or echo.
2304 + * @return string|void
2305 + */
2306 +function usces_the_delivery_time( $value = '', $out = '' ) {
2307 +
2308 + $html = "<div id=\"delivery_time_limit_message\"></div>\n";
2309 + $html .= "<select name=\"offer[delivery_time]\" id=\"delivery_time_select\" class=\"delivery_time\">\n";
1232 2310 $html .= "</select>\n";
1233 -
1234 - if( $out == 'return' ){
2311 + $html = apply_filters( 'the_delivery_time', $html );
2312 +
2313 + if ( 'return' === $out ) {
1235 2314 return $html;
1236 - }else{
1237 - echo $html;
2315 + } else {
2316 + echo $html; // no escape due to filter.
1238 2317 }
1239 2318 }
1240 2319
1241 -function usces_the_campaign_schedule($flag, $kind){
2320 +/**
2321 + * Campaign Schedule
2322 + *
2323 + * @param string $flag Flag.
2324 + * @param string $kind Kind.
2325 + */
2326 +function usces_the_campaign_schedule( $flag, $kind ) {
1242 2327 global $usces;
1243 - $startdate = $usces->options['campaign_schedule']['start']['year'] . __('year','usces') . $usces->options['campaign_schedule']['start']['month'] . __('month','usces') . $usces->options['campaign_schedule']['start']['day'] . __('day','usces');
1244 - $starttime = $usces->options['campaign_schedule']['start']['hour'] . __('hour','usces') . $usces->options['campaign_schedule']['start']['min'] . __('min','usces');
1245 - $enddate = $usces->options['campaign_schedule']['end']['year'] . __('year','usces') . $usces->options['campaign_schedule']['end']['month'] . __('month','usces') . $usces->options['campaign_schedule']['end']['day'] . __('day','usces');
1246 - $endtime = $usces->options['campaign_schedule']['end']['hour'] . __('hour','usces') . $usces->options['campaign_schedule']['end']['min'] . __('min','usces');
1247 - if( 'start' == $flag ) {
1248 - if( 'date' == $kind ) {
1249 - echo esc_html($startdate);
1250 - }elseif( 'datetime' == $kind ) {
1251 - echo esc_html($startdate . ' ' . $starttime);
2328 +
2329 + $startdate = $usces->options['campaign_schedule']['start']['year'] . __( 'year', 'usces' ) . $usces->options['campaign_schedule']['start']['month'] . __( 'month', 'usces' ) . $usces->options['campaign_schedule']['start']['day'] . __( 'day', 'usces' );
2330 + $starttime = $usces->options['campaign_schedule']['start']['hour'] . __( 'hour', 'usces' ) . $usces->options['campaign_schedule']['start']['min'] . __( 'min', 'usces' );
2331 + $enddate = $usces->options['campaign_schedule']['end']['year'] . __( 'year', 'usces' ) . $usces->options['campaign_schedule']['end']['month'] . __( 'month', 'usces' ) . $usces->options['campaign_schedule']['end']['day'] . __( 'day', 'usces' );
2332 + $endtime = $usces->options['campaign_schedule']['end']['hour'] . __( 'hour', 'usces' ) . $usces->options['campaign_schedule']['end']['min'] . __( 'min', 'usces' );
2333 + if ( 'start' === $flag ) {
2334 + if ( 'date' === $kind ) {
2335 + echo esc_html( $startdate );
2336 + } elseif ( 'datetime' === $kind ) {
2337 + echo esc_html( $startdate . ' ' . $starttime );
1252 2338 }
1253 - } elseif ( 'end' == $flag ) {
1254 - if( 'date' == $kind ) {
1255 - echo esc_html($enddate);
1256 - }elseif( 'datetime' == $kind ) {
1257 - echo esc_html($enddate . ' ' . $endtime);
2339 + } elseif ( 'end' === $flag ) {
2340 + if ( 'date' === $kind ) {
2341 + echo esc_html( $enddate );
2342 + } elseif ( 'datetime' === $kind ) {
2343 + echo esc_html( $enddate . ' ' . $endtime );
1258 2344 }
1259 2345 }
1260 2346 }
1261 2347
1262 -
2348 +/**
2349 + * Display cart confirm
2350 + */
1263 2351 function usces_the_confirm() {
1264 2352 global $usces;
1265 -
1266 2353 $usces->display_cart_confirm();
1267 2354 }
1268 2355
2356 +/**
2357 + * Inquiry
2358 + */
1269 2359 function usces_inquiry_condition() {
1270 2360 global $error_message, $reserve, $inq_name, $inq_mailaddress, $inq_contents;
1271 - require(USCES_PLUGIN_DIR.'/includes/inquiry_condition.php');
2361 + require USCES_PLUGIN_DIR . '/includes/inquiry_condition.php';
1272 2362 }
1273 2363
2364 +/**
2365 + * Inquiry form
2366 + */
1274 2367 function usces_the_inquiry_form() {
1275 2368 global $usces;
2369 +
1276 2370 $error_message = '';
1277 - if( isset($_POST['inq_name']) && !WCUtils::is_blank($_POST['inq_name']) ) {
1278 - $inq_name = trim($_POST['inq_name']);
1279 - }else{
2371 + if ( isset( $_POST['inq_name'] ) && ! WCUtils::is_blank( $_POST['inq_name'] ) ) {
2372 + $inq_name = trim( wp_unslash( $_POST['inq_name'] ) );
2373 + } else {
1280 2374 $inq_name = '';
1281 - if($usces->page == 'deficiency')
1282 - $error_message .= __('Please input your name.', 'usces') . "<br />";
2375 + if ( 'deficiency' === $usces->page ) {
2376 + $error_message .= __( 'Please input your name.', 'usces' ) . '<br />';
2377 + }
1283 2378 }
1284 - if( isset($_POST['inq_mailaddress']) && is_email(trim($_POST['inq_mailaddress'])) ) {
1285 - $inq_mailaddress = trim($_POST['inq_mailaddress']);
1286 - }elseif( isset($_POST['inq_mailaddress']) && !is_email(trim($_POST['inq_mailaddress'])) ) {
1287 - $inq_mailaddress = trim($_POST['inq_mailaddress']);
1288 - if($usces->page == 'deficiency')
1289 - $error_message .= __('E-mail address is not correct', 'usces') . "<br />";
1290 - }else{
2379 + if ( isset( $_POST['inq_mailaddress'] ) && is_email( trim( wp_unslash( $_POST['inq_mailaddress'] ) ) ) ) {
2380 + $inq_mailaddress = trim( wp_unslash( $_POST['inq_mailaddress'] ) );
2381 + } elseif ( isset( $_POST['inq_mailaddress'] ) && ! is_email( trim( wp_unslash( $_POST['inq_mailaddress'] ) ) ) ) {
2382 + $inq_mailaddress = trim( wp_unslash( $_POST['inq_mailaddress'] ) );
2383 + if ( 'deficiency' === $usces->page ) {
2384 + $error_message .= __( 'E-mail address is not correct', 'usces' ) . '<br />';
2385 + }
2386 + } else {
1291 2387 $inq_mailaddress = '';
1292 - if($usces->page == 'deficiency')
1293 - $error_message .= __('Please input your e-mail address.', 'usces') . "<br />";
2388 + if ( 'deficiency' === $usces->page ) {
2389 + $error_message .= __( 'Please input your e-mail address.', 'usces' ) . '<br />';
2390 + }
1294 2391 }
1295 - if( isset($_POST['inq_contents']) && !WCUtils::is_blank($_POST['inq_contents']) ) {
1296 - $inq_contents = trim($_POST['inq_contents']);
1297 - }else{
2392 + if ( isset( $_POST['inq_contents'] ) && ! WCUtils::is_blank( $_POST['inq_contents'] ) ) {
2393 + $inq_contents = trim( wp_unslash( $_POST['inq_contents'] ) );
2394 + } else {
1298 2395 $inq_contents = '';
1299 - if($usces->page == 'deficiency')
1300 - $error_message .= __('Please input contents.', 'usces');
2396 + if ( 'deficiency' === $usces->page ) {
2397 + $error_message .= __( 'Please input contents.', 'usces' );
2398 + }
1301 2399 }
1302 -
1303 2400
1304 - if($usces->page == 'inquiry_comp') :
1305 - $inq_message = apply_filters( 'usces_filter_inquiry_message_completion', __('I send a reply email to a visitor. I ask in a few minutes to be able to have you refer in there being the fear that e-mail address is different again when the email from this shop does not arrive.', 'usces') );
1306 -?>
1307 - <div class="inquiry_comp"><?php _e('sending completed','usces') ?></div>
1308 - <div class="compbox"><?php echo $inq_message; ?></div>
1309 -<?php
1310 - elseif($usces->page == 'inquiry_error') :
1311 -?>
1312 - <div class="inquiry_comp"><?php _e('Failure in sending','usces') ?></div>
1313 -<?php
2401 + if ( 'inquiry_comp' === $usces->page ) :
2402 + $inq_message = apply_filters( 'usces_filter_inquiry_message_completion', __( 'I send a reply email to a visitor. I ask in a few minutes to be able to have you refer in there being the fear that e-mail address is different again when the email from this shop does not arrive.', 'usces' ) );
2403 + ?>
2404 + <div class="inquiry_comp"><?php esc_html_e( 'sending completed', 'usces' ); ?></div>
2405 + <div class="compbox"><?php wel_esc_script_e( $inq_message ); ?></div>
2406 + <?php
2407 + elseif ( 'inquiry_error' === $usces->page ) :
2408 + ?>
2409 + <div class="inquiry_comp"><?php esc_html_e( 'Failure in sending', 'usces' ); ?></div>
2410 + <?php
1314 2411 else :
1315 -?>
1316 -<?php if( !empty($error_message) ): ?>
1317 -<div class="error_message"><?php echo $error_message; ?></div>
1318 -<?php endif; ?>
1319 -<form name="inquiry_form" action="<?php //echo USCES_CART_URL; ?>" method="post">
2412 + ?>
2413 + <?php if ( ! empty( $error_message ) ) : ?>
2414 +<div class="error_message"><?php wel_esc_script_e( $error_message ); ?></div>
2415 + <?php endif; ?>
2416 +<form name="inquiry_form" method="post">
2417 +<input type="hidden" name="kakuninyou" />
1320 2418 <table border="0" cellpadding="0" cellspacing="0" class="inquiry_table">
1321 2419 <tr>
1322 -<th scope="row"><?php _e('Full name','usces') ?></th>
1323 -<td><input name="inq_name" type="text" class="inquiry_name" value="<?php echo esc_attr($inq_name); ?>" /></td>
2420 +<th scope="row"><?php esc_html_e( 'Full name', 'usces' ); ?></th>
2421 +<td><input name="inq_name" type="text" class="inquiry_name" value="<?php echo esc_attr( $inq_name ); ?>" /></td>
1324 2422 </tr>
1325 2423 <tr>
1326 -<th scope="row"><?php _e('e-mail adress','usces') ?></th>
1327 -<td><input name="inq_mailaddress" type="text" class="inquiry_mailaddress" value="<?php echo esc_attr($inq_mailaddress); ?>" /></td>
2424 +<th scope="row"><?php esc_html_e( 'e-mail adress', 'usces' ); ?></th>
2425 +<td><input name="inq_mailaddress" type="text" class="inquiry_mailaddress" value="<?php echo esc_attr( $inq_mailaddress ); ?>" /></td>
1328 2426 </tr>
1329 2427 <tr>
1330 -<th scope="row"><?php _e('contents','usces') ?></th>
1331 -<td><textarea name="inq_contents" class="inquiry_contents"><?php echo esc_attr($inq_contents); ?></textarea></td>
2428 +<th scope="row"><?php esc_html_e( 'contents', 'usces' ); ?></th>
2429 +<td><textarea name="inq_contents" class="inquiry_contents"><?php echo esc_attr( $inq_contents ); ?></textarea></td>
1332 2430 </tr>
1333 2431 </table>
1334 -<div class="send"><input name="inquiry_button" type="submit" value="<?php _e('Admit to send it with this information.','usces') ?>" /></div>
2432 +<div class="send"><input name="inquiry_button" type="submit" value="<?php esc_attr_e( 'Admit to send it with this information.', 'usces' ); ?>" /></div>
1335 2433 </form>
1336 -<?php
2434 + <?php
1337 2435 endif;
1338 2436 }
1339 2437
2438 +/**
2439 + * Get Category ID
2440 + *
2441 + * @param string $slug Slag.
2442 + * @return int
2443 + */
1340 2444 function usces_get_cat_id( $slug ) {
1341 - $cat = get_category_by_slug( $slug );
1342 - return $cat->term_id;
2445 + $cat = get_category_by_slug( $slug );
2446 + $term_id = $cat->term_id ?? 0;
2447 + return $term_id;
1343 2448 }
1344 2449
2450 +/**
2451 + * Widget Calendar
2452 + */
1345 2453 function usces_the_calendar() {
1346 2454 global $usces;
1347 - include (USCES_PLUGIN_DIR . '/includes/widget_calendar.php');
2455 + include USCES_PLUGIN_DIR . '/includes/widget_calendar.php';
1348 2456 }
1349 2457
1350 -function usces_loginout( $out = '') {
2458 +/**
2459 + * Login/Logout link
2460 + *
2461 + * @param string $out Return value or echo.
2462 + * @return string|void
2463 + */
2464 +function usces_loginout( $out = '' ) {
1351 2465 global $usces;
1352 - if ( !$usces->is_member_logged_in() )
1353 - $res = '<a href="' . apply_filters('usces_filter_login_uri', USCES_LOGIN_URL) . '" class="usces_login_a">' . apply_filters('usces_filter_loginlink_label', __('Log-in','usces')) . '</a>';
1354 - else
1355 - $res = '<a href="' . apply_filters('usces_filter_logout_uri', USCES_LOGOUT_URL) . '" class="usces_logout_a">' . apply_filters('usces_filter_logoutlink_label', __('Log out','usces')) . '</a>';
1356 2466
1357 - if( $out == 'return' ){
1358 - return $res;
1359 - }else{
1360 - echo $res;
2467 + if ( ! $usces->is_member_logged_in() ) {
2468 + $res = '<a href="' . apply_filters( 'usces_filter_login_uri', USCES_LOGIN_URL ) . '" class="usces_login_a">' . apply_filters( 'usces_filter_loginlink_label', __( 'Log-in', 'usces' ) ) . '</a>';
2469 + } else {
2470 + $res = '<a href="' . apply_filters( 'usces_filter_logout_uri', USCES_LOGOUT_URL ) . '" class="usces_logout_a">' . apply_filters( 'usces_filter_logoutlink_label', __( 'Log out', 'usces' ) ) . '</a>';
1361 2471 }
2472 + if ( 'return' === $out ) {
2473 + return wel_esc_script( $res );
2474 + } else {
2475 + wel_esc_script_e( $res );
2476 + }
1362 2477 }
1363 2478
2479 +/**
2480 + * Is Login
2481 + *
2482 + * @return bool
2483 + */
1364 2484 function usces_is_login() {
1365 2485 global $usces;
1366 -
1367 - if( false === $usces->is_member_logged_in() )
2486 +
2487 + if ( false === $usces->is_member_logged_in() ) {
1368 2488 $res = false;
1369 - else
2489 + } else {
1370 2490 $res = true;
1371 -
2491 + }
1372 2492 return $res;
1373 2493 }
1374 2494
1375 -function usces_the_member_name( $out = '') {
2495 +/**
2496 + * Member Name
2497 + *
2498 + * @param string $out Return value or echo.
2499 + * @return string|void
2500 + */
2501 +function usces_the_member_name( $out = '' ) {
1376 2502 global $usces;
2503 +
1377 2504 $usces->get_current_member();
1378 - $res = esc_html($usces->current_member['name']);
1379 - if( $out == 'return' ){
1380 - return $res;
1381 - }else{
1382 - echo $res;
2505 + $res = esc_html( $usces->current_member['name'] );
2506 + if ( 'return' === $out ) {
2507 + return wel_esc_script( $res );
2508 + } else {
2509 + wel_esc_script_e( $res );
1383 2510 }
1384 -
1385 2511 }
1386 2512
2513 +/**
2514 + * Membership Point
2515 + *
2516 + * @param string $out Return value or echo.
2517 + * @return string|void
2518 + */
1387 2519 function usces_the_member_point( $out = '' ) {
1388 2520 global $usces;
1389 -
1390 - if( !$usces->is_member_logged_in() ) return;
1391 -
2521 +
2522 + if ( ! $usces->is_member_logged_in() ) {
2523 + return;
2524 + }
2525 +
1392 2526 $member = $usces->get_member();
1393 - if( $out == 'return' ){
2527 +
2528 + if ( 'return' === $out ) {
1394 2529 return $member['point'];
1395 - }else{
1396 - echo number_format($member['point']);
2530 + } else {
2531 + echo number_format( $member['point'] );
1397 2532 }
1398 2533 }
1399 2534
2535 +/**
2536 + * Membership Rank
2537 + *
2538 + * @param string $out Return value or echo.
2539 + * @return string|void
2540 + */
1400 2541 function usces_the_member_status( $out = '' ) {
1401 2542 global $usces;
1402 - if( !$usces->is_member_logged_in() ) return;
1403 -
2543 +
2544 + if ( ! $usces->is_member_logged_in() ) {
2545 + return;
2546 + }
2547 +
1404 2548 $usces->get_current_member();
1405 - $member = $usces->get_member_info($usces->current_member['id']);
1406 - $status_name = $usces->member_status[$member['mem_status']];
2549 + $member = $usces->get_member_info( $usces->current_member['id'] );
2550 + $status_name = $usces->member_status[ $member['mem_status'] ];
1407 2551
1408 - if( $out == 'return' ){
2552 + if ( 'return' === $out ) {
1409 2553 return $status_name;
1410 - }else{
1411 - echo esc_html($status_name);
2554 + } else {
2555 + echo esc_html( $status_name );
1412 2556 }
1413 2557 }
1414 2558
1415 -function usces_get_assistance_id_list($post_id) {
2559 +/**
2560 + * Related item list
2561 + *
2562 + * @param int $post_id Post ID.
2563 + * @return array
2564 + */
2565 +function usces_get_assistance_id_list( $post_id ) {
1416 2566 global $usces;
1417 - $names = $usces->get_tag_names($post_id);
1418 - $list = '';
1419 - foreach ( $names as $itemname )
1420 - $list .= $usces->get_ID_byItemName($itemname, 'publish') . ',';
1421 -
1422 - $list = trim($list, ',');
1423 2567
2568 + $names = $usces->get_tag_names( $post_id );
2569 + $list = '';
2570 + foreach ( (array) $names as $itemname ) {
2571 + $list .= $usces->get_ID_byItemName( $itemname, 'publish' ) . ',';
2572 + }
2573 + $list = trim( $list, ',' );
1424 2574 return $list;
1425 2575 }
1426 -function usces_get_assistance_ids($post_id) {
2576 +
2577 +/**
2578 + * Related item
2579 + *
2580 + * @param int $post_id Post ID.
2581 + * @return array
2582 + */
2583 +function usces_get_assistance_ids( $post_id ) {
1427 2584 global $usces;
1428 - $names = $usces->get_tag_names($post_id);
1429 - $ids = array();
1430 - foreach ( $names as $itemname )
1431 - $ids[] = $usces->get_ID_byItemName($itemname, 'publish');
1432 2585
2586 + $names = $usces->get_tag_names( $post_id );
2587 + $ids = array();
2588 + foreach ( $names as $itemname ) {
2589 + $ids[] = $usces->get_ID_byItemName( $itemname, 'publish' );
2590 + }
1433 2591 return $ids;
1434 2592 }
1435 -function usces_remembername( $out = '' ){
2593 +
2594 +/**
2595 + * Forgot account
2596 + *
2597 + * @param string $out Return value or echo.
2598 + * @return string|void
2599 + */
2600 +function usces_remembername( $out = '' ) {
1436 2601 global $usces;
2602 +
1437 2603 $value = $usces->get_cookie();
1438 -
1439 - if( $out == 'return' ){
1440 - if(isset($value['name']))
1441 - return $value['name'];
1442 - else
2604 + if ( 'return' === $out ) {
2605 +// if ( isset( $value['name'] ) )
2606 +// return $value['name'];
2607 +// else
1443 2608 return '';
1444 - }else{
1445 - if(isset($value['name']))
1446 - echo esc_html($value['name']);
1447 - else
2609 + } else {
2610 +// if ( isset( $value['name'] ) )
2611 +// echo esc_html( $value['name'] );
2612 +// else
1448 2613 echo '';
1449 2614 }
1450 2615 }
1451 -function usces_rememberpass( $out = '' ){
2616 +
2617 +/**
2618 + * Forgot password
2619 + *
2620 + * @param string $out Return value or echo.
2621 + * @return string|void
2622 + */
2623 +function usces_rememberpass( $out = '' ) {
1452 2624 global $usces;
2625 +
1453 2626 $value = $usces->get_cookie();
1454 -
1455 - if( $out == 'return' ){
1456 - if(isset($value['pass']))
1457 - return $value['pass'];
1458 - else
2627 + if ( 'return' === $out ) {
2628 +// if ( isset( $value['pass'] ) )
2629 +// return $value['pass'];
2630 +// else
1459 2631 return '';
1460 - }else{
1461 - if(isset($value['pass']))
1462 - echo esc_html($value['pass']);
1463 - else
2632 + } else {
2633 +// if ( isset( $value['pass'] ) )
2634 +// echo esc_html( $value['pass'] );
2635 +// else
1464 2636 echo '';
1465 2637 }
1466 2638 }
1467 -function usces_remembercheck( $out = '' ){
2639 +
2640 +/**
2641 + * Forgot account check
2642 + *
2643 + * @param string $out Return value or echo.
2644 + * @return string|void
2645 + */
2646 +function usces_remembercheck( $out = '' ) {
1468 2647 global $usces;
2648 +
1469 2649 $value = $usces->get_cookie();
1470 -
1471 - if( $out == 'return' ){
1472 - if(isset($value['name']) && $value['name'] != '')
1473 - return ' checked="checked"';
1474 - else
2650 + if ( 'return' === $out ) {
2651 +// if ( isset( $value['name'] ) && $value['name'] != '' )
2652 +// return ' checked="checked"';
2653 +// else
1475 2654 return '';
1476 - }else{
1477 - if(isset($value['name']) && $value['name'] != '')
1478 - echo ' checked="checked"';
1479 - else
2655 + } else {
2656 +// if ( isset( $value['name'] ) && $value['name'] != '' )
2657 +// echo ' checked="checked"';
2658 +// else
1480 2659 echo '';
1481 2660 }
1482 2661 }
1483 -function usces_shippingchargeTR( $index='' ) {
2662 +
2663 +/**
2664 + * Shipping charge table
2665 + *
2666 + * @param string $index Index.
2667 + */
2668 +function usces_shippingchargeTR( $index = '' ) {
1484 2669 global $usces;
1485 - if($index == ""){
2670 +
2671 + if ( '' === $index ) {
1486 2672 $index = 0;
1487 2673 }
1488 2674 $list = '';
1489 - if( !isset($usces->options['shipping_charge'][$index]) ) return;
1490 - $shipping_charge = $usces->options['shipping_charge'][$index];
1491 -//20120710ysk start 0000472
1492 - $entry = $usces->cart->get_entry();
1493 - $country = (isset($entry['delivery']['country']) && !empty($entry['delivery']['country'])) ? $entry['delivery']['country'] : $entry['customer']['country'];//20120710ysk 0000472
1494 - //foreach ($shipping_charge['value'] as $pref => $value) {
1495 - foreach ($shipping_charge[$country] as $pref => $value) {
1496 -//20120710ysk end
1497 - $list .= "<tr><th>" . esc_html($pref) . "</th>\n";
1498 - $list .= "<td class='rightnum'>" . number_format($value) . "</td>\n";
2675 + if ( ! isset( $usces->options['shipping_charge'][ $index ] ) ) {
2676 + return;
2677 + }
2678 + $shipping_charge = $usces->options['shipping_charge'][ $index ];
2679 + $entry = $usces->cart->get_entry();
2680 + $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
2681 + foreach ( $shipping_charge[ $country ] as $pref => $value ) {
2682 + $list .= '<tr><th>' . esc_html( $pref ) . "</th>\n";
2683 + $list .= '<td class="rightnum">' . number_format( $value ) . "</td>\n";
1499 2684 $list .= "</tr>\n";
1500 2685 }
1501 - echo $list;
2686 + wel_esc_script_e( $list );
1502 2687 }
2688 +
2689 +/**
2690 + * Shipping charge
2691 + */
1503 2692 function usces_sc_shipping_charge() {
1504 2693 global $usces;
1505 - echo esc_html($usces->sc_shipping_charge());
2694 + echo esc_html( $usces->sc_shipping_charge() );
1506 2695 }
2696 +
2697 +/**
2698 + * Postage privilege
2699 + */
1507 2700 function usces_sc_postage_privilege() {
1508 2701 global $usces;
1509 - echo esc_html($usces->sc_postage_privilege());
2702 + echo esc_html( $usces->sc_postage_privilege() );
1510 2703 }
2704 +
2705 +/**
2706 + * Payment title
2707 + */
1511 2708 function usces_sc_payment_title() {
1512 2709 global $usces;
1513 - echo $usces->sc_payment_title();
2710 + wel_esc_script_e( $usces->sc_payment_title() );
1514 2711 }
1515 2712
1516 -
1517 -
1518 -function usces_posts_random_offset( $posts ){
2713 +/**
2714 + * Posts offset
2715 + *
2716 + * @param object $posts Post data.
2717 + * @return int
2718 + */
2719 +function usces_posts_random_offset( $posts ) {
1519 2720 $ids = array();
1520 - foreach( (array)$posts as $post ){
2721 + foreach ( (array) $posts as $post ) {
1521 2722 $ids[] = $post->ID;
1522 2723 }
1523 - $ct = count($ids);
1524 - $index = rand(0, ($ct-1));
2724 + $ct = count( $ids );
2725 + $index = rand( 0, ( $ct - 1 ) );
1525 2726 return $index;
1526 2727 }
1527 2728
1528 -function usces_get_category_link_by_slug( $slug ){
1529 - $category = get_category_by_slug($slug);
2729 +/**
2730 + * Get category link
2731 + *
2732 + * @param string $slug Slug.
2733 + */
2734 +function usces_get_category_link_by_slug( $slug ) {
2735 + $category = get_category_by_slug( $slug );
1530 2736 echo get_category_link( $category->term_id );
1531 2737 }
1532 2738
1533 -function usces_get_page_ID_by_pname( $post_name, $return = 'echo' ){
2739 +/**
2740 + * Get page ID
2741 + *
2742 + * @param string $post_name Post name.
2743 + * @param string $return Return value or echo.
2744 + * @return string|void
2745 + */
2746 +function usces_get_page_ID_by_pname( $post_name, $return = 'echo' ) {
1534 2747 $page = get_page_by_path( $post_name );
1535 - if($return == 'return')
2748 + if ( 'return' === $return ) {
1536 2749 return $page->ID;
1537 - else
1538 - echo $page->ID;
2750 + } else {
2751 + echo esc_attr( $page->ID );
2752 + }
1539 2753 }
1540 2754
1541 -function usces_list_bestseller($num, $days = ''){
2755 +/**
2756 + * Bestseller
2757 + *
2758 + * @param int $num Number.
2759 + * @param string $days Days.
2760 + */
2761 +function usces_list_bestseller( $num, $days = '' ) {
1542 2762 global $usces;
2763 +
1543 2764 $ids = $usces->get_bestseller_ids( $days );
1544 - $htm = "";
1545 - for($i=0; $i<$num; $i++){
1546 - if(isset($ids[$i])){
1547 - $post = get_post($ids[$i]);
1548 - if( !is_object($post) )
2765 + $htm = '';
2766 + for ( $i = 0; $i < $num; $i++ ) {
2767 + if ( isset( $ids[ $i ] ) ) {
2768 + $post_id = (int) $ids[ $i ];
2769 + $product = wel_get_product( $post_id );
2770 + $post = $product['_pst'];
2771 +
2772 + if ( false === $product ) {
1549 2773 continue;
1550 -
1551 - $disp_text = apply_filters('usces_widget_bestseller_auto_text', esc_html($post->post_title), $ids[$i]);
1552 - $list = "<li><a href='" . get_permalink($ids[$i]) . "'>" . $disp_text . "</a></li>\n";
1553 - $htm .= apply_filters('usces_filter_bestseller', $list, $ids[$i], $i);
2774 + }
2775 +
2776 + $disp_text = apply_filters( 'usces_widget_bestseller_auto_text', esc_html( $post->post_title ), $post_id );
2777 + $list = '<li><a href="' . get_permalink( $post_id ) . '">' . $disp_text . "</a></li>\n";
2778 + $htm .= apply_filters( 'usces_filter_bestseller', $list, $post_id, $i );
1554 2779 }
1555 2780 }
1556 2781 wp_reset_postdata();
1557 - echo $htm;
2782 + wel_esc_script_e( $htm );
1558 2783 }
1559 2784
1560 -function usces_list_post( $slug, $rownum, $widget_id=NULL ){
1561 - global $usces, $post;
2785 +/**
2786 + * Post list
2787 + *
2788 + * @param string $slug Slug.
2789 + * @param string $rownum Page number.
2790 + * @param string $widget_id Widget ID.
2791 + */
2792 +function usces_list_post( $slug, $rownum, $widget_id = null ) {
2793 + global $post;
2794 +
1562 2795 usces_remove_filter();
1563 -
1564 - $li = '';
1565 - $infolist = new wp_query( array('category_name'=>$slug, 'post_status'=>'publish', 'posts_per_page'=>$rownum, 'order'=>'DESC', 'orderby'=>'date') );
1566 - if( NULL != $widget_id && $infolist->have_posts() ){
2796 +
2797 + $li = '';
2798 + $infolist = new WP_Query( array( 'category_name' => $slug, 'post_status' => 'publish', 'posts_per_page' => $rownum, 'order' => 'DESC', 'orderby' => 'date' ) );
2799 + if ( null !== $widget_id && $infolist->have_posts() ) {
1567 2800 remove_filter( 'excerpt_length', 'welcart_excerpt_length' );
1568 2801 remove_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' );
1569 2802 remove_filter( 'excerpt_more', 'welcart_auto_excerpt_more' );
1570 - if( function_exists('welcart_widget_post_excerpt_length_'.$widget_id) )
1571 - add_filter( 'excerpt_length', 'welcart_widget_post_excerpt_length_'.$widget_id );
1572 - if( function_exists('welcart_widget_post_excerpt_mblength_'.$widget_id) )
1573 - add_filter( 'excerpt_mblength', 'welcart_widget_post_excerpt_mblength_'.$widget_id );
2803 + if ( function_exists( 'welcart_widget_post_excerpt_length_' . $widget_id ) ) {
2804 + add_filter( 'excerpt_length', 'welcart_widget_post_excerpt_length_' . $widget_id );
2805 + }
2806 + if ( function_exists( 'welcart_widget_post_excerpt_mblength_' . $widget_id ) ) {
2807 + add_filter( 'excerpt_mblength', 'welcart_widget_post_excerpt_mblength_' . $widget_id );
2808 + }
1574 2809 }
1575 2810 $list_index = 0;
1576 - while ($infolist->have_posts()) {
2811 + while ( $infolist->have_posts() ) {
1577 2812 $infolist->the_post();
1578 - $list = '<li class="post_list'. apply_filters('usces_filter_post_list_class', NULL, $list_index, count($infolist)) . '">'."\n";
1579 - $list .= "<div class='title'><a href='" . get_permalink($post->ID) . "'>" . get_the_title() . "</a></div>\n";
1580 - $list .= "<p>" . get_the_excerpt() . "</p>\n";
2813 + $list = '<li class="post_list' . apply_filters( 'usces_filter_post_list_class', null, $list_index, $infolist->post_count ) . '">' . "\n";
2814 + $list .= "<div class='title'><a href='" . get_permalink( $post->ID ) . "'>" . get_the_title() . "</a></div>\n";
2815 + $list .= '<p>' . get_the_excerpt() . "</p>\n";
1581 2816 $list .= "</li>\n";
1582 - $li .= apply_filters( 'usces_filter_widget_post', $list, $post, $slug, $list_index);
2817 + $li .= apply_filters( 'usces_filter_widget_post', $list, $post, $slug, $list_index );
1583 2818 $list_index++;
1584 2819 }
1585 - wp_reset_query();
2820 + wp_reset_postdata();
1586 2821 usces_reset_filter();
1587 - if( NULL != $widget_id && $infolist->have_posts() ){
2822 + if ( null !== $widget_id && $infolist->have_posts() ) {
1588 2823 add_filter( 'excerpt_length', 'welcart_excerpt_length' );
1589 2824 add_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' );
1590 2825 add_filter( 'excerpt_more', 'welcart_auto_excerpt_more' );
1591 2826 }
1592 - echo $li;
2827 + wel_esc_script_e( $li );
1593 2828 }
1594 2829
1595 -function usces_categories_checkbox($output=''){
1596 - global $usces;
1597 - $retcats = apply_filters('usces_search_retcats', usces_search_categories());
1598 - $parent_id = apply_filters('usces_search_categories_checkbox_parent', USCES_ITEM_CAT_PARENT_ID);
1599 - $htm = usces_get_categories_checkbox($parent_id);
1600 - $htm = apply_filters('usces_filter_categories_checkbox', $htm, $parent_id);
1601 -
1602 - if($output == '' || $output == 'echo')
1603 - echo $htm;
1604 - else
1605 - return $htm;
2830 +/**
2831 + * Category checkbox
2832 + *
2833 + * @param string $output Return value or echo.
2834 + * @return string|void
2835 + */
2836 +function usces_categories_checkbox( $output = '' ) {
2837 +
2838 + $retcats = apply_filters( 'usces_search_retcats', usces_search_categories() );
2839 + $parent_id = apply_filters( 'usces_search_categories_checkbox_parent', USCES_ITEM_CAT_PARENT_ID );
2840 + $htm = usces_get_categories_checkbox( $parent_id );
2841 + $htm = apply_filters( 'usces_filter_categories_checkbox', $htm, $parent_id );
2842 +
2843 + if ( '' === $output || 'echo' === $output ) {
2844 + wel_esc_script_e( $htm );
2845 + } else {
2846 + return wel_esc_script( $htm );
2847 + }
1606 2848 }
1607 2849
1608 -function usces_get_categories_checkbox($parent_id){
2850 +/**
2851 + * Category checkbox
2852 + *
2853 + * @param int $parent_id Parent category ID.
2854 + */
2855 +function usces_get_categories_checkbox( $parent_id ) {
1609 2856 global $usces;
1610 - $htm = '';
1611 - $retcats = usces_search_categories();
1612 - $parent_cat = get_category($parent_id);
1613 - $categories = get_categories('parent='.$parent_id . "&hide_empty=0&orderby=" . $usces->options['fukugo_category_orderby'] . "&order=" . $usces->options['fukugo_category_order']);
1614 - $htm .= "<fieldset class='catfield-" . $parent_cat->term_id . "'><legend>" . $parent_cat->cat_name . "</legend><ul>\n";
1615 - foreach ($categories as $cat) {
1616 - $children = get_categories('parent='.$cat->term_id . "&hide_empty=0");
1617 - if( 0 === count($children) ){
1618 - $checked = in_array($cat->term_id, $retcats) ? " checked='checked'" : "";
1619 - $htm .= "<li><input name='category[".$cat->term_id."]' type='checkbox' id='category[".$cat->term_id."]' value='".$cat->term_id."'".$checked." /><label for='category[".$cat->term_id."]' class='catlabel-" . $cat->term_id . "'>".esc_html($cat->cat_name)."</label></li>\n";
2857 +
2858 + $htm = '';
2859 + $retcats = usces_search_categories();
2860 + $parent_cat = get_category( $parent_id );
2861 + $categories = get_categories( 'parent=' . $parent_id . '&hide_empty=0&orderby=' . $usces->options['fukugo_category_orderby'] . '&order=' . $usces->options['fukugo_category_order'] );
2862 + $htm .= '<fieldset class="catfield-' . $parent_cat->term_id . '"><legend>' . $parent_cat->cat_name . "</legend><ul>\n";
2863 + foreach ( $categories as $cat ) {
2864 + $children = get_categories( 'parent=' . $cat->term_id . '&hide_empty=0' );
2865 + if ( 0 === count( $children ) ) {
2866 + $checked = in_array( $cat->term_id, $retcats ) ? ' checked="checked"' : '';
2867 + $htm .= '<li><input name="category[' . $cat->term_id . ']" type="checkbox" id="category[' . $cat->term_id . ']" value="' . $cat->term_id . '"' . $checked . ' /><label for="category[' . $cat->term_id . ']" class="catlabel-' . $cat->term_id . '">' . esc_html( $cat->cat_name ) . "</label></li>\n";
1620 2868 }
1621 2869 }
1622 2870 $htm .= "</ul>\n";
1623 - foreach ($categories as $cat) {
1624 - $children = get_categories('parent='.$cat->term_id . "&hide_empty=0");
1625 - if( 0 < count($children) ){
1626 - $htm .= usces_get_categories_checkbox($cat->term_id);
2871 + foreach ( $categories as $cat ) {
2872 + $children = get_categories( 'parent=' . $cat->term_id . '&hide_empty=0' );
2873 + if ( 0 < count( $children ) ) {
2874 + $htm .= usces_get_categories_checkbox( $cat->term_id );
1627 2875 }
1628 2876 }
1629 2877 $htm .= "</fieldset>\n";
1630 2878
@@ -1630,316 +2878,375 @@
1630 2878
1631 2879 return $htm;
1632 2880 }
1633 2881
1634 -function usces_search_categories(){
2882 +/**
2883 + * Search categories
2884 + *
2885 + * @return array
2886 + */
2887 +function usces_search_categories() {
1635 2888 $cats = array();
1636 - //if(isset($_POST['category']))
1637 - // $cats = $_POST['category'];
1638 - if(isset($_REQUEST['category']))
1639 - $cats = $_REQUEST['category'];
1640 - else
2889 + if ( isset( $_REQUEST['category'] ) ) {
2890 + $cats = wp_unslash( $_REQUEST['category'] );
2891 + } else {
1641 2892 $cats[] = USCES_ITEM_CAT_PARENT_ID;
1642 - sort($cats);
2893 + }
2894 + sort( $cats );
1643 2895 return $cats;
1644 2896 }
1645 2897
1646 -function usces_delivery_method_name( $id, $out = '' ){
2898 +/**
2899 + * Delivery method name
2900 + *
2901 + * @param int $id Delivery ID.
2902 + * @param string $out Return value or echo.
2903 + * @return string|void
2904 + */
2905 +function usces_delivery_method_name( $id, $out = '' ) {
1647 2906 global $usces;
1648 -
1649 - if($id > -1){
1650 - $id =$usces->get_delivery_method_index($id);
1651 - $name = $usces->options['delivery_method'][$id]['name'];
1652 - }else{
1653 - $name = __('No preference','usces');
2907 +
2908 + $id = $usces->get_delivery_method_index( $id );
2909 + if ( $id > -1 ) {
2910 + $name = $usces->options['delivery_method'][ $id ]['name'];
2911 + } else {
2912 + $name = __( 'No preference', 'usces' );
1654 2913 }
1655 -
1656 - if($out == 'return'){
2914 +
2915 + if ( 'return' === $out ) {
1657 2916 return $name;
1658 - }else{
1659 - echo esc_html($name);
2917 + } else {
2918 + echo esc_html( $name );
1660 2919 }
1661 2920 }
1662 2921
1663 -function usces_is_membersystem_state(){
2922 +/**
2923 + * Use membership system
2924 + *
2925 + * @return bool
2926 + */
2927 +function usces_is_membersystem_state() {
1664 2928 global $usces;
1665 2929
1666 - if($usces->options['membersystem_state'] == 'activate') {
2930 + if ( 'activate' === $usces->options['membersystem_state'] ) {
1667 2931 return true;
1668 - }else{
2932 + } else {
1669 2933 return false;
1670 2934 }
1671 2935 }
1672 2936
1673 -function usces_is_membersystem_point(){
2937 +/**
2938 + * Use membership point
2939 + *
2940 + * @return bool
2941 + */
2942 +function usces_is_membersystem_point() {
1674 2943 global $usces;
1675 2944
1676 - if($usces->options['membersystem_point'] == 'activate') {
2945 + if ( 'activate' === $usces->options['membersystem_point'] ) {
1677 2946 return true;
1678 - }else{
2947 + } else {
1679 2948 return false;
1680 2949 }
1681 2950 }
1682 2951
1683 -function usces_copyright(){
2952 +/**
2953 + * Copyright
2954 + */
2955 +function usces_copyright() {
1684 2956 global $usces;
1685 -
1686 - echo esc_html($usces->options['copyright']);
2957 + echo esc_html( $usces->options['copyright'] );
1687 2958 }
1688 2959
1689 -function usces_totalprice_in_cart(){
2960 +/**
2961 + * Total amount in cart
2962 + */
2963 +function usces_totalprice_in_cart() {
1690 2964 global $usces;
1691 -
1692 - echo number_format($usces->get_total_price());
2965 + echo number_format( $usces->get_total_price() );
1693 2966 }
1694 2967
1695 -function usces_totalquantity_in_cart(){
2968 +/**
2969 + * Total quantities in cart
2970 + */
2971 +function usces_totalquantity_in_cart() {
1696 2972 global $usces;
1697 -
1698 - echo number_format($usces->get_total_quantity());
2973 + echo number_format( $usces->get_total_quantity() );
1699 2974 }
1700 2975
1701 -function usces_get_page_mode(){
2976 +/**
2977 + * Page mode
2978 + *
2979 + * @return string
2980 + */
2981 +function usces_get_page_mode() {
1702 2982 global $usces;
1703 -
1704 2983 return $usces->page;
1705 2984 }
1706 2985
1707 -function usces_is_cat_of_item( $cat_id ){
2986 +/**
2987 + * Is in item category
2988 + *
2989 + * @param int $cat_id Category ID.
2990 + * @return bool
2991 + */
2992 +function usces_is_cat_of_item( $cat_id ) {
1708 2993 global $usces;
1709 - $ids = $usces->get_item_cat_ids();
2994 +
2995 + $ids = $usces->get_item_cat_ids();
1710 2996 $ids[] = USCES_ITEM_CAT_PARENT_ID;
1711 - if(in_array($cat_id, $ids)){
2997 + if ( in_array( $cat_id, $ids ) ) {
1712 2998 return true;
1713 - }else{
2999 + } else {
1714 3000 return false;
1715 3001 }
1716 3002 }
1717 3003
1718 -function usces_get_item_custom( $post_id, $type = 'list', $out = '' ){
3004 +/**
3005 + * Item custom field
3006 + *
3007 + * @param int $post_id Post ID.
3008 + * @param string $type Type.
3009 + * @param string $out Return value or echo.
3010 + * @return string|void
3011 + */
3012 +function usces_get_item_custom( $post_id, $type = 'list', $out = '' ) {
1719 3013 global $usces;
1720 - $cfields = $usces->get_post_custom($post_id);
1721 - switch( $type ){
3014 +
3015 + $cfields = wel_get_extra_data( $post_id );
3016 + $html = '';
3017 +
3018 + switch ( $type ) {
1722 3019 case 'list':
1723 3020 $list = '';
1724 - $html = '<ul class="item_custom_field">'."\n";
1725 - foreach( $cfields as $key => $value ){
1726 - if( 'wccs_' == substr($key, 0, 5) ){
1727 - $list .= '<li>' . esc_html(substr($key, 5)) . ' : ' . nl2br(esc_html($value[0])) . '</li>'."\n";
3021 + $html = '<ul class="item_custom_field">' . "\n";
3022 + foreach ( $cfields as $key => $values ) {
3023 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3024 + if ( is_array( $values ) ) {
3025 + foreach ( $values as $value ) {
3026 + $list .= '<li>' . esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $value ) ) . '</li>' . "\n";
3027 + }
3028 + } else {
3029 + $list .= '<li>' . esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $values ) ) . '</li>' . "\n";
3030 + }
1728 3031 }
1729 3032 }
1730 - if(empty($list)){
3033 + if ( empty( $list ) ) {
1731 3034 $html = '';
1732 - }else{
1733 - $html .= $list . '</ul>'."\n";
3035 + } else {
3036 + $html .= $list . '</ul>' . "\n";
1734 3037 }
1735 3038 break;
1736 3039
1737 3040 case 'table':
1738 3041 $list = '';
1739 - $html = '<table class="item_custom_field">'."\n";
1740 - foreach($cfields as $key => $value){
1741 - if( 'wccs_' == substr($key, 0, 5) ){
1742 - $list .= '<tr><th>' . esc_html(substr($key, 5)) . '</th><td>' . nl2br(esc_html($value[0])) . '</td></tr>'."\n";
3042 + $html = '<table class="item_custom_field">' . "\n";
3043 + foreach ( $cfields as $key => $values ) {
3044 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3045 + if ( is_array( $values ) ) {
3046 + foreach ( $values as $value ) {
3047 + $list .= '<tr><th>' . esc_html( substr( $key, 5 ) ) . '</th><td>' . nl2br( esc_html( $value ) ) . '</td></tr>' . "\n";
3048 + }
3049 + } else {
3050 + $list .= '<tr><th>' . esc_html( substr( $key, 5 ) ) . '</th><td>' . nl2br( esc_html( $values ) ) . '</td></tr>' . "\n";
3051 + }
1743 3052 }
1744 3053 }
1745 - if(empty($list)){
3054 + if ( empty( $list ) ) {
1746 3055 $html = '';
1747 - }else{
1748 - $html .= $list . '</table>'."\n";
3056 + } else {
3057 + $html .= $list . '</table>' . "\n";
1749 3058 }
1750 3059 break;
1751 3060
1752 3061 case 'notag':
1753 3062 $list = '';
1754 - foreach($cfields as $key => $value){
1755 - if( 'wccs_' == substr($key, 0, 5) ){
1756 - $list .= esc_html(substr($key, 5)) . ' : ' . nl2br(esc_html($value[0])) . "\r\n";
3063 + foreach ( $cfields as $key => $values ) {
3064 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3065 + if ( is_array( $values ) ) {
3066 + foreach ( $values as $value ) {
3067 + $list .= esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $value ) ) . "\r\n";
3068 + }
3069 + } else {
3070 + $list .= esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $values ) ) . "\r\n";
3071 + }
1757 3072 }
1758 3073 }
1759 - if(empty($list)){
3074 + if ( empty( $list ) ) {
1760 3075 $html = '';
1761 - }else{
3076 + } else {
1762 3077 $html = $list;
1763 3078 }
1764 3079 break;
3080 +
3081 + case 'mail_html':
3082 + $list = '';
3083 + foreach ( $cfields as $key => $values ) {
3084 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3085 + if ( is_array( $values ) ) {
3086 + foreach ( $values as $value ) {
3087 + $list .= '<tr>
3088 + <td style="padding: 0 0 10px; text-align: left; width: 100px; font-weight: normal; vertical-align: text-top;">' . esc_html( substr( $key, 5 ) ) . '</td>
3089 + <td style="padding: 0 0 10px 50px; width: calc( 100% - 100px );">' . nl2br( esc_html( $value ) ) . '</td>
3090 + </tr>';
3091 + }
3092 + } else {
3093 + $list .= '<tr>
3094 + <td style="padding: 0 0 10px; text-align: left; width: 100px; font-weight: normal; vertical-align: text-top;">' . esc_html( substr( $key, 5 ) ) . '</td>
3095 + <td style="padding: 0 0 10px 50px; width: calc( 100% - 100px );">' . nl2br( esc_html( $values ) ) . '</td>
3096 + </tr>';
3097 + }
3098 + }
3099 + }
3100 + if ( empty( $list ) ) {
3101 + $html = '';
3102 + } else {
3103 + $html = '<table style="font-size: 14px; width: 100%; border-collapse: collapse;">';
3104 + $html .= '<tbody><tr><td style="background-color: #f9f9f9; padding: 30px;">';
3105 + $html .= '<table style="width: 100%;"><tbody>';
3106 + $html .= $list;
3107 + $html .= '</tbody></table></td></tr></tbody></table>';
3108 + }
3109 + break;
1765 3110 }
1766 3111 $html = apply_filters( 'usces_filter_item_custom', $html, $post_id, $type );
1767 -
1768 - if( 'return' == $out){
3112 +
3113 + if ( 'return' === $out ) {
1769 3114 return $html;
1770 - }else{
1771 - echo $html;
3115 + } else {
3116 + echo $html; // no escape due to filter.
1772 3117 }
1773 3118 }
1774 3119
1775 -function usces_settle_info_field( $order_id, $type='nl', $out='echo' ){
3120 +/**
3121 + * Settlement information
3122 + *
3123 + * @param int $order_id Order ID.
3124 + * @param string $type Type.
3125 + * @param string $out Return value or echo.
3126 + * @return string|void
3127 + */
3128 +function usces_settle_info_field( $order_id, $type = 'nl', $out = 'echo' ) {
1776 3129 global $usces;
1777 - $str = '';
3130 +
3131 + $str = '';
1778 3132 $fields = $usces->get_settle_info_field( $order_id );
1779 -//20101018ysk start
1780 - $acting = isset($fields['acting']) ? $fields['acting'] : '';
1781 - foreach($fields as $key => $value){
1782 -//20101018ysk end
1783 - $keys = array(
1784 - 'acting','order_no','tracking_no','status','error_message','money',
1785 - 'pay_cvs', 'pay_no1', 'pay_no2', 'pay_limit', 'error_code',
1786 - 'settlement_id','RECDATE','JOB_ID','S_TORIHIKI_NO','TOTAL','CENDATE',
1787 - 'gid', 'rst', 'ap', 'ec', 'god', 'ta', 'cv', 'no', 'cu', 'mf', 'nk', 'nkd', 'bank', 'exp',
1788 - 'order_number',
1789 - 'res_tracking_id', 'res_payment_date', 'res_payinfo_key',
1790 - 'SID', 'DATE', 'TIME', 'CVS', 'SHNO', 'FURL', 'settltment_status', 'settltment_errmsg',
1791 - 'stran', 'mbtran', 'bktrans', 'tranid', 'TransactionId',
1792 - 'mStatus', 'vResultCode', 'orderId', 'cvsType', 'receiptNo', 'receiptDate', 'rcvAmount'
1793 - );
1794 - $keys = apply_filters( 'usces_filter_settle_info_field_keys', $keys );
1795 - if( !in_array($key, $keys) ) {
3133 + $acting = isset( $fields['acting'] ) ? $fields['acting'] : '';
3134 + $keys = array(
3135 + 'acting',
3136 + 'order_no',
3137 + 'tracking_no',
3138 + 'status',
3139 + 'error_message',
3140 + 'money',
3141 + 'pay_cvs',
3142 + 'pay_no1',
3143 + 'pay_no2',
3144 + 'pay_limit',
3145 + 'error_code',
3146 + 'settlement_id',
3147 + 'RECDATE',
3148 + 'JOB_ID',
3149 + 'S_TORIHIKI_NO',
3150 + 'TOTAL',
3151 + 'CENDATE',
3152 + 'gid',
3153 + 'rst',
3154 + 'ap',
3155 + 'ec',
3156 + 'god',
3157 + 'ta',
3158 + 'cv',
3159 + 'no',
3160 + 'cu',
3161 + 'mf',
3162 + 'nk',
3163 + 'nkd',
3164 + 'bank',
3165 + 'exp',
3166 + 'txn_id',
3167 + 'order_number',
3168 + 'res_tracking_id',
3169 + 'res_payment_date',
3170 + 'res_payinfo_key',
3171 + 'settltment_status',
3172 + 'settltment_errmsg',
3173 + 'stran',
3174 + 'mbtran',
3175 + 'bktrans',
3176 + 'tranid',
3177 + 'TransactionId',
3178 + 'mStatus',
3179 + 'vResultCode',
3180 + 'orderId',
3181 + 'cvsType',
3182 + 'receiptNo',
3183 + 'receiptDate',
3184 + 'rcvAmount',
3185 + 'trading_id',
3186 + 'payment_type',
3187 + 'seq_payment_id',
3188 + 'sendpoint',
3189 + 'option',
3190 + 'LINK_KEY',
3191 + );
3192 + $keys = apply_filters( 'usces_filter_settle_info_field_keys', $keys, $fields );
3193 + foreach ( $fields as $key => $value ) {
3194 + if ( ! in_array( $key, $keys, true ) ) {
1796 3195 continue;
1797 3196 }
1798 3197
1799 - switch($acting){
1800 - case 'zeus_bank':
1801 - if( 'status' == $key){
1802 - if( '01' === $value ){
1803 - $value = '受付中';
1804 - }elseif( '02' === $value ){
1805 - $value = '未入金';
1806 - }elseif( '03' === $value ){
1807 - $value = '入金済';
1808 - }elseif( '04' === $value ){
1809 - $value = 'エラー';
1810 - }elseif( '05' === $value ){
1811 - $value = '入金失敗';
1812 - }
1813 - }elseif( 'error_message' == $key){
1814 - if( '0002' === $value ){
1815 - $value = '入金不足';
1816 - }elseif( '0003' === $value ){
1817 - $value = '過剰入金';
1818 - }
3198 + if ( 'jpayment_conv' === $acting ) {
3199 + if ( 'rst' === $key ) {
3200 + if ( '1' === $value ) {
3201 + $value = 'OK';
3202 + } elseif ( '2' === $value ) {
3203 + $value = 'NG';
1819 3204 }
1820 - break;
1821 - case 'zeus_conv':
1822 - if( 'pay_cvs' == $key){
1823 - if( 'D001' === $value ){
1824 - $value = 'セブンイレブン';
1825 - }elseif( 'D002' === $value ){
1826 - $value = 'ローソン';
1827 - }elseif( 'D030' === $value ){
1828 - $value = 'ファミリーマート';
1829 - }elseif( 'D040' === $value ){
1830 - $value = 'サークルKサンクス';
1831 - }elseif( 'D015' === $value ){
1832 - $value = 'セイコーマート';
1833 - }elseif( 'D050' === $value ){
1834 - $value = 'ミニストップ';
1835 - }elseif( 'D060' === $value ){
1836 - $value = 'デイリーヤマザキ';
1837 - }
1838 - }elseif( 'status' == $key){
1839 - if( '01' === $value ){
1840 - $value = '未入金';
1841 - }elseif( '02' === $value ){
1842 - $value = '申込エラー';
1843 - }elseif( '03' === $value ){
1844 - $value = '期日切';
1845 - }elseif( '04' === $value ){
1846 - $value = '入金済';
1847 - }elseif( '05' === $value ){
1848 - $value = '売上確定';
1849 - }elseif( '06' === $value ){
1850 - $value = '入金取消';
1851 - }elseif( '11' === $value ){
1852 - $value = 'キャンセル後入金';
1853 - }elseif( '12' === $value ){
1854 - $value = 'キャンセル後売上';
1855 - }elseif( '13' === $value ){
1856 - $value = 'キャンセル後取消';
1857 - }
1858 - }elseif( 'pay_limit' == $key){
1859 - $value = substr($value, 0, 4).'年' . substr($value, 4, 2).'月' . substr($value, 6, 2).'日';
3205 + } elseif ( 'ap' === $key ) {
3206 + if ( 'CPL_PRE' === $value ) {
3207 + $value = 'コンビニペーパーレス決済識別コード';
3208 + } elseif ( 'CPL' === $value ) {
3209 + $value = '入金確定';
3210 + } elseif ( 'CVS_CAN' === $value ) {
3211 + $value = '入金取消';
1860 3212 }
1861 - break;
1862 -//20101018ysk start
1863 - case 'jpayment_conv':
1864 - switch($key) {
1865 - case 'rst':
1866 - switch($value) {
1867 - case '1':
1868 - $value = 'OK'; break;
1869 - case '2':
1870 - $value = 'NG'; break;
1871 - }
1872 - break;
1873 - case 'ap':
1874 - switch($value) {
1875 - case 'CPL_PRE':
1876 - $value = 'コンビニペーパーレス決済識別コード'; break;
1877 - case 'CPL':
1878 - $value = '入金確定'; break;
1879 - case 'CVS_CAN':
1880 - $value = '入金取消'; break;
1881 - }
1882 - break;
1883 - case 'cv':
1884 - $value = esc_html(usces_get_conv_name($value));
1885 - break;
1886 - case 'mf':
1887 - case 'nk':
1888 - case 'nkd':
1889 - case 'bank':
1890 - case 'exp':
1891 - continue;
1892 - break;
3213 + } elseif ( 'cv' === $key ) {
3214 + $value = esc_html( usces_get_conv_name( $value ) );
3215 + } else {
3216 + continue;
3217 + }
3218 + } elseif ( 'jpayment_bank' === $acting ) {
3219 + if ( 'rst' === $key ) {
3220 + if ( '1' === $value ) {
3221 + $value = 'OK';
3222 + } elseif ( '2' === $value ) {
3223 + $value = 'NG';
1893 3224 }
1894 - break;
1895 -
1896 - case 'jpayment_bank':
1897 - switch($key) {
1898 - case 'rst':
1899 - switch($value) {
1900 - case '1':
1901 - $value = 'OK'; break;
1902 - case '2':
1903 - $value = 'NG'; break;
1904 - }
1905 - break;
1906 - case 'ap':
1907 - switch($value) {
1908 - case 'BANK':
1909 - $value = '受付完了'; break;
1910 - case 'BAN_SAL':
1911 - $value = '入金完了'; break;
1912 - }
1913 - break;
1914 - case 'mf':
1915 - switch($value) {
1916 - case '1':
1917 - $value = 'マッチ'; break;
1918 - case '2':
1919 - $value = '過少'; break;
1920 - case '3':
1921 - $value = '過剰'; break;
1922 - }
1923 - break;
1924 - case 'nkd':
1925 - $value = substr($value, 0, 4).'年'.substr($value, 4, 2).'月'.substr($value, 6, 2).'日';
1926 - break;
1927 - case 'exp':
1928 - $value = substr($value, 0, 4).'年'.substr($value, 4, 2).'月'.substr($value, 6, 2).'日';
1929 - break;
1930 - case 'cv':
1931 - case 'no':
1932 - case 'cu':
1933 - continue;
1934 - break;
3225 + } elseif ( 'ap' === $key ) {
3226 + if ( 'BANK' === $value ) {
3227 + $value = '受付完了';
3228 + } elseif ( 'BAN_SAL' === $value ) {
3229 + $value = '入金完了';
1935 3230 }
1936 - break;
1937 -//20101018ysk end
1938 -//20140206ysk start
1939 - case 'veritrans_conv':
1940 - if( 'cvsType' == $key ) {
1941 - switch( $value ) {
3231 + } elseif ( 'mf' === $key ) {
3232 + if ( '1' === $value ) {
3233 + $value = 'マッチ';
3234 + } elseif ( '2' === $value ) {
3235 + $value = '過少';
3236 + } elseif ( '3' === $value ) {
3237 + $value = '過剰';
3238 + }
3239 + } elseif ( 'nkd' === $key ) {
3240 + $value = substr( $value, 0, 4 ) . '年' . substr( $value, 4, 2 ) . '月' . substr( $value, 6, 2 ) . '日';
3241 + } elseif ( 'exp' === $key ) {
3242 + $value = substr( $value, 0, 4 ) . '年' . substr( $value, 4, 2 ) . '月' . substr( $value, 6, 2 ) . '日';
3243 + } else {
3244 + continue;
3245 + }
3246 + } elseif ( 'veritrans_conv' === $acting ) {
3247 + if ( 'cvsType' === $key ) {
3248 + switch ( $value ) {
1942 3249 case 'sej':
1943 3250 $value = 'セブン-イレブン';
1944 3251 break;
1945 3252 case 'econ-lw':
@@ -1953,194 +3260,222 @@
1953 3260 break;
1954 3261 case 'econ-other':
1955 3262 $value = 'セイコーマート';
1956 3263 break;
1957 - }
3264 + case 'econ-sn':
3265 + $value = 'サンクス';
3266 + break;
3267 + case 'econ-ck':
3268 + $value = 'サークルK';
3269 + break;
1958 3270 }
1959 - break;
1960 -//20140206ysk end
3271 + }
1961 3272 }
1962 3273 $value = apply_filters( 'usces_filter_settle_info_field_value', $value, $key, $acting );
1963 - switch($type){
3274 + switch ( $type ) {
1964 3275 case 'nl':
1965 3276 $str .= $key . ' : ' . $value . "<br />\n";
1966 3277 break;
1967 -
1968 3278 case 'tr':
1969 3279 $str .= '<tr><td class="label">' . $key . '</td><td>' . $value . "</td></tr>\n";
1970 3280 break;
1971 -
1972 3281 case 'li':
1973 3282 $str .= '<li>' . $key . ' : ' . $value . "</li>\n";
1974 3283 break;
1975 3284 }
1976 3285 }
1977 - if( 'return' == $out){
1978 - return $str;
1979 - }else{
1980 - echo $str;
3286 + if ( 'return' === $out ) {
3287 + return wel_esc_script( $str );
3288 + } else {
3289 + wel_esc_script_e( $str );
1981 3290 }
1982 3291 }
1983 3292
1984 -//20100818ysk start
3293 +/**
3294 + * Custom field
3295 + *
3296 + * @param array $data Order data.
3297 + * @param string $custom_field Custom field.
3298 + * @param string $position Position.
3299 + * @param string $out Return value or echo.
3300 + * @return string|void
3301 + */
1985 3302 function usces_custom_field_input( $data, $custom_field, $position, $out = '' ) {
1986 3303
1987 3304 $html = '';
1988 - switch($custom_field) {
1989 - case 'order':
1990 - $label = 'custom_order';
1991 - $field = 'usces_custom_order_field';
1992 - break;
1993 - case 'customer':
1994 - $label = 'custom_customer';
1995 - $field = 'usces_custom_customer_field';
1996 - break;
1997 - case 'delivery':
1998 - $label = 'custom_delivery';
1999 - $field = 'usces_custom_delivery_field';
2000 - break;
2001 - case 'member':
2002 - $label = 'custom_member';
2003 - $field = 'usces_custom_member_field';
2004 - break;
2005 - default:
2006 - return;
3305 +
3306 + switch ( $custom_field ) {
3307 + case 'order':
3308 + $label = 'custom_order';
3309 + $field = 'usces_custom_order_field';
3310 + break;
3311 + case 'customer':
3312 + $label = 'custom_customer';
3313 + $field = 'usces_custom_customer_field';
3314 + break;
3315 + case 'delivery':
3316 + $label = 'custom_delivery';
3317 + $field = 'usces_custom_delivery_field';
3318 + break;
3319 + case 'member':
3320 + $label = 'custom_member';
3321 + $field = 'usces_custom_member_field';
3322 + break;
3323 + default:
3324 + return;
2007 3325 }
2008 3326
2009 - $meta = usces_has_custom_field_meta($custom_field);
3327 + $meta = usces_has_custom_field_meta( $custom_field );
2010 3328
2011 - if(!empty($meta) and is_array($meta)) {
2012 - foreach($meta as $key => $entry) {
2013 - if($custom_field == 'order' or $entry['position'] == $position) {
2014 - $name = $entry['name'];
2015 - $means = $entry['means'];
2016 - $essential = $entry['essential'];
2017 - $value = '';
2018 - if(is_array($entry['value'])) {
2019 - foreach($entry['value'] as $k => $v) {
2020 - $value .= $v."\n";
3329 + if ( ! empty( $meta ) && is_array( $meta ) ) {
3330 + foreach ( $meta as $key => $entry ) {
3331 + if ( 'order' === $custom_field || $entry['position'] === $position ) {
3332 + $name = $entry['name'];
3333 + $means = (int) $entry['means'];
3334 + $essential = (int) $entry['essential'];
3335 + $value = '';
3336 + if ( is_array( $entry['value'] ) ) {
3337 + foreach ( $entry['value'] as $k => $v ) {
3338 + $value .= $v . "\n";
2021 3339 }
2022 3340 }
2023 - $value = trim($value);
3341 + $value = usces_change_line_break( $value );
2024 3342
2025 - $e = ($essential == 1) ? '<em>' . __('*', 'usces') . '</em>' : '';
3343 + $e = ( 1 === $essential ) ? '<em>' . __( '*', 'usces' ) . '</em>' : '';
2026 3344 $html .= '
2027 3345 <tr class="customkey_' . $key . '">
2028 - <th scope="row">'.$e.esc_html($name).apply_filters('usces_filter_custom_field_input_label', NULL, $key, $entry).'</th>';
2029 - $html .= apply_filters( 'usces_filter_custom_field_input_td', '<td colspan="2">', $key, $entry);
2030 - switch($means) {
2031 - case 0://シングルセレクト
2032 - case 1://マルチセレクト
2033 - $selects = explode("\n", $value);
2034 - $multiple = ($means == 0) ? '' : ' multiple';
2035 - $multiple_array = ($means == 0) ? '' : '[]';
2036 - $html .= '<select name="'.$label.'['.esc_attr($key).']'.$multiple_array.'" class="iopt_select"'.$multiple.'>';
2037 - if($essential == 1)
3346 + <th scope="row">' . $e . esc_html( $name ) . apply_filters( 'usces_filter_custom_field_input_label', null, $key, $entry ) . '</th>';
3347 + $html .= apply_filters( 'usces_filter_custom_field_input_td', '<td colspan="2">', $key, $entry );
3348 + switch ( $means ) {
3349 + case 0: // Single-select.
3350 + case 1: // Multi-select.
3351 + $selects = explode( "\n", $value );
3352 + $multiple = ( 0 === $means ) ? '' : ' multiple';
3353 + $multiple_array = ( 0 === $means ) ? '' : '[]';
3354 + $html .= '<select name="' . $label . '[' . esc_attr( $key ) . ']' . $multiple_array . '" class="iopt_select"' . $multiple . '>';
3355 + if ( 1 === $essential ) {
2038 3356 $html .= '
2039 - <option value="#NONE#">'.__('Choose','usces').'</option>';
2040 - foreach($selects as $v) {
2041 - $selected = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' selected' : '';
2042 - $html .= '
2043 - <option value="'.esc_attr($v).'"'.$selected.'>'.esc_html($v).'</option>';
3357 + <option value="#NONE#">' . __( 'Choose', 'usces' ) . '</option>';
2044 3358 }
3359 + foreach ( (array) $selects as $v ) {
3360 + $selected = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' selected' : '';
3361 + $html .= '
3362 + <option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_html( $v ) . '</option>';
3363 + }
2045 3364 $html .= '
2046 3365 </select>';
2047 3366 break;
2048 - case 2://テキスト
2049 - $text = isset($data[$label][$key]) ? $data[$label][$key] : '';
2050 - $html .= '<input type="text" name="'.$label.'['.esc_attr($key).']" value="'.esc_attr($text).'" />';
3367 + case 2: // Text.
3368 + $text = isset( $data[ $label ][ $key ] ) ? $data[ $label ][ $key ] : '';
3369 + $html .= '<input type="text" name="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_text" value="' . esc_attr( $text ) . '" />';
2051 3370 break;
2052 - case 3://ラジオボタン
2053 - $selects = explode("\n", $value);
2054 - foreach($selects as $v) {
2055 - $checked = ( isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' checked' : '';
2056 - $html .= '
2057 - <label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label"><input type="radio" name="'.$label.'['.esc_attr($key).']" id="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" value="'.esc_attr($v).'"'.$checked.'>'.esc_html($v).'</label>';
3371 + case 3: // Radio-button.
3372 + $selects = explode( "\n", $value );
3373 + foreach ( (array) $selects as $v ) {
3374 + $checked = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' checked' : '';
3375 + $html .= '
3376 + <label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label"><input type="radio" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '>' . esc_html( $v ) . '</label>';
2058 3377 }
2059 3378 break;
2060 - case 4://チェックボックス
2061 - $selects = explode("\n", $value);
2062 - foreach($selects as $v) {
2063 - if( isset($data[$label][$key]) && is_array($data[$label][$key]) ) {
2064 - $checked = (isset($data[$label][$key]) && array_key_exists($v, $data[$label][$key])) ? ' checked' : '';
3379 + case 4: // Check-box.
3380 + $selects = explode( "\n", $value );
3381 + foreach ( $selects as $v ) {
3382 + if ( isset( $data[ $label ][ $key ] ) && is_array( $data[ $label ][ $key ] ) ) {
3383 + $checked = ( isset( $data[ $label ][ $key ] ) && array_key_exists( $v, $data[ $label ][ $key ] ) ) ? ' checked' : '';
2065 3384 } else {
2066 - $checked = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' checked' : '';
3385 + $checked = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' checked' : '';
2067 3386 }
2068 3387 $html .= '
2069 - <label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label"><input type="checkbox" name="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" id="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" value="'.esc_attr($v).'"'.$checked.'>'.esc_html($v).'</label>';
3388 + <label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label"><input type="checkbox" name="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '>' . esc_html( $v ) . '</label>';
2070 3389 }
2071 3390 break;
3391 + case 5: // Text-area.
3392 + $text = ( isset( $data[ $label ][ $key ] ) ) ? $data[ $label ][ $key ] : '';
3393 + $html .= '<textarea name="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_textarea">' . esc_attr( $text ) . '</textarea>';
3394 + break;
2072 3395 }
2073 - $html .= apply_filters('usces_filter_custom_field_input_value', NULL, $key, $entry).'</td>';
3396 + $html .= apply_filters( 'usces_filter_custom_field_input_value', null, $key, $entry ) . '</td>';
2074 3397 $html .= '
2075 3398 </tr>';
2076 3399 }
2077 3400 }
2078 3401 }
2079 -
2080 - $html = apply_filters('usces_filter_custom_field_input', $html, $data, $custom_field, $position);
2081 3402
2082 - if($out == 'return') {
2083 - return stripslashes($html);
3403 + $html = apply_filters( 'usces_filter_custom_field_input', $html, $data, $custom_field, $position );
3404 +
3405 + if ( 'return' === $out ) {
3406 + return stripslashes( $html );
2084 3407 } else {
2085 - echo stripslashes($html);
3408 + echo stripslashes( $html );
2086 3409 }
2087 3410 }
2088 3411
3412 +/**
3413 + * Custom field information
3414 + *
3415 + * @param array $data Order data.
3416 + * @param string $custom_field Custom field.
3417 + * @param string $position Position.
3418 + * @param string $out Return value or echo.
3419 + * @return string|void
3420 + */
2089 3421 function usces_custom_field_info( $data, $custom_field, $position, $out = '' ) {
2090 3422
2091 3423 $html = '';
2092 - switch($custom_field) {
2093 - case 'order':
2094 - $label = 'custom_order';
2095 - $field = 'usces_custom_order_field';
2096 - break;
2097 - case 'customer':
2098 - $label = 'custom_customer';
2099 - $field = 'usces_custom_customer_field';
2100 - break;
2101 - case 'delivery':
2102 - $label = 'custom_delivery';
2103 - $field = 'usces_custom_delivery_field';
2104 - break;
2105 - case 'member':
2106 - $label = 'custom_member';
2107 - $field = 'usces_custom_member_field';
2108 - break;
2109 - default:
2110 - return;
3424 + switch ( $custom_field ) {
3425 + case 'order':
3426 + $label = 'custom_order';
3427 + $field = 'usces_custom_order_field';
3428 + break;
3429 + case 'customer':
3430 + $label = 'custom_customer';
3431 + $field = 'usces_custom_customer_field';
3432 + break;
3433 + case 'delivery':
3434 + $label = 'custom_delivery';
3435 + $field = 'usces_custom_delivery_field';
3436 + break;
3437 + case 'member':
3438 + $label = 'custom_member';
3439 + $field = 'usces_custom_member_field';
3440 + break;
3441 + default:
3442 + return;
2111 3443 }
2112 3444
2113 - $meta = usces_has_custom_field_meta($custom_field);
3445 + $meta = usces_has_custom_field_meta( $custom_field );
2114 3446
2115 - if(!empty($meta) and is_array($meta)) {
2116 - foreach($meta as $key => $entry) {
2117 - if($custom_field == 'order' or $entry['position'] == $position) {
2118 - $name = $entry['name'];
2119 - $means = $entry['means'];
3447 + if ( ! empty( $meta ) && is_array( $meta ) ) {
3448 + foreach ( $meta as $key => $entry ) {
3449 + if ( 'order' === $custom_field || $entry['position'] === $position ) {
3450 + $name = $entry['name'];
3451 + $means = (int) $entry['means'];
2120 3452
2121 3453 $html .= '<tr>
2122 - <th>'.esc_html($name).'</th>
3454 + <th>' . esc_html( $name ) . '</th>
2123 3455 <td>';
2124 - if(!empty($data[$label][$key])) {
2125 - switch($means) {
2126 - case 0://シングルセレクト
2127 - case 2://テキスト
2128 - case 3://ラジオボタン
2129 - $html .= esc_html($data[$label][$key]);
2130 - break;
2131 - case 1://マルチセレクト
2132 - case 4://チェックボックス
2133 - if(is_array($data[$label][$key])) {
2134 - $c = '';
2135 - foreach($data[$label][$key] as $v) {
2136 - $html .= $c.esc_html($v);
2137 - $c = ', ';
3456 + if ( ! empty( $data[ $label ][ $key ] ) ) {
3457 + switch ( $means ) {
3458 + case 0: // Single-select.
3459 + case 2: // Text.
3460 + case 3: // Radio-button.
3461 + case 5: // Text-area.
3462 + $html .= esc_html( $data[ $label ][ $key ] );
3463 + break;
3464 + case 1: // Multi-select.
3465 + case 4: // Check-box.
3466 + if ( is_array( $data[ $label ][ $key ] ) ) {
3467 + $c = '';
3468 + foreach ( $data[ $label ][ $key ] as $v ) {
3469 + $html .= $c . esc_html( $v );
3470 + $c = ', ';
3471 + }
3472 + } else {
3473 + if ( ! empty( $data[ $label ][ $key ] ) ) {
3474 + $html .= esc_html( $data[ $label ][ $key ] );
3475 + }
2138 3476 }
2139 - } else {
2140 - if(!empty($data[$label][$key])) $html .= esc_html($data[$label][$key]);
2141 - }
2142 - break;
3477 + break;
2143 3478 }
2144 3479 }
2145 3480 $html .= '
2146 3481 </td>
@@ -2148,151 +3483,173 @@
2148 3483 }
2149 3484 }
2150 3485 }
2151 3486
2152 - $html = apply_filters('usces_filter_custom_field_info', $html, $data, $custom_field, $position);
3487 + $html = apply_filters( 'usces_filter_custom_field_info', $html, $data, $custom_field, $position );
2153 3488
2154 - if($out == 'return') {
2155 - return stripslashes($html);
3489 + if ( 'return' === $out ) {
3490 + return stripslashes( $html );
2156 3491 } else {
2157 - echo stripslashes($html);
3492 + echo stripslashes( $html );
2158 3493 }
2159 3494 }
2160 3495
3496 +/**
3497 + * Admin Custom field
3498 + *
3499 + * @param array $meta Order meta data.
3500 + * @param string $custom_field Custom field.
3501 + * @param string $position Position.
3502 + * @param string $out Return value or echo.
3503 + * @return string|void
3504 + */
2161 3505 function usces_admin_custom_field_input( $meta, $custom_field, $position, $out = '' ) {
2162 3506
2163 3507 $html = '';
2164 - switch($custom_field) {
2165 - case 'order':
2166 - $label = 'custom_order';
2167 - $class = '';
2168 - break;
2169 - case 'customer':
2170 - $label = 'custom_customer';
2171 - $class = ' class="col2"';
2172 - break;
2173 - case 'delivery':
2174 - $label = 'custom_delivery';
2175 - $class = ' class="col3"';
2176 - break;
2177 - case 'member':
2178 - $label = 'custom_member';
2179 - $class = '';
2180 - break;
2181 - default:
2182 - return;
3508 + switch ( $custom_field ) {
3509 + case 'order':
3510 + $label = 'custom_order';
3511 + $class = '';
3512 + break;
3513 + case 'customer':
3514 + $label = 'custom_customer';
3515 + $class = ' class="col2"';
3516 + break;
3517 + case 'delivery':
3518 + $label = 'custom_delivery';
3519 + $class = ' class="col3"';
3520 + break;
3521 + case 'member':
3522 + $label = 'custom_member';
3523 + $class = '';
3524 + break;
3525 + case 'admin_member':
3526 + $label = 'admin_custom_member';
3527 + $class = '';
3528 + break;
3529 + default:
3530 + return;
2183 3531 }
2184 3532
2185 -
2186 - if(!empty($meta) and is_array($meta)) {
2187 - foreach($meta as $key => $entry) {
2188 - if($custom_field == 'order' or $entry['position'] == $position) {
2189 - $name = $entry['name'];
2190 - $means = $entry['means'];
2191 - $essential = $entry['essential'];
2192 - $value = '';
2193 - if(is_array($entry['value'])) {
2194 - foreach($entry['value'] as $k => $v) {
2195 - $value .= $v."\n";
3533 + if ( ! empty( $meta ) && is_array( $meta ) ) {
3534 + foreach ( $meta as $key => $entry ) {
3535 + if ( 'order' === $custom_field || $entry['position'] === $position ) {
3536 + $name = $entry['name'];
3537 + $means = (int) $entry['means'];
3538 + $essential = (int) $entry['essential'];
3539 + $value = '';
3540 + if ( is_array( $entry['value'] ) ) {
3541 + foreach ( $entry['value'] as $k => $v ) {
3542 + $value .= $v . "\n";
2196 3543 }
2197 3544 }
2198 - $value = trim($value);
2199 - $data = $entry['data'];
3545 + $value = usces_change_line_break( $value );
3546 + $value = apply_filters( 'usces_filter_admin_custom_field_input_value', $value, $key, $entry, $custom_field );
3547 + $data = ( isset( $entry['data'] ) ) ? $entry['data'] : null;
2200 3548
2201 3549 $html .= '
2202 3550 <tr>
2203 - <td class="label">'.esc_html($name).'</td>';
2204 - switch($means) {
2205 - case 0://シングルセレクト
2206 - case 1://マルチセレクト
2207 - $selects = explode("\n", $value);
2208 - $multiple = ($means == 0) ? '' : ' multiple';
2209 - $multiple_array = ($means == 0) ? '' : '[]';
2210 - $html .= '
2211 - <td'.$class.'>
2212 - <select name="'.$label.'['.esc_attr($key).']'.$multiple_array.'" id="'.$label.'['.esc_attr($key).']" class="iopt_select"'.$multiple.'>';
2213 - if($essential == 1)
3551 + <td class="label">' . esc_html( $name ) . '</td>';
3552 + switch ( $means ) {
3553 + case 0: /* Single-select */
3554 + case 1: /* Multi-select */
3555 + $selects = explode( "\n", $value );
3556 + $multiple = ( 0 === $means ) ? '' : ' multiple';
3557 + $multiple_array = ( 0 === $means ) ? '' : '[]';
3558 + $html .= '
3559 + <td' . $class . '>
3560 + <select name="' . $label . '[' . esc_attr( $key ) . ']' . $multiple_array . '" id="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_select"' . $multiple . '>';
3561 + if ( 1 === $essential ) {
3562 + $html .= '
3563 + <option value="#NONE#">' . __( 'Choose', 'usces' ) . '</option>';
3564 + }
3565 + foreach ( $selects as $v ) {
3566 + $selected = ( $data == $v ) ? ' selected' : '';
3567 + $html .= '
3568 + <option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_html( $v ) . '</option>';
3569 + }
2214 3570 $html .= '
2215 - <option value="#NONE#">'.__('Choose','usces').'</option>';
2216 - foreach($selects as $v) {
2217 - $selected = ($data == $v) ? ' selected' : '';
3571 + </select></td>';
3572 + break;
3573 + case 2: /* Text */
2218 3574 $html .= '
2219 - <option value="'.esc_attr($v).'"'.$selected.'>'.esc_html($v).'</option>';
2220 - }
2221 - $html .= '
2222 - </select></td>';
2223 - break;
2224 - case 2://テキスト
2225 - $html .= '
2226 - <td'.$class.'><input type="text" name="'.$label.'['.esc_attr($key).']" id="'.$label.'['.esc_attr($key).']" size="30" value="'.esc_attr($data).'" /></td>';
2227 - break;
2228 - case 3://ラジオボタン
2229 - $selects = explode("\n", $value);
2230 - $html .= '
2231 - <td'.$class.'>';
2232 - foreach($selects as $v) {
2233 - $checked = ($data == $v) ? ' checked' : '';
3575 + <td' . $class . '><input type="text" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . ']" size="30" value="' . esc_attr( $data ) . '" /></td>';
3576 + break;
3577 + case 3: /* Radio-button */
3578 + $selects = explode( "\n", $value );
3579 + $html .= '
3580 + <td' . $class . '>';
3581 + foreach ( $selects as $v ) {
3582 + $checked = ( $data == $v ) ? ' checked' : '';
3583 + $html .= '
3584 + <input type="radio" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '><label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label">' . esc_html( $v ) . '</label>';
3585 + }
2234 3586 $html .= '
2235 - <input type="radio" name="'.$label.'['.esc_attr($key).']" value="'.esc_attr($v).'"'.$checked.'><label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label">'.esc_html($v).'</label>';
2236 - }
2237 - $html .= '
2238 - </td>';
2239 - break;
2240 - case 4://チェックボックス
2241 - $selects = explode("\n", $value);
2242 - $html .= '
2243 - <td'.$class.'>';
2244 - foreach($selects as $v) {
2245 - if(is_array($data)) {
2246 - $checked = (array_key_exists($v, $data)) ? ' checked' : '';
2247 - } else {
2248 - $checked = ($data == $v) ? ' checked' : '';
3587 + </td>';
3588 + break;
3589 + case 4: /* Check-box */
3590 + $selects = explode( "\n", $value );
3591 + $html .= '
3592 + <td' . $class . '>';
3593 + foreach ( $selects as $v ) {
3594 + if ( is_array( $data ) ) {
3595 + $checked = ( array_key_exists( $v, $data ) ) ? ' checked' : '';
3596 + } else {
3597 + $checked = ( $data == $v ) ? ' checked' : '';
3598 + }
3599 + $html .= '
3600 + <input type="checkbox" name="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '><label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label">' . esc_html( $v ) . '</label>';
2249 3601 }
2250 3602 $html .= '
2251 - <input type="checkbox" name="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" value="'.esc_attr($v).'"'.$checked.'><label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label">'.esc_html($v).'</label>';
2252 - }
2253 - $html .= '
2254 - </td>';
2255 - break;
3603 + </td>';
3604 + break;
3605 + case 5: /* Text-area */
3606 + $html .= '
3607 + <td' . $class . '><textarea name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . ']" >' . esc_attr( $data ) . '</textarea></td>';
3608 + break;
2256 3609 }
2257 3610 $html .= '
2258 3611 </tr>';
2259 3612 }
2260 -
2261 3613 }
2262 3614 }
2263 - $html = apply_filters( 'usces_filter_admin_custom_field_input', $html, $meta, $custom_field, $position, $out );
3615 + $html = apply_filters( 'usces_filter_admin_custom_field_input', $html, $meta, $custom_field, $position, $out );
2264 3616
2265 - if($out == 'return') {
2266 - return stripslashes($html);
3617 + if ( 'return' === $out ) {
3618 + return stripslashes( $html );
2267 3619 } else {
2268 - echo stripslashes($html);
3620 + echo stripslashes( $html );
2269 3621 }
2270 3622 }
2271 3623
3624 +/**
3625 + * Required Custom Field
3626 + *
3627 + * @return string
3628 + */
2272 3629 function has_custom_customer_field_essential() {
2273 3630
2274 - $mes = '';
3631 + $mes = '';
2275 3632 $essential = array();
2276 3633
2277 - $csmb_meta = usces_has_custom_field_meta('member');
2278 - if(!empty($csmb_meta) and is_array($csmb_meta)) {
2279 - foreach($csmb_meta as $key => $entry) {
2280 - if($entry['essential'] == 1) {
2281 - $essential[$key] = $key;
3634 + $csmb_meta = usces_has_custom_field_meta( 'member' );
3635 + if ( ! empty( $csmb_meta ) && is_array( $csmb_meta ) ) {
3636 + foreach ( $csmb_meta as $key => $entry ) {
3637 + if ( 1 === (int) $entry['essential'] ) {
3638 + $essential[ $key ] = $key;
2282 3639 }
2283 3640 }
2284 3641 }
2285 - if(!empty($essential)) {
2286 - $cscs_meta = usces_has_custom_field_meta('customer');
2287 - if(!empty($cscs_meta) and is_array($cscs_meta)) {
2288 - foreach($cscs_meta as $key => $entry) {
2289 - if($entry['essential'] == 1) {
2290 - if(!array_key_exists($key, $essential)) {
2291 - if($entry['means'] == 2) {//Text
2292 - $mes .= sprintf(__("Input the %s", 'usces'), esc_html($entry['name']))."<br />";
3642 + if ( ! empty( $essential ) ) {
3643 + $cscs_meta = usces_has_custom_field_meta( 'customer' );
3644 + if ( ! empty( $cscs_meta ) && is_array( $cscs_meta ) ) {
3645 + foreach ( $cscs_meta as $key => $entry ) {
3646 + if ( 1 === (int) $entry['essential'] ) {
3647 + if ( ! array_key_exists( $key, $essential ) ) {
3648 + if ( 2 === (int) $entry['means'] ) { // Text.
3649 + $mes .= sprintf( __( "Input the %s", 'usces' ), esc_html( $entry['name'] ) ) . '<br />';
2293 3650 } else {
2294 - $mes .= sprintf(__("Chose the %s", 'usces'), esc_html($entry['name']))."<br />";
3651 + $mes .= sprintf( __( "Chose the %s", 'usces' ), esc_html( $entry['name'] ) ) . '<br />';
2295 3652 }
2296 3653 }
2297 3654 }
2298 3655 }
@@ -2299,970 +3656,1713 @@
2299 3656 }
2300 3657 }
2301 3658 return $mes;
2302 3659 }
2303 -//20100818ysk end
2304 3660
2305 -function usces_order_discount( $out = '' ){
3661 +/**
3662 + * Discount
3663 + *
3664 + * @param string $out Return value or echo.
3665 + * @return string|void
3666 + */
3667 +function usces_order_discount( $out = '' ) {
2306 3668 global $usces;
2307 - $res = abs($usces->get_order_discount());
2308 -
2309 - if($out == 'return') {
3669 +
3670 + $res = abs( $usces->get_order_discount() );
3671 +
3672 + if ( 'return' === $out ) {
2310 3673 return $res;
2311 3674 } else {
2312 - echo number_format($res);
3675 + echo number_format( $res );
2313 3676 }
2314 3677 }
2315 3678
2316 -function usces_item_discount( $out = '', $post_id = '', $sku = '' ){
3679 +/**
3680 + * Item discount
3681 + *
3682 + * @param string $out Return value or echo.
3683 + * @param int $post_id Post ID.
3684 + * @param string $sku SKU code.
3685 + * @return string|void
3686 + */
3687 +function usces_item_discount( $out = '', $post_id = '', $sku = '' ) {
2317 3688 global $usces, $post;
2318 -
2319 - if( '' == $post_id )
3689 +
3690 + if ( '' === $post_id ) {
2320 3691 $post_id = $post->ID;
2321 - if( '' == $sku )
3692 + }
3693 + if ( '' === $sku ) {
2322 3694 $sku = $usces->itemsku['code'];
2323 -
2324 - $res = $usces->getItemDiscount($post_id, $sku);
2325 -
2326 - if($out == 'return') {
3695 + }
3696 + $res = $usces->getItemDiscount( $post_id, $sku );
3697 +
3698 + if ( 'return' === $out ) {
2327 3699 return $res;
2328 3700 } else {
2329 - echo number_format($res);
3701 + echo number_format( $res );
2330 3702 }
2331 3703 }
2332 3704
2333 -function usces_singleitem_error_message($post_id, $skukey, $out = ''){
2334 - if( !isset($_SESSION['usces_singleitem']['error_message'][$post_id][$skukey]) )
3705 +/**
3706 + * Item page error message
3707 + *
3708 + * @param int $post_id Post ID.
3709 + * @param string $skukey SKU code.
3710 + * @param string $out Return value or echo.
3711 + * @return string|void
3712 + */
3713 +function usces_singleitem_error_message( $post_id, $skukey, $out = '' ) {
3714 + if ( ! isset( $_SESSION['usces_singleitem']['error_message'][ $post_id ][ $skukey ] ) ) {
2335 3715 $ret = '';
2336 - else
2337 - $ret = $_SESSION['usces_singleitem']['error_message'][$post_id][$skukey];
2338 -
2339 - if($out == 'return') {
2340 - return $ret;
2341 3716 } else {
2342 - echo $ret;
3717 + $ret = $_SESSION['usces_singleitem']['error_message'][ $post_id ][ $skukey ];
2343 3718 }
3719 + if ( 'return' === $out ) {
3720 + return wel_esc_script( $ret );
3721 + } else {
3722 + wel_esc_script_e( $ret );
3723 + }
2344 3724 }
2345 3725
3726 +/**
3727 + * Amount Formatting
3728 + *
3729 + * @param float $float Price.
3730 + * @param bool $symbol_pre Forward symbol.
3731 + * @param bool $symbol_post Backward symbol.
3732 + * @param string $out Return value or echo.
3733 + * @param bool $seperator_flag Seperator.
3734 + * @return string|void
3735 + */
2346 3736 function usces_crform( $float, $symbol_pre = true, $symbol_post = true, $out = '', $seperator_flag = true ) {
2347 3737 global $usces;
2348 - $price = esc_html($usces->get_currency($float, $symbol_pre, $symbol_post, $seperator_flag ));
2349 - $res = apply_filters('usces_filter_crform', $price, $float);
2350 -
2351 - if($out == 'return'){
3738 +
3739 + $price = esc_html( $usces->get_currency( $float, $symbol_pre, $symbol_post, $seperator_flag ) );
3740 + $res = apply_filters( 'usces_filter_crform', $price, $float );
3741 +
3742 + if ( 'return' === $out ) {
2352 3743 return $res;
2353 - }else{
2354 - echo $res;
3744 + } else {
3745 + echo $res; // no escape due to filter.
2355 3746 }
2356 3747 }
2357 3748
2358 -function usces_memberinfo( $key, $out = '' ){
3749 +/**
3750 + * Member Information
3751 + *
3752 + * @param string $key Key.
3753 + * @param string $out Return value or echo.
3754 + * @return string|void
3755 + */
3756 +function usces_memberinfo( $key, $out = '' ) {
2359 3757 global $usces, $wpdb;
3758 +
2360 3759 $info = $usces->get_member();
2361 3760
2362 - if( empty($key) ) return $info;
2363 -
2364 - switch ($key){
3761 + if ( empty( $key ) ) {
3762 + return $info;
3763 + }
3764 +
3765 + switch ( $key ) {
2365 3766 case 'registered':
2366 - $res = mysql2date(__('Mj, Y', 'usces'), $info['registered']);
3767 + $res = mysql2date( __( 'Mj, Y', 'usces' ), $info['registered'] );
2367 3768 break;
2368 -//20120919ysk start 0000573
2369 3769 case 'point':
2370 - $member_table = $wpdb->prefix."usces_member";
2371 - $query = $wpdb->prepare("SELECT mem_point FROM $member_table WHERE ID = %d", $info['ID']);
2372 - $res = $wpdb->get_var( $query );
3770 + $member_table = usces_get_tablename( 'usces_member' );
3771 + $query = $wpdb->prepare( "SELECT mem_point FROM $member_table WHERE ID = %d", $info['ID'] );
3772 + $res = $wpdb->get_var( $query );
2373 3773 break;
2374 -//20120919ysk end
2375 3774 default:
2376 - $res = isset($info[$key]) ? $info[$key] : '';
3775 + $res = isset( $info[ $key ] ) ? $info[ $key ] : '';
2377 3776 }
2378 -
2379 - if($out == 'return'){
2380 - return $res;
2381 - }else{
2382 - echo esc_html($res);
2383 - }
2384 -}
2385 3777
2386 -function usces_localized_name( $Familly_name, $Given_name, $out = '' ){
2387 - global $usces_settings, $usces;
2388 -
2389 - $options = get_option('usces');
2390 - $form = $options['system']['addressform'];
2391 - if( $usces_settings['nameform'][$form] ){
2392 - $res = $Given_name . ' ' . $Familly_name;
2393 - }else{
2394 - $res = $Familly_name . ' ' . $Given_name;
2395 - }
2396 -
2397 - if($out == 'return'){
3778 + if ( 'return' === $out ) {
2398 3779 return $res;
2399 - }else{
2400 - echo esc_html($res);
3780 + } else {
3781 + echo esc_html( $res );
2401 3782 }
2402 3783 }
2403 3784
2404 -function usces_member_history( $out = '' ){
3785 +/**
3786 + * Member Purchase History
3787 + *
3788 + * @param string $out Return value or echo.
3789 + * @return string|void
3790 + */
3791 +function usces_member_history( $out = '' ) {
2405 3792 global $usces;
2406 -
2407 - $usces_members = $usces->get_member();
2408 - $usces_member_history = $usces->get_member_history($usces_members['ID']);
2409 - $colspan = usces_is_membersystem_point() ? 9 : 7;
2410 3793
2411 - $html = '<table>';
2412 - if ( !count($usces_member_history) ) {
2413 - $html .= '<tr>
2414 - <td>' . __('There is no purchase history for this moment.', 'usces') . '</td>
2415 - </tr>';
2416 - }
2417 - foreach ( $usces_member_history as $umhs ) {
2418 - $cart = $umhs['cart'];
2419 - $history_member_head = '<tr>
2420 - <th class="historyrow">' . __('Order number', 'usces') . '</th>
2421 - <th class="historyrow">' . __('Purchase date', 'usces') . '</th>
2422 - <th class="historyrow">' . __('Purchase price', 'usces') . '</th>';
2423 - if( usces_is_membersystem_point() ){
2424 - $history_member_head .= '<th class="historyrow">' . __('Used points', 'usces') . '</th>';
2425 - }
2426 - $history_member_head .= '<th class="historyrow">' . apply_filters( 'usces_member_discount_label', __('Special Price', 'usces'), $umhs['ID'] ) . '</th>
2427 - <th class="historyrow">' . __('Shipping', 'usces') . '</th>
2428 - <th class="historyrow">' . __('C.O.D', 'usces') . '</th>
2429 - <th class="historyrow">' . __('consumption tax', 'usces') . '</th>';
2430 - if( usces_is_membersystem_point() ){
2431 - $history_member_head .= '<th class="historyrow">' . __('Acquired points', 'usces') . '</th>';
2432 - }
2433 - $history_member_head .= '</tr>
2434 - <tr>
2435 - <td class="rightnum">' . usces_get_deco_order_id($umhs['ID']) . '</td>
2436 - <td class="date">' . $umhs['date'] . '</td>
2437 - <td class="rightnum">' . usces_crform(($usces->get_total_price($cart)-$umhs['usedpoint']+$umhs['discount']+$umhs['shipping_charge']+$umhs['cod_fee']+$umhs['tax']), true, false, 'return') . '</td>';
2438 - if( usces_is_membersystem_point() ){
2439 - $history_member_head .= '<td class="rightnum">' . number_format($umhs['usedpoint']) . '</td>';
2440 - }
2441 - $history_member_head .= '<td class="rightnum">' . usces_crform($umhs['discount'], true, false, 'return') . '</td>
2442 - <td class="rightnum">' . usces_crform($umhs['shipping_charge'], true, false, 'return') . '</td>
2443 - <td class="rightnum">' . usces_crform($umhs['cod_fee'], true, false, 'return') . '</td>
2444 - <td class="rightnum">' . usces_crform($umhs['tax'], true, false, 'return') . '</td>';
2445 - if( usces_is_membersystem_point() ){
2446 - $history_member_head .= '<td class="rightnum">' . number_format($umhs['getpoint']) . '</td>';
2447 - }
2448 - $history_member_head .= '</tr>';
2449 - $html .= apply_filters( 'usces_filter_history_member_head', $history_member_head, $umhs );
2450 - $html .= apply_filters('usces_filter_member_history_header', NULL, $umhs);
2451 - $html .= '<tr>
2452 - <td class="retail" colspan="' . $colspan . '">
2453 - <table id="retail_table_' . $umhs['ID'] . '" class="retail">';
2454 - $history_cart_head = '<tr>
2455 - <th scope="row" class="num">No.</th>
2456 - <th class="thumbnail">&nbsp;</th>
2457 - <th>' . __('Items', 'usces') . '</th>
2458 - <th class="price ">' . __('Unit price', 'usces') . '</th>
2459 - <th class="quantity">' . __('Quantity', 'usces') . '</th>
2460 - <th class="subtotal">' . __('Amount', 'usces') . '</th>
2461 - </tr>';
2462 - $html .= apply_filters('usces_filter_history_cart_head', $history_cart_head, $umhs);
2463 -
2464 - for($i=0; $i<count($cart); $i++) {
2465 - $cart_row = $cart[$i];
2466 - $post_id = $cart_row['post_id'];
2467 - $sku = urldecode($cart_row['sku']);
2468 - $quantity = $cart_row['quantity'];
2469 - $options = $cart_row['options'];
2470 - $itemCode = $usces->getItemCode($post_id);
2471 - $itemName = $usces->getItemName($post_id);
2472 - $cartItemName = $usces->getCartItemName($post_id, $sku);
2473 - //$skuPrice = $usces->getItemPrice($post_id, $sku);
2474 - $skuPrice = $cart_row['price'];
2475 - $pictid = (int)$usces->get_mainpictid($itemCode);
2476 - $optstr = '';
2477 - if( is_array($options) && count($options) > 0 ){
2478 - $optstr = '';
2479 - foreach($options as $key => $value){
2480 -//20110629ysk start 0000190
2481 - //f( !empty($key) )
2482 - // $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2483 - if( !empty($key) ) {
2484 - $key = urldecode($key);
2485 - if(is_array($value)) {
2486 - $c = '';
2487 - $optstr .= esc_html($key) . ' : ';
2488 - foreach($value as $v) {
2489 - $optstr .= $c.nl2br(esc_html(urldecode($v)));
2490 - $c = ', ';
3794 + $usces_members = $usces->get_member();
3795 + $history = $usces->get_member_history( $usces_members['ID'], true );
3796 + $usces_member_history = apply_filters( 'usces_filter_get_member_history', $history, $usces_members['ID'] );
3797 +
3798 + $usces_member_history_count = ( $usces_member_history && is_array( $usces_member_history ) ) ? count( $usces_member_history ) : 0;
3799 +
3800 + $html = usces_load_filter_purchase_date();
3801 + $html .= '<div class="history-area">';
3802 + if ( 0 === $usces_member_history_count ) {
3803 + $no_history_message = apply_filters( 'usces_filter_no_history_message', __( 'There is no purchase history during the period.', 'usces' ) );
3804 + $html .= '<table id="history_head"><tr>
3805 + <td>' . $no_history_message . '</td>
3806 + </tr></table>';
3807 + } else {
3808 + $management_status = apply_filters( 'usces_filter_management_status', get_option( 'usces_management_status' ) );
3809 + foreach ( $usces_member_history as $umhs ) {
3810 + $condition = $umhs['condition'];
3811 + $tax_display = ( isset( $condition['tax_display'] ) ) ? $condition['tax_display'] : usces_get_tax_display();
3812 + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : usces_get_tax_mode();
3813 + $tax_target = ( isset( $condition['tax_target'] ) ) ? $condition['tax_target'] : usces_get_tax_target();
3814 + $tax_label = ( 'exclude' === $tax_mode ) ? __( 'consumption tax', 'usces' ) : __( 'Internal tax', 'usces' );
3815 + $member_system_point = ( isset( $condition['membersystem_point'] ) && 'activate' === $condition['membersystem_point'] ) ? true : usces_is_membersystem_point();
3816 + $point_coverage = ( isset( $condition['point_coverage'] ) ) ? (int) $condition['point_coverage'] : (int) usces_point_coverage();
3817 + $cart = $umhs['cart'];
3818 + $value = $umhs['order_status'];
3819 +
3820 + $p_status = '';
3821 + if ( $usces->is_status( 'duringorder', $value ) ) {
3822 + $p_status = isset( $management_status['duringorder'] ) ? esc_html( $management_status['duringorder'] ) : '';
3823 + } elseif ( $usces->is_status( 'cancel', $value ) ) {
3824 + $p_status = isset( $management_status['cancel'] ) ? esc_html( $management_status['cancel'] ) : '';
3825 + } elseif ( $usces->is_status( 'completion', $value ) ) {
3826 + $p_status = isset( $management_status['completion'] ) ? esc_html( $management_status['completion'] ) : '';
3827 + } else {
3828 + $p_status = esc_html( __( 'new order', 'usces' ) );
3829 + }
3830 + $p_status = apply_filters( 'usces_filter_orderlist_process_status', $p_status, $value, $management_status, $umhs['ID'] );
3831 +
3832 + $r_status = '';
3833 + if ( $usces->is_status( 'noreceipt', $value ) ) {
3834 + $r_status = isset( $management_status['noreceipt'] ) ? esc_html( $management_status['noreceipt'] ) : '';
3835 + } elseif ( $usces->is_status( 'pending', $value ) ) {
3836 + $r_status = isset( $management_status['pending'] ) ? esc_html( $management_status['pending'] ) : '';
3837 + } elseif ( $usces->is_status( 'receipted', $value ) ) {
3838 + $r_status = isset( $management_status['receipted'] ) ? esc_html( $management_status['receipted'] ) : '';
3839 + }
3840 + $r_status = apply_filters( 'usces_filter_orderlist_receipt_status', $r_status, $value, $management_status, $umhs['ID'] );
3841 +
3842 + $shipping = usces_have_shipped( $cart );
3843 + $delivery_company = '';
3844 + $tracking_number = '';
3845 + $delivery_company_url = '';
3846 + if ( $shipping ) {
3847 + $tracking_number = $usces->get_order_meta_value( apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' ), $umhs['ID'] );
3848 + $delivery_company = $usces->get_order_meta_value( 'delivery_company', $umhs['ID'] );
3849 + $delivery_company_url = usces_get_delivery_company_url( $delivery_company, $tracking_number );
3850 + }
3851 +
3852 + $head_col = 4;
3853 + $history_member_head = '<table id="history_head"><thead>
3854 + <tr class="order_head_label">
3855 + <th class="historyrow order_number">' . __( 'Order number', 'usces' ) . '</th>
3856 + <th class="historyrow purchase_date">' . __( 'Purchase date', 'usces' ) . '</th>';
3857 + if ( ! empty( $p_status ) ) {
3858 + $history_member_head .= '<th class="historyrow processing_status">' . __( 'Processing status', 'usces' ) . '</th>';
3859 + $head_col++;
3860 + }
3861 + if ( ! empty( $r_status ) ) {
3862 + $history_member_head .= '<th class="historyrow transfer_statement">' . __( 'transfer statement', 'usces' ) . '</th>';
3863 + $head_col++;
3864 + }
3865 + $history_member_head .= '<th class="historyrow purchase_price">' . __( 'Purchase price', 'usces' ) . '</th>
3866 + <th class="historyrow discount">' . apply_filters( 'usces_member_discount_label', __( 'Discount', 'usces' ), $umhs['ID'] ) . '</th>';
3867 + if ( $tax_display && 'products' === $tax_target ) {
3868 + $history_member_head .= '<th class="historyrow tax">' . $tax_label . '</th>';
3869 + $head_col++;
3870 + }
3871 + if ( $member_system_point && 0 === $point_coverage ) {
3872 + $history_member_head .= '<th class="historyrow used_point">' . __( 'Used points', 'usces' ) . '</th>';
3873 + $head_col++;
3874 + }
3875 + if ( $shipping ) {
3876 + $history_member_head .= '<th class="historyrow shipping">' . __( 'Shipping', 'usces' ) . '</th>';
3877 + $head_col++;
3878 + }
3879 + if ( ! empty( $umhs['cod_fee'] ) ) {
3880 + $payment = usces_get_payments_by_name( $umhs['payment_name'] );
3881 + $cod_label = ( isset( $payment['settlement'] ) && 'COD' === $payment['settlement'] ) ? __( 'C.O.D', 'usces' ) : __( 'Fee', 'usces' );
3882 + $cod_label = apply_filters( 'usces_filter_member_history_cod_label', $cod_label, $umhs['ID'] );
3883 + $history_member_head .= '<th class="historyrow cod">' . $cod_label . '</th>';
3884 + $head_col++;
3885 + }
3886 + if ( $tax_display && 'all' === $tax_target ) {
3887 + $history_member_head .= '<th class="historyrow tax">' . $tax_label . '</th>';
3888 + $head_col++;
3889 + }
3890 + if ( $member_system_point && 1 === $point_coverage ) {
3891 + $history_member_head .= '<th class="historyrow used_point">' . __( 'Used points', 'usces' ) . '</th>';
3892 + $head_col++;
3893 + }
3894 + if ( $member_system_point ) {
3895 + $history_member_head .= '<th class="historyrow get_point">' . __( 'Acquired points', 'usces' ) . '</th>';
3896 + $head_col++;
3897 + }
3898 + if ( ! empty( $tracking_number ) ) {
3899 + $history_member_head .= '<th class="historyrow">' . __( 'Tracking number', 'usces' ) . '</th>';
3900 + $head_col++;
3901 + }
3902 + $total_price = $umhs['total_items_price'] - $umhs['usedpoint'] + $umhs['discount'] + $umhs['shipping_charge'] + $umhs['cod_fee'] + $umhs['tax'];
3903 + if ( $total_price < 0 ) {
3904 + $total_price = 0;
3905 + }
3906 + $history_member_head .= '</tr></thead>
3907 + <tbody>
3908 + <tr class="order_head_value">
3909 + <td class="order_number" data-label="' . __( 'Order number', 'usces' ) . '">' . usces_get_deco_order_id( $umhs['ID'] ) . '</td>
3910 + <td class="date purchase_date" data-label="' . __( 'Purchase date', 'usces' ) . '">' . $umhs['date'] . '</td>';
3911 + if ( ! empty( $p_status ) ) {
3912 + $history_member_head .= '<td class="rightnum" data-label="' . __( 'Processing status', 'usces' ) . '">' . $p_status . '</td>';
3913 + }
3914 + if ( ! empty( $r_status ) ) {
3915 + $history_member_head .= '<td class="rightnum" data-label="' . __( 'transfer statement', 'usces' ) . '">' . $r_status . '</td>';
3916 + }
3917 + $history_member_head .= '<td class="rightnum purchase_price" data-label="' . __( 'Purchase price', 'usces' ) . '">' . usces_crform( $total_price, true, false, 'return' ) . '</td>
3918 + <td class="rightnum discount" data-label="' . apply_filters( 'usces_filter_discount_label', __( 'Discount', 'usces' ) ) . '">' . usces_crform( $umhs['discount'], true, false, 'return' ) . '</td>';
3919 + if ( $tax_display && 'products' === $tax_target ) {
3920 + $history_member_head .= '<td class="rightnum tax" data-label="' . $tax_label . '">' . usces_order_history_tax( $umhs, $tax_mode ) . '</td>';
3921 + }
3922 + if ( $member_system_point && 0 === $point_coverage ) {
3923 + $history_member_head .= '<td class="rightnum used_point" data-label="' . __( 'Used points', 'usces' ) . '">' . number_format( $umhs['usedpoint'] ) . '</td>';
3924 + }
3925 + if ( $shipping ) {
3926 + $history_member_head .= '<td class="rightnum shipping" data-label="' . __( 'Shipping', 'usces' ) . '">' . usces_crform( $umhs['shipping_charge'], true, false, 'return' ) . '</td>';
3927 + }
3928 + if ( ! empty( $umhs['cod_fee'] ) ) {
3929 + $history_member_head .= '<td class="rightnum cod" data-label="' . apply_filters( 'usces_filter_cod_label', __( 'C.O.D', 'usces' ) ) . '">' . usces_crform( $umhs['cod_fee'], true, false, 'return' ) . '</td>';
3930 + }
3931 + if ( $tax_display && 'all' === $tax_target ) {
3932 + $history_member_head .= '<td class="rightnum tax" data-label="' . $tax_label . '">' . usces_order_history_tax( $umhs, $tax_mode ) . '</td>';
3933 + }
3934 + if ( $member_system_point && 1 === $point_coverage ) {
3935 + $history_member_head .= '<td class="rightnum used_point" data-label="' . __( 'Used points', 'usces' ) . '">' . number_format( $umhs['usedpoint'] ) . '</td>';
3936 + }
3937 + if ( $member_system_point ) {
3938 + $history_member_head .= '<td class="rightnum get_point" data-label="' . __( 'Acquired points', 'usces' ) . '">' . number_format( $umhs['getpoint'] ) . '</td>';
3939 + }
3940 + if ( ! empty( $tracking_number ) ) {
3941 + if ( ! empty( $delivery_company_url ) ) {
3942 + $history_member_head .= '<td data-label="' . __( 'Tracking number', 'usces' ) . '"><a href="' . esc_url( $delivery_company_url ) . '">' . esc_attr( $tracking_number ) . '</a></td>';
3943 + } else {
3944 + $history_member_head .= '<td data-label="' . __( 'Tracking number', 'usces' ) . '">' . esc_attr( $tracking_number ) . '</td>';
3945 + }
3946 + }
3947 + $history_member_head .= '</tr>';
3948 + $html .= apply_filters( 'usces_filter_history_member_head', $history_member_head, $umhs );
3949 + $html .= apply_filters( 'usces_filter_member_history_header', null, $umhs, $head_col );
3950 + $html .= '</tbody></table>
3951 + <table id="retail_table_' . $umhs['ID'] . '" class="retail">';
3952 + $history_cart_head = '<thead><tr>
3953 + <th scope="row" class="cartrownum">No.</th>
3954 + <th class="thumbnail">&nbsp;</th>
3955 + <th class="productname">' . __( 'Items', 'usces' ) . '</th>
3956 + <th class="price">' . __( 'Unit price', 'usces' ) . '</th>
3957 + <th class="quantity">' . __( 'Quantity', 'usces' ) . '</th>
3958 + <th class="subtotal">' . __( 'Amount', 'usces' ) . '</th>
3959 + </tr></thead><tbody>';
3960 + $html .= apply_filters( 'usces_filter_history_cart_head', $history_cart_head, $umhs );
3961 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
3962 + for ( $i = 0; $i < $cart_count; $i++ ) {
3963 + $cart_row = $cart[ $i ];
3964 + $ordercart_id = $cart_row['cart_id'];
3965 + $post_id = $cart_row['post_id'];
3966 + $sku = $cart_row['sku'];
3967 + $sku_code = urldecode( $cart_row['sku'] );
3968 + $quantity = $cart_row['quantity'];
3969 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
3970 + $itemCode = $cart_row['item_code'];
3971 + $itemName = $cart_row['item_name'];
3972 + $cartItemName = $usces->getCartItemName_byOrder( $cart_row );
3973 + $skuPrice = $cart_row['price'];
3974 + $pictid = (int) $usces->get_mainpictid( $itemCode );
3975 + $optstr = '';
3976 + if ( is_array( $options ) && count( $options ) > 0 ) {
3977 + foreach ( $options as $key => $value ) {
3978 + if ( ! empty( $key ) ) {
3979 + $key = urldecode( $key );
3980 + $value = wel_safe_maybe_unserialize( $value );
3981 + if ( is_array( $value ) ) {
3982 + $c = '';
3983 + $optstr .= esc_html( $key ) . ' : ';
3984 + foreach ( $value as $v ) {
3985 + $optstr .= $c . nl2br( esc_html( rawurldecode( $v ) ) );
3986 + $c = ', ';
3987 + }
3988 + $optstr .= "<br />\n";
3989 + } else {
3990 + $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( rawurldecode( $value ) ) ) . "<br />\n";
2491 3991 }
2492 - $optstr .= "<br />\n";
2493 - } else {
2494 - $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2495 3992 }
2496 3993 }
2497 -//20110629ysk end
3994 + $optstr = apply_filters( 'usces_filter_option_history', $optstr, $options );
2498 3995 }
2499 - $optstr = apply_filters( 'usces_filter_option_history', $optstr, $options);
3996 + $optstr = apply_filters( 'usces_filter_option_info_history', $optstr, $umhs, $cart_row, $i );
3997 + $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
3998 +
3999 + $cart_item_name = '<a href="' . get_permalink( $post_id ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />' . $optstr . '</a>' . apply_filters( 'usces_filter_history_item_name', null, $umhs, $cart_row, $i );
4000 + $cart_item_name = apply_filters( 'usces_filter_history_cart_item_name', $cart_item_name, $cartItemName, $optstr, $cart_row, $i, $umhs );
4001 +
4002 + $history_cart_row = '<tr>
4003 + <td class="cartrownum">' . ( $i + 1 ) . '</td>
4004 + <td class="thumbnail">';
4005 + $cart_thumbnail = '<a href="' . get_permalink( $post_id ) . '">' . wp_get_attachment_image( $pictid, array( 60, 60 ), true ) . '</a>';
4006 + $history_cart_row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4007 + $history_cart_row .= '</td>
4008 + <td class="aleft productname" data-label="' . __( 'Items', 'usces' ) . '">' . $cart_item_name . '</td>
4009 + <td class="rightnum price" data-label="' . __( 'Unit price', 'usces' ) . '">' . usces_crform( $skuPrice, true, false, 'return' ) . '</td>
4010 + <td class="rightnum quantity" data-label="' . __( 'Quantity', 'usces' ) . '">' . number_format( $cart_row['quantity'] ) . '</td>
4011 + <td class="rightnum subtotal" data-label="' . __( 'Amount', 'usces' ) . '">' . usces_crform( $skuPrice * $cart_row['quantity'], true, false, 'return' ) . '</td>
4012 + </tr>';
4013 + $materials = compact( 'cart_thumbnail', 'post_id', 'pictid', 'cartItemName', 'optstr' );
4014 + $html .= apply_filters( 'usces_filter_history_cart_row', $history_cart_row, $umhs, $cart_row, $i, $materials );
2500 4015 }
2501 - $optstr = apply_filters( 'usces_filter_option_info_history', $optstr, $umhs, $cart_row, $i );
2502 -
2503 - $history_cart_row = '<tr>
2504 - <td>' . ($i + 1) . '</td>
2505 - <td>';
2506 - $cart_thumbnail = '<a href="' . get_permalink($post_id) . '">' . wp_get_attachment_image( $pictid, array(60, 60), true ) . '</a>';
2507 - $history_cart_row .= apply_filters('usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row);
2508 - $history_cart_row .= '</td>
2509 - <td class="aleft"><a href="' . get_permalink($post_id) . '">' . esc_html($cartItemName) . '<br />' . $optstr . '</a>' . apply_filters('usces_filter_history_item_name', NULL, $umhs, $cart_row, $i) . '</td>
2510 - <td class="rightnum">' . usces_crform($skuPrice, true, false, 'return') . '</td>
2511 - <td class="rightnum">' . number_format($cart_row['quantity']) . '</td>
2512 - <td class="rightnum">' . usces_crform($skuPrice * $cart_row['quantity'], true, false, 'return') . '</td>
2513 - </tr>';
2514 - $materials = compact( 'cart_thumbnail', 'post_id', 'pictid', 'cartItemName', 'optstr' );
2515 - $html .= apply_filters( 'usces_filter_history_cart_row', $history_cart_row, $umhs, $cart_row, $i, $materials );
4016 + $html .= '</tbody></table>';
4017 + $html .= apply_filters( 'usces_filter_member_history_row', '', $umhs, $cart );
2516 4018 }
2517 - $html .= '</table>
2518 - </td>
2519 - </tr>';
2520 4019 }
2521 -
2522 - $html .= '</table>';
4020 + $html .= '</div>';
4021 + $html = apply_filters( 'usces_filter_member_history', $html, $usces_member_history );
2523 4022
2524 - if($out == 'return'){
4023 + if ( 'return' === $out ) {
2525 4024 return $html;
2526 - }else{
2527 - echo $html;
4025 + } else {
4026 + echo $html; // no escape due to filter.
2528 4027 }
2529 4028 }
2530 4029
2531 -function usces_newmember_button($member_regmode){
2532 - $html = '<input name="member_regmode" type="hidden" value="' . $member_regmode . '" />';
2533 - $newmemberbutton = '<input name="regmember" type="submit" value="' . __('transmit a message', 'usces') . '" />';
2534 - $html .= apply_filters('usces_filter_newmember_button', $newmemberbutton);
2535 - echo $html;
4030 +/**
4031 + * Load select list filter purchase history.
4032 + */
4033 +function usces_load_filter_purchase_date() {
4034 + global $usces;
4035 +
4036 + $pur_date = $usces->usces_get_member_cookies( 'pur-date' );
4037 + $current_year = (int) gmdate( 'Y' );
4038 + $year_filter = 11;
4039 + $arr_filter = array(
4040 + '' => __( 'All of period', 'usces' ),
4041 + 'm_0' => __( 'This month', 'usces' ),
4042 + 'm_1' => __( 'Previous month', 'usces' ),
4043 + 'm_2' => __( 'Two months ago', 'usces' ),
4044 + 'd_30' => __( 'Last 30 days', 'usces' ),
4045 + 'd_60' => __( 'Last 60 days', 'usces' ),
4046 + );
4047 + for ( $i = 0; $i < $year_filter; $i++ ) {
4048 + $year = $current_year - $i;
4049 + $arr_filter[ 'y_' . $year ] = $year . __( 'year', 'usces' );
4050 + }
4051 + $exclude_cancel = $usces->usces_get_member_cookies( 'ord_ex_cancel' );
4052 + $add_ex_args = array(
4053 + 'ord_ex_cancel' => ( 'on' === (string) $exclude_cancel ) ? 'off' : 'on',
4054 + 'pur-date' => $pur_date,
4055 + );
4056 + $url_ex_filter = add_query_arg( $add_ex_args, USCES_MEMBER_URL ) . '#usces_history';
4057 + $html = '<div id="usces_history" class="usces_filter_history">';
4058 + $content = '<div class="exclude_cancel">';
4059 + $content .= '<label for="ord_exclude_cancel">';
4060 + $content .= '<input type="checkbox" id="ord_exclude_cancel" name="ord_exclude_cancel" onchange="memberOrderHistory.onChangeFilter(this);" value="' . esc_url( $url_ex_filter ) . '" ' . checked( $exclude_cancel, 'on', false ) . ' />';
4061 + $content .= __( 'Exclude cancellations', 'usces' ) . '</label>';
4062 + $content .= '</div>';
4063 + $content .= '<div class="usce_period">';
4064 + $content .= '<span>' . __( 'Period', 'usces' ) . '</span>';
4065 + $content .= '<select name="usces_purdate" id="usces_purdate" onchange="memberOrderHistory.onChangeFilter(this);">';
4066 + foreach ( $arr_filter as $key => $name ) {
4067 + $selected = '';
4068 + $add_args = array(
4069 + 'pur-date' => $key,
4070 + );
4071 + if ( (string) $key === (string) $pur_date ) {
4072 + $selected = 'selected';
4073 + }
4074 + $url_filter = add_query_arg( $add_args, USCES_MEMBER_URL ) . '#usces_history';
4075 + $content .= '<option cvalue="' . $key . '" value="' . esc_url( $url_filter ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $name ) . '</option>';
4076 + }
4077 + $content .= '</select>';
4078 + $content .= '</div>';
4079 + $html .= apply_filters( 'usces_filter_member_history_top_navi', $content );
4080 + $html .= '</div>';
4081 + return $html;
2536 4082 }
2537 4083
2538 -function usces_login_button(){
2539 - $loginbutton = '<input type="submit" name="member_login" id="member_login" class="member_login_button" value="' . __('Log-in', 'usces') . '" />';
2540 - $html = apply_filters('usces_filter_login_button', $loginbutton);
2541 - echo $html;
4084 +/**
4085 + * New registration button
4086 + *
4087 + * @param string $member_regmode Registration mode.
4088 + */
4089 +function usces_newmember_button( $member_regmode ) {
4090 + $html = '<input name="member_regmode" type="hidden" value="' . $member_regmode . '" />';
4091 + $newmemberbutton = '<input name="regmember" type="submit" value="' . __( 'transmit a message', 'usces' ) . '" />';
4092 + $html .= apply_filters( 'usces_filter_newmember_button', $newmemberbutton );
4093 + wel_esc_script_e( $html );
2542 4094 }
2543 4095
2544 -function usces_assistance_item($post_id, $title ){
2545 - if (usces_get_assistance_id_list($post_id)) :
4096 +/**
4097 + * Login button
4098 + */
4099 +function usces_login_button() {
4100 + $loginbutton = '<input type="submit" name="member_login" id="member_login" class="member_login_button" value="' . __( 'Log-in', 'usces' ) . '" />';
4101 + $html = apply_filters( 'usces_filter_login_button', $loginbutton );
4102 + wel_esc_script_e( $html );
4103 +}
4104 +
4105 +/**
4106 + * Related item
4107 + *
4108 + * @param int $post_id Post ID.
4109 + * @param string $title Title.
4110 + */
4111 +function usces_assistance_item( $post_id, $title ) {
4112 + if ( usces_get_assistance_id_list( $post_id ) ) :
2546 4113 global $post;
2547 - $r = new WP_Query( array('post__in'=>usces_get_assistance_ids($post_id), 'ignore_sticky_posts'=>1) );
2548 - if($r->have_posts()) :
2549 - add_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
2550 - add_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
2551 - $width = apply_filters( 'usces_filter_assistance_item_width', 100 );
2552 - $height = apply_filters( 'usces_filter_assistance_item_height', 100 );
2553 -?>
4114 + $r = new WP_Query( array( 'post__in' => usces_get_assistance_ids( $post_id ), 'ignore_sticky_posts' => 1 ) );
4115 + if ( $r->have_posts() ) :
4116 + add_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
4117 + add_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
4118 + $width = apply_filters( 'usces_filter_assistance_item_width', 100 );
4119 + $height = apply_filters( 'usces_filter_assistance_item_height', 100 );
4120 + ?>
2554 4121 <div class="assistance_item">
2555 - <h3><?php echo $title; ?></h3>
4122 + <h3><?php wel_esc_script_e( $title ); ?></h3>
2556 4123 <ul class="clearfix">
2557 -<?php
2558 - while ($r->have_posts()) :
2559 - $r->the_post();
2560 - usces_remove_filter();
2561 - usces_the_item();
2562 - ob_start();
2563 -?>
4124 + <?php
4125 + while ( $r->have_posts() ) :
4126 + $r->the_post();
4127 + usces_remove_filter();
4128 + usces_the_item();
4129 + ob_start();
4130 + ?>
2564 4131 <li>
2565 4132 <div class="listbox clearfix">
2566 4133 <div class="slit">
2567 - <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses(get_the_title()); ?>"><?php usces_the_itemImage(0, $width, $height, $post); ?></a>
4134 + <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses( get_the_title() ); ?>"><?php usces_the_itemImage( 0, $width, $height, $post ); ?></a>
2568 4135 </div>
2569 4136 <div class="detail">
2570 4137 <div class="assist_excerpt">
2571 - <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses(get_the_title()); ?>"><h4><?php usces_the_itemName(); ?></h4></a>
4138 + <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses( get_the_title() ); ?>"><h4><?php usces_the_itemName(); ?></h4></a>
2572 4139 <?php the_excerpt(); ?>
2573 4140 </div>
4141 + <?php if ( usces_is_skus() ) : ?>
2574 4142 <div class="assist_price">
2575 - <?php if (usces_is_skus()) : ?>
2576 - <?php _e('$', 'usces'); ?><?php usces_the_firstPrice(); ?>
4143 + <?php usces_crform( usces_the_firstPrice( 'return' ), true, false ); ?>
4144 + </div>
4145 + <?php usces_crform_the_itemPriceCr_taxincluded(); ?>
2577 4146 <?php endif; ?>
2578 - </div>
2579 4147 </div>
2580 4148 </div>
2581 4149 </li>
2582 - <?php
2583 - $list = ob_get_contents();
2584 - ob_end_clean();
2585 - echo apply_filters('usces_filter_assistance_item_list', $list, $post);
2586 - endwhile; ?>
2587 -
4150 + <?php
4151 + $list = ob_get_contents();
4152 + ob_end_clean();
4153 + echo apply_filters( 'usces_filter_assistance_item_list', $list, $post );
4154 + endwhile;
4155 + ?>
2588 4156 </ul>
2589 4157 </div><!-- end of assistance_item -->
2590 -<?php
2591 - wp_reset_postdata();
2592 - usces_reset_filter();
2593 - remove_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
2594 - remove_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
4158 + <?php
4159 + wp_reset_postdata();
4160 + usces_reset_filter();
4161 + remove_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
4162 + remove_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
2595 4163 endif;
2596 4164 endif;
2597 4165 }
2598 4166
4167 +/**
4168 + * Cart Item Details
4169 + *
4170 + * @param string $out Return value or echo.
4171 + * @return string|void
4172 + */
2599 4173 function usces_get_cart_rows( $out = '' ) {
2600 4174 global $usces, $usces_gp;
2601 - $cart = $usces->cart->get_cart();
2602 - $usces_gp = 0;
2603 - $res = '';
2604 4175
2605 - for($i=0; $i<count($cart); $i++) {
2606 - $cart_row = $cart[$i];
2607 - $post_id = $cart_row['post_id'];
2608 - $sku = $cart_row['sku'];
2609 - $sku_code = esc_attr(urldecode($cart_row['sku']));
2610 - $quantity = $cart_row['quantity'];
2611 - $options = $cart_row['options'];
2612 - $advance = $usces->cart->wc_serialize($cart_row['advance']);
2613 - $itemCode = $usces->getItemCode($post_id);
2614 - $itemName = $usces->getItemName($post_id);
2615 - $cartItemName = $usces->getCartItemName($post_id, $sku_code);
2616 - $itemRestriction = $usces->getItemRestriction($post_id);
2617 - $skuPrice = $cart_row['price'];
2618 - $skuZaikonum = $usces->getItemZaikonum($post_id, $sku_code);
2619 - $stockid = $usces->getItemZaikoStatusId($post_id, $sku_code);
2620 - $stock = $usces->getItemZaiko($post_id, $sku_code);
2621 - $red = (in_array($stock, array(__('sellout','usces'), __('Out Of Stock','usces'), __('Out of print','usces')))) ? 'class="signal_red"' : '';
2622 - $pictid = (int)$usces->get_mainpictid($itemCode);
2623 - $args = compact('cart', 'i', 'cart_row', 'post_id', 'sku' );
2624 - $row = '';
2625 - if ( empty($options) ) {
2626 - $optstr = '';
2627 - $options = array();
2628 - }
2629 - $row .= '<tr>
2630 - <td>' . ($i + 1) . '</td>
2631 - <td>';
2632 - $cart_thumbnail = '<a href="' . get_permalink($post_id) . '">' . wp_get_attachment_image( $pictid, array(60, 60), true ) . '</a>';
2633 - $row .= apply_filters('usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i,$cart_row);
2634 - $row .= '</td><td class="aleft">' . esc_html($cartItemName) . '<br />';
2635 - if( is_array($options) && count($options) > 0 ){
4176 + $cart = $usces->cart->get_cart();
4177 + $usces_gp = 0;
4178 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
4179 + $res = '';
4180 +
4181 + for ( $i = 0; $i < $cart_count; $i++ ) {
4182 + $cart_row = $cart[ $i ];
4183 + $post_id = (int) $cart_row['post_id'];
4184 + $sku = $cart_row['sku'];
4185 + $sku_code = urldecode( $cart_row['sku'] );
4186 + $quantity = $cart_row['quantity'];
4187 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
4188 + $advance = ( ! empty( $cart_row['advance'] ) ) ? $cart_row['advance'] : '';
4189 + $itemCode = $usces->getItemCode( $post_id );
4190 + $itemName = $usces->getItemName( $post_id );
4191 + $cartItemName = $usces->getCartItemName( $post_id, $sku_code );
4192 + $itemRestriction = $usces->getItemRestriction( $post_id );
4193 + $itemOrderAcceptable = $usces->getItemOrderAcceptable( $post_id );
4194 + $skuPrice = $cart_row['price'];
4195 + $skuZaikonum = $usces->getItemZaikonum( $post_id, $sku_code );
4196 + $stockid = $usces->getItemZaikoStatusId( $post_id, $sku_code );
4197 + $stock = $usces->getItemZaiko( $post_id, $sku_code );
4198 + $red = ( 1 < $stockid ) ? 'class="signal_red stock"' : 'class="stock"';
4199 + $pictid = (int) $usces->get_mainpictid( $itemCode );
4200 + $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
4201 +
4202 + $row = '';
4203 + $row .= '<tr>
4204 + <td class="num">' . ( $i + 1 ) . '</td>
4205 + <td class="thumbnail">';
4206 + $cart_thumbnail = '<a href="' . get_permalink( $post_id ) . '">' . wp_get_attachment_image( $pictid, array( 60, 60 ), true ) . '</a>';
4207 + $row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4208 + $row .= '</td>
4209 + <td class="aleft productname" data-label="' . esc_html__( 'Items', 'usces' ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />';
4210 + if ( is_array( $options ) && count( $options ) > 0 ) {
2636 4211 $optstr = '';
2637 - foreach($options as $key => $value){
2638 -//20110629ysk start 0000190
2639 - //if( !empty($key) )
2640 - // $row .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2641 - if( !empty($key) ) {
2642 - $key = urldecode($key);
2643 - if(is_array($value)) {
2644 - $c = '';
2645 - $optstr .= esc_html($key) . ' : ';
2646 - foreach($value as $v) {
2647 - $optstr .= $c.nl2br(esc_html(urldecode($v)));
2648 - $c = ', ';
4212 + foreach ( $options as $key => $value ) {
4213 + if ( ! empty( $key ) ) {
4214 + $key = urldecode( $key );
4215 + if ( is_array( $value ) ) {
4216 + $c = '';
4217 + $optstr .= esc_html( $key ) . ' : ';
4218 + foreach ( $value as $v ) {
4219 + $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
4220 + $c = ', ';
2649 4221 }
2650 - $optstr .= "<br />\n";
4222 + $optstr .= "<br />\n";
2651 4223 } else {
2652 - $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
4224 + $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . "<br />\n";
2653 4225 }
2654 4226 }
2655 -//20110629ysk end
2656 4227 }
2657 - $row .= apply_filters( 'usces_filter_option_cart', $optstr, $options);
4228 + $row .= apply_filters( 'usces_filter_option_cart', $optstr, $options, $args );
2658 4229 }
2659 4230 $row .= apply_filters( 'usces_filter_option_info_cart', '', $cart_row, $args );
2660 4231 $row .= '</td>
2661 - <td class="aright">';
2662 - if( usces_is_gptekiyo($post_id, $sku_code, $quantity) ) {
2663 - $usces_gp = 1;
2664 - $Business_pack_mark = '<img src="' . get_template_directory_uri() . '/images/gp.gif" alt="' . __('Business package discount','usces') . '" /><br />';
2665 - $row .= apply_filters('usces_filter_itemGpExp_cart_mark', $Business_pack_mark);
4232 + <td class="aright unitprice" data-label="' . esc_html__( 'Unit price', 'usces' ) . '">';
4233 + if ( usces_is_gptekiyo( $post_id, $sku_code, $quantity ) ) {
4234 + $usces_gp = 1;
4235 + $gp_src = file_exists( get_template_directory() . '/images/gp.gif' ) ? get_template_directory_uri() . '/images/gp.gif' : USCES_PLUGIN_URL . '/images/gp.gif';
4236 + $Business_pack_mark = '<img src="' . $gp_src . '" alt="' . __( 'Business package discount', 'usces' ) . '" /><br />';
4237 + $row .= apply_filters( 'usces_filter_itemGpExp_cart_mark', $Business_pack_mark );
2666 4238 }
2667 - $row .= usces_crform($skuPrice, true, false, 'return') . '
4239 + $row .= usces_crform( $skuPrice, true, false, 'return' ) . '
2668 4240 </td>
2669 - <td>';
2670 - $row_quant = '<input name="quant[' . $i . '][' . $post_id . '][' . $sku . ']" class="quantity" type="text" value="' . esc_attr($cart_row['quantity']) . '" />';
2671 - $row .= apply_filters( 'usces_filter_cart_rows_quant', $row_quant, $args );
2672 - $row .= '</td>
2673 - <td class="aright">' . usces_crform(($skuPrice * $cart_row['quantity']), true, false, 'return') . '</td>
2674 - <td ' . $red . '>' . $stock . '</td>
2675 - <td>';
2676 - foreach($options as $key => $value){
2677 -//20110629ysk start 0000190
2678 - //$row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . $sku . '][' . $key . ']" type="hidden" value="' . $value . '" />';
2679 - if(is_array($value)) {
2680 - foreach($value as $v) {
2681 - $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . $sku . '][' . $key . '][' . $v . ']" type="hidden" value="' . $v . '" />';
4241 + <td class="quantity" data-label="' . esc_html__( 'Quantity', 'usces' ) . '">';
4242 + $row_quant = '<input name="quant[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" class="quantity" type="text" value="' . esc_attr( $cart_row['quantity'] ) . '" />';
4243 + $row .= apply_filters( 'usces_filter_cart_rows_quant', $row_quant, $args );
4244 + $row .= '</td>
4245 + <td class="aright subtotal" data-label="' . esc_html__( 'Amount', 'usces' ) . usces_guid_tax( 'return', false ) . '">' . usces_crform( ( $skuPrice * $cart_row['quantity'] ), true, false, 'return' ) . '</td>';
4246 + $stock_column = '<td ' . $red . ' data-label="' . esc_html__( 'stock status', 'usces' ) . '">' . esc_html( $stock ) . '</td>';
4247 + $row .= apply_filters( 'usces_filter_cart_rows_stock', $stock_column, $args, $red, $stock );
4248 + $row .= '<td class="action">';
4249 + if ( is_array( $options ) && count( $options ) > 0 ) {
4250 + foreach ( $options as $key => $value ) {
4251 + if ( is_array( $value ) ) {
4252 + foreach ( $value as $v ) {
4253 + $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . '][' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" type="hidden" value="' . esc_attr( $v ) . '" />' . "\n";
4254 + }
4255 + } else {
4256 + $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . '][' . esc_attr( $key ) . ']" type="hidden" value="' . esc_attr( $value ) . '" />' . "\n";
2682 4257 }
2683 - } else {
2684 - $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . $sku . '][' . $key . ']" type="hidden" value="' . $value . '" />';
2685 4258 }
2686 -//20110629ysk end
2687 4259 }
2688 - $row .= '<input name="itemRestriction[' . $i . ']" type="hidden" value="' . $itemRestriction . '" />
2689 - <input name="stockid[' . $i . ']" type="hidden" value="' . $stockid . '" />
2690 - <input name="itempostid[' . $i . ']" type="hidden" value="' . $post_id . '" />
2691 - <input name="itemsku[' . $i . ']" type="hidden" value="' . $sku . '" />
2692 - <input name="zaikonum[' . $i . '][' . $post_id . '][' . $sku . ']" type="hidden" value="' . esc_attr($skuZaikonum) . '" />
2693 - <input name="skuPrice[' . $i . '][' . $post_id . '][' . $sku . ']" type="hidden" value="' . esc_attr($skuPrice) . '" />
2694 - <input name="advance[' . $i . '][' . $post_id . '][' . $sku . ']" type="hidden" value="' . esc_attr($advance) . '" />
2695 - <input name="delButton[' . $i . '][' . $post_id . '][' . $sku . ']" class="delButton" type="submit" value="' . __('Delete','usces') . '" />
4260 + $row .= '<input name="itemRestriction[' . $i . ']" type="hidden" value="' . esc_attr( $itemRestriction ) . '" />
4261 + <input name="itemOrderAcceptable[' . $i . ']" type="hidden" value="' . $itemOrderAcceptable . '" />
4262 + <input name="stockid[' . $i . ']" type="hidden" value="' . esc_attr( $stockid ) . '" />
4263 + <input name="itempostid[' . $i . ']" type="hidden" value="' . esc_attr( $post_id ) . '" />
4264 + <input name="itemsku[' . $i . ']" type="hidden" value="' . esc_attr( $sku ) . '" />
4265 + <input name="zaikonum[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $skuZaikonum ) . '" />
4266 + <input name="skuPrice[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $skuPrice ) . '" />
4267 + <input name="advance[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $advance ) . '" />
4268 + <input name="delButton[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" class="delButton" type="submit" value="' . __( 'Delete', 'usces' ) . '" />
2696 4269 </td>
2697 4270 </tr>';
2698 - $materials = compact('i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance',
2699 - 'itemCode', 'itemName', 'cartItemName', 'itemRestriction', 'skuPrice', 'skuZaikonum',
2700 - 'stockid', 'stock', 'red', 'pictid');
2701 - $res .= apply_filters( 'usces_filter_cart_row', $row, $cart, $materials);
4271 + $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance', 'itemCode', 'itemName', 'cartItemName', 'itemRestriction', 'skuPrice', 'skuZaikonum', 'stockid', 'stock', 'red', 'pictid' );
4272 + $res .= apply_filters( 'usces_filter_cart_row', $row, $cart, $materials );
2702 4273 }
2703 -
2704 - $res = apply_filters( 'usces_filter_cart_rows', $res, $cart);
2705 4274
2706 - if($out == 'return'){
4275 + $res = apply_filters( 'usces_filter_cart_rows', $res, $cart );
4276 +
4277 + if ( 'return' === $out ) {
2707 4278 return $res;
2708 - }else{
2709 - echo $res;
4279 + } else {
4280 + echo $res; // no escape due to filter.
2710 4281 }
2711 4282 }
4283 +
4284 +/**
4285 + * Confirm Cart Item Details
4286 + *
4287 + * @param string $out Return value or echo.
4288 + * @return string|void
4289 + */
2712 4290 function usces_get_confirm_rows( $out = '' ) {
2713 4291 global $usces, $usces_members, $usces_entries;
2714 -// $usces_members = $usces->get_member();
2715 - $memid = ( empty($usces_members['ID']) ) ? 999999999 : $usces_members['ID'];
2716 -// $usces_entries = $usces->cart->get_entry();
4292 +
4293 + $memid = ( empty( $usces_members['ID'] ) ) ? 999999999 : $usces_members['ID'];
2717 4294 $usces->set_cart_fees( $usces_members, $usces_entries );
2718 4295 $usces_entries = $usces->cart->get_entry();
2719 -
2720 - $cart = $usces->cart->get_cart();
2721 - $res = '';
2722 - for($i=0; $i<count($cart); $i++) {
2723 - $cart_row = $cart[$i];
2724 - $post_id = $cart_row['post_id'];
2725 - $sku = esc_attr($cart_row['sku']);
2726 - $sku_code = esc_attr(urldecode($cart_row['sku']));
2727 - $quantity = $cart_row['quantity'];
2728 - $options = $cart_row['options'];
2729 - $advance = $usces->cart->wc_serialize($cart_row['advance']);
2730 - $itemCode = $usces->getItemCode($post_id);
2731 - $itemName = $usces->getItemName($post_id);
2732 - $cartItemName = $usces->getCartItemName($post_id, $sku_code);
2733 - $skuPrice = $cart_row['price'];
2734 - $pictid = $usces->get_mainpictid($itemCode);
2735 - $args = compact('cart', 'i', 'cart_row', 'post_id', 'sku' );
2736 - $row = '';
2737 - if (empty($options)) {
2738 - $optstr = '';
2739 - $options = array();
2740 - }
2741 -
2742 - $row .= '<tr>
2743 - <td>' . ($i + 1) . '</td>
2744 - <td>';
2745 - $cart_thumbnail = wp_get_attachment_image( $pictid, array(60, 60), true );
2746 - $row .= apply_filters('usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row);
2747 - $row .= '</td><td class="aleft">' . $cartItemName . '<br />';
2748 - if( is_array($options) && count($options) > 0 ){
4296 +
4297 + $cart = $usces->cart->get_cart();
4298 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
4299 + $res = '';
4300 +
4301 + for ( $i = 0; $i < $cart_count; $i++ ) {
4302 + $cart_row = $cart[ $i ];
4303 + $post_id = (int) $cart_row['post_id'];
4304 + $sku = $cart_row['sku'];
4305 + $sku_code = urldecode( $cart_row['sku'] );
4306 + $quantity = $cart_row['quantity'];
4307 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
4308 + $advance = $cart_row['advance'];
4309 + $itemCode = $usces->getItemCode( $post_id );
4310 + $itemName = $usces->getItemName( $post_id );
4311 + $cartItemName = $usces->getCartItemName( $post_id, $sku_code );
4312 + $skuPrice = $cart_row['price'];
4313 + $pictid = $usces->get_mainpictid( $itemCode );
4314 + $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
4315 +
4316 + $row = '';
4317 + $row .= '<tr>
4318 + <td class="num">' . ( $i + 1 ) . '</td>
4319 + <td class="thumbnail">';
4320 + $cart_thumbnail = wp_get_attachment_image( $pictid, array( 60, 60 ), true );
4321 + $row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4322 + $row .= '</td><td class="productname" data-label="' . esc_html__( 'Items', 'usces' ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />';
4323 + if ( is_array( $options ) && count( $options ) > 0 ) {
2749 4324 $optstr = '';
2750 - foreach($options as $key => $value){
2751 -//20110629ysk start 0000190
2752 - //if( !empty($key) )
2753 - // $row .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2754 - if( !empty($key) ) {
2755 - $key = urldecode($key);
2756 - if(is_array($value)) {
2757 - $c = '';
2758 - $optstr .= esc_html($key) . ' : ';
2759 - foreach($value as $v) {
2760 - $optstr .= $c.nl2br(esc_html(urldecode($v)));
2761 - $c = ', ';
4325 + foreach ( $options as $key => $value ) {
4326 + if ( ! empty( $key ) ) {
4327 + $key = urldecode( $key );
4328 + if ( is_array( $value ) ) {
4329 + $c = '';
4330 + $optstr .= esc_html( $key ) . ' : ';
4331 + foreach ( $value as $v ) {
4332 + $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
4333 + $c = ', ';
2762 4334 }
2763 - $optstr .= "<br />\n";
4335 + $optstr .= "<br />\n";
2764 4336 } else {
2765 - $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
4337 + $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . "<br />\n";
2766 4338 }
2767 4339 }
2768 -//20110629ysk end
2769 4340 }
2770 - $row .= apply_filters( 'usces_filter_option_confirm', $optstr, $options);
4341 + $row .= apply_filters( 'usces_filter_option_confirm', $optstr, $options, $args );
2771 4342 }
2772 4343 $row .= apply_filters( 'usces_filter_option_info_confirm', '', $cart_row, $args );
2773 4344 $row .= '</td>
2774 - <td class="aright">' . usces_crform($skuPrice, true, false, 'return') . '</td>
2775 - <td>' . $cart_row['quantity'] . '</td>
2776 - <td class="aright">' . usces_crform(($skuPrice * $cart_row['quantity']), true, false, 'return') . '</td>
2777 - <td>';
2778 - $res = apply_filters('usces_additional_confirm', $res, array($i, $post_id, $sku_code));
4345 + <td class="unitprice" data-label="' . esc_html__( 'Unit price', 'usces' ) . '">' . esc_html( usces_crform( $skuPrice, true, false, 'return' ) ) . '</td>
4346 + <td class="quantity" data-label="' . esc_html__( 'Quantity', 'usces' ) . '">' . esc_html( $cart_row['quantity'] ) . '</td>
4347 + <td class="subtotal" data-label="' . esc_html__( 'Amount', 'usces' ) . '">' . esc_html( usces_crform( ( $skuPrice * $cart_row['quantity'] ), true, false, 'return' ) ) . '</td>
4348 + <td class="action">';
4349 + $row .= apply_filters( 'usces_additional_confirm', '', array( $i, $post_id, $sku_code ) );
2779 4350 $row .= '</td>
2780 4351 </tr>';
2781 -
2782 - $materials = compact('i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance',
2783 - 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'pictid');
2784 - $res .= apply_filters( 'usces_filter_confirm_row', $row, $cart, $materials);
2785 - }
2786 -
2787 - $res = apply_filters( 'usces_filter_confirm_rows', $res, $cart);
2788 4352
2789 - if($out == 'return'){
4353 + $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance', 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'pictid' );
4354 + $res .= apply_filters( 'usces_filter_confirm_row', $row, $cart, $materials );
4355 + }
4356 +
4357 + $res = apply_filters( 'usces_filter_confirm_rows', $res, $cart );
4358 +
4359 + if ( 'return' === $out ) {
2790 4360 return $res;
2791 - }else{
2792 - echo $res;
4361 + } else {
4362 + echo $res; // no escape due to filter.
2793 4363 }
2794 4364 }
2795 4365
2796 -function uesces_addressform( $type, $data, $out = 'return' ){
4366 +/**
4367 + * Address Information
4368 + *
4369 + * @param string $type Type.
4370 + * @param array $data Entry data.
4371 + * @param string $out Return value or echo.
4372 + * @return string|void
4373 + */
4374 +function uesces_addressform( $type, $data, $out = 'return' ) {
2797 4375 global $usces, $usces_settings;
2798 - $options = get_option('usces');
2799 - $form = $options['system']['addressform'];
2800 - $nameform = $usces_settings['nameform'][$form];
2801 - $applyform = usces_get_apply_addressform($form);
2802 - $formtag = '';
2803 - switch( $type ){
2804 - case 'confirm':
2805 - case 'member':
2806 - $values = $data;
2807 - break;
2808 - case 'customer':
2809 - case 'delivery':
2810 - $values = $data[$type];
2811 - break;
2812 - }
2813 - $data['type'] = $type;
2814 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
2815 - $values = $usces->stripslashes_deep_post($values);
2816 - if( 'confirm' == $type ){
2817 -
2818 - switch ($applyform){
2819 -
2820 - case 'JP':
2821 - $formtag .= usces_custom_field_info($data, 'customer', 'name_pre', 'return');
2822 - $formtag .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['customer']['name1']) . ' ' . esc_html($values['customer']['name2']) . '</td></tr>';
2823 - $furigana_customer = '<tr><th>'.__('furigana', 'usces').'</th><td>' . esc_html($values['customer']['name3']) . ' ' . esc_html($values['customer']['name4']) . '</td></tr>';
2824 - $formtag .= apply_filters( 'usces_filter_furigana_confirm_customer', $furigana_customer, $type, $values );
2825 - $formtag .= usces_custom_field_info($data, 'customer', 'name_after', 'return');
2826 - $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : '';
2827 - $formtag .= '<tr><th>'.__('Zip/Postal Code', 'usces').'</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>';
2828 -//20131213_kitamura_start
2829 - if( count( $options['system']['target_market'] ) != 1 ){
2830 - $formtag .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($customer_country) . '</td></tr>';
2831 - }
2832 -//20131213_kitamura_end
2833 - $formtag .= '
2834 - <tr><th>'.__('Province', 'usces').'</th><td>' . esc_html($values['customer']['pref']) . '</td></tr>
2835 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['customer']['address1']) . '</td></tr>
2836 - <tr><th>'.__('numbers', 'usces').'</th><td>' . esc_html($values['customer']['address2']) . '</td></tr>
2837 - <tr><th>'.__('building name', 'usces').'</th><td>' . esc_html($values['customer']['address3']) . '</td></tr>
2838 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['customer']['tel']) . '</td></tr>
2839 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>';
2840 - $formtag .= usces_custom_field_info($data, 'customer', 'fax_after', 'return');
2841 -
2842 - $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>'.__('Shipping address information', 'usces').'</h3></td></tr>';
2843 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return');
2844 - $shipping_address_info .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['delivery']['name1']) . ' ' . esc_html($values['delivery']['name2']) . '</td></tr>';
2845 - $furigana_delivery = '<tr><th>'.__('furigana', 'usces').'</th><td>' . esc_html($values['delivery']['name3']) . ' ' . esc_html($values['delivery']['name4']) . '</td></tr>';
2846 - $shipping_address_info .= apply_filters( 'usces_filter_furigana_confirm_delivery', $furigana_delivery, $type, $values );
2847 - $shipping_address_info .= usces_custom_field_info($values, 'delivery', 'name_after', 'return');
2848 - $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : '';
2849 - $shipping_address_info .= '<tr><th>'.__('Zip/Postal Code', 'usces').'</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>';
2850 -//20131213_kitamura_start
2851 - if( count( $options['system']['target_market'] ) != 1 ){
2852 - $shipping_address_info .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($shipping_country) . '</td></tr>';
2853 - }
2854 -//20131213_kitamura_end
2855 - $shipping_address_info .= '
2856 - <tr><th>'.__('Province', 'usces').'</th><td>' . esc_html($values['delivery']['pref']) . '</td></tr>
2857 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr>
2858 - <tr><th>'.__('numbers', 'usces').'</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr>
2859 - <tr><th>'.__('building name', 'usces').'</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr>
2860 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>
2861 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>';
2862 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return');
2863 - $formtag .= apply_filters('usces_filter_shipping_address_info', $shipping_address_info);
4376 +
4377 + $options = get_option( 'usces', array() );
4378 + $form = $options['system']['addressform'];
4379 + $nameform = $usces_settings['nameform'][ $form ];
4380 + $applyform = usces_get_apply_addressform( $form );
4381 + $formtag = '';
4382 + switch ( $type ) {
4383 + case 'confirm':
4384 + case 'member':
4385 + $values = $data;
2864 4386 break;
2865 -
2866 - case 'CN':
2867 - $formtag .= usces_custom_field_info($data, 'customer', 'name_pre', 'return');
2868 - $formtag .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html(usces_localized_name( $values['customer']['name1'], $values['customer']['name2'], 'return' )) . '</td></tr>';
2869 - $formtag .= usces_custom_field_info($data, 'customer', 'name_after', 'return');
2870 -//20131213_kitamura_start
2871 - if( count( $options['system']['target_market'] ) != 1 ){
2872 - $formtag .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($usces_settings['country'][$values['customer']['country']]) . '</td></tr>';
2873 - }
2874 -//20131213_kitamura_end
2875 - $formtag .= '
2876 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['customer']['pref']) . '</td></tr>
2877 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['customer']['address1']) . '</td></tr>
2878 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['customer']['address2']) . '</td></tr>
2879 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['customer']['address3']) . '</td></tr>
2880 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>
2881 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['customer']['tel']) . '</td></tr>
2882 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>';
2883 - $formtag .= usces_custom_field_info($data, 'customer', 'fax_after', 'return');
2884 -
2885 - $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>'.__('Shipping address information', 'usces').'</h3></td></tr>';
2886 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return');
2887 - $shipping_address_info .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html(usces_localized_name( $values['delivery']['name1'], $values['delivery']['name2'], 'return' )) . '</td></tr>';
2888 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_after', 'return');
2889 -//20131213_kitamura_start
2890 - if( count( $options['system']['target_market'] ) != 1 ){
2891 - $shipping_address_info .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($usces_settings['country'][$values['delivery']['country']]) . '</td></tr>';
2892 - }
2893 -//20131213_kitamura_end
2894 - $shipping_address_info .= '
2895 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['delivery']['pref']) . '</td></tr>
2896 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr>
2897 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr>
2898 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr>
2899 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>
2900 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>
2901 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>';
2902 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return');
2903 - $formtag .= apply_filters('usces_filter_shipping_address_info', $shipping_address_info);
4387 + case 'customer':
4388 + case 'delivery':
4389 + $values = $data[ $type ];
2904 4390 break;
2905 -
2906 - case 'US':
2907 - default :
2908 - $formtag .= usces_custom_field_info($data, 'customer', 'name_pre', 'return');
2909 - $formtag .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['customer']['name2']) . ' ' . esc_html($values['customer']['name1']) . '</td></tr>';
2910 - $formtag .= usces_custom_field_info($data, 'customer', 'name_after', 'return');
2911 - $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : '';
2912 - $formtag .= '
2913 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['customer']['address2']) . '</td></tr>
2914 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['customer']['address3']) . '</td></tr>
2915 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['customer']['address1']) . '</td></tr>
2916 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['customer']['pref']) . '</td></tr>';
4391 + }
4392 + $data['type'] = $type;
4393 + $values['country'] = ! empty( $values['country'] ) ? $values['country'] : usces_get_local_addressform();
4394 + $values = $usces->stripslashes_deep_post( $values );
4395 + $target_market_count = ( isset( $options['system']['target_market'] ) && is_array( $options['system']['target_market'] ) ) ? count( $options['system']['target_market'] ) : 1;
2917 4396
2918 -//20131213_kitamura_start
2919 - if( count( $options['system']['target_market'] ) != 1 ){
2920 - $formtag .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($customer_country) . '</td></tr>';
2921 - }
2922 -//20131213_kitamura_end
2923 - $formtag .= '
2924 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>
2925 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['customer']['tel']) . '</td></tr>
2926 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>';
2927 - $formtag .= usces_custom_field_info($data, 'customer', 'fax_after', 'return');
2928 -
2929 - $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>'.__('Shipping address information', 'usces').'</h3></td></tr>';
2930 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return');
2931 - $shipping_address_info .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['delivery']['name2']) . ' ' . esc_html($values['delivery']['name1']) . '</td></tr>';
2932 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_after', 'return');
2933 - $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : '';
2934 - $shipping_address_info .= '
2935 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr>
2936 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr>
2937 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr>
2938 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['delivery']['pref']) . '</td></tr>';
2939 -//20131213_kitamura_start
2940 - if( count( $options['system']['target_market'] ) != 1 ){
2941 - $shipping_address_info .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($shipping_country) . '</td></tr>';
2942 - }
2943 -//20131213_kitamura_end
2944 - $shipping_address_info .= '
2945 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>
2946 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>
2947 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>';
2948 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return');
2949 - $formtag .= apply_filters('usces_filter_shipping_address_info', $shipping_address_info);
2950 - break;
2951 -
4397 + if ( 'confirm' === $type ) {
4398 +
4399 + switch ( $applyform ) {
4400 +
4401 + case 'JP':
4402 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4403 + $formtag .= '<tr class="name-row member-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . esc_html( sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name1'] ) . ' ' . esc_html( $values['customer']['name2'] ) ) ) ) . '</td></tr>';
4404 + $furigana = ( '' === ( trim( $values['customer']['name3'] ) . trim( $values['customer']['name4'] ) ) ) ? '' : sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name3'] ) . ' ' . esc_html( $values['customer']['name4'] ) ) );
4405 + $furigana_customer = '<tr class="furikana-row member-furikana-row"><th>' . __( 'furigana', 'usces' ) . '</th><td>' . $furigana . '</td></tr>';
4406 + $formtag .= apply_filters( 'usces_filter_furigana_confirm_customer', $furigana_customer, $type, $values );
4407 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4408 + $formtag .= '<tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip/Postal Code', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>';
4409 + if ( 1 < $target_market_count ) {
4410 + $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4411 + $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4412 + }
4413 + $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4414 + $formtag .= '
4415 + <tr class="states-row member-states-row"><th>' . __( 'Province', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>
4416 + <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4417 + <tr class="address2-row member-address2-row"><th>' . __( 'numbers', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4418 + <tr class="address3-row member-address3-row"><th>' . __( 'building name', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4419 + <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4420 + <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4421 + $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4422 +
4423 + $shipping_address_info = '';
4424 + if ( isset( $values['delivery'] ) ) {
4425 + $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4426 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4427 + $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['delivery']['name1'] ) . ' ' . esc_html( $values['delivery']['name2'] ) ) ) . '</td></tr>';
4428 + $deli_furigana = ( '' === ( trim( $values['delivery']['name3'] ) . trim( $values['delivery']['name4'] ) ) ) ? '' : sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['delivery']['name3'] ) . ' ' . esc_html( $values['delivery']['name4'] ) ) );
4429 + $furigana_delivery = '<tr class="furikana-row delivery-furikana-row"><th>' . __( 'furigana', 'usces' ) . '</th><td>' . $deli_furigana . '</td></tr>';
4430 + $shipping_address_info .= apply_filters( 'usces_filter_furigana_confirm_delivery', $furigana_delivery, $type, $values );
4431 + $shipping_address_info .= usces_custom_field_info( $values, 'delivery', 'name_after', 'return' );
4432 + $shipping_address_info .= '<tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip/Postal Code', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>';
4433 + if ( 1 < $target_market_count ) {
4434 + $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4435 + $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4436 + }
4437 + $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4438 + $shipping_address_info .= '
4439 + <tr class="states-row delivery-states-row"><th>' . __( 'Province', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>
4440 + <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4441 + <tr class="address2-row delivery-address2-row"><th>' . __( 'numbers', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4442 + <tr class="address3-row delivery-address3-row"><th>' . __( 'building name', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4443 + <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4444 + <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4445 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4446 + }
4447 + $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4448 + break;
4449 +
4450 + case 'CN':
4451 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4452 + $formtag .= '<tr class="name-row member-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), esc_html( usces_localized_name( $values['customer']['name1'], $values['customer']['name2'], 'return' ) ) ) . '</td></tr>';
4453 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4454 + if ( 1 < $target_market_count ) {
4455 + $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4456 + $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4457 + }
4458 + $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4459 + $formtag .= '
4460 + <tr class="states-row member-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>
4461 + <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4462 + <tr class="address2-row member-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4463 + <tr class="address3-row member-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4464 + <tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>
4465 + <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4466 + <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4467 + $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4468 +
4469 + $shipping_address_info = '';
4470 + if ( isset( $values['delivery'] ) ) {
4471 + $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4472 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4473 + $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), esc_html( usces_localized_name( $values['delivery']['name1'], $values['delivery']['name2'], 'return' ) ) ) . '</td></tr>';
4474 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_after', 'return' );
4475 + if ( 1 < $target_market_count ) {
4476 + $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4477 + $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4478 + }
4479 + $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4480 + $shipping_address_info .= '
4481 + <tr class="states-row delivery-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>
4482 + <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4483 + <tr class="address2-row delivery-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4484 + <tr class="address3-row delivery-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4485 + <tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>
4486 + <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4487 + <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4488 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4489 + }
4490 + $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4491 + break;
4492 +
4493 + case 'US':
4494 + default:
4495 + $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4496 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4497 + $formtag .= '<tr class="name-row member-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name2'] ) . ' ' . esc_html( $values['customer']['name1'] ) ) ) . '</td></tr>';
4498 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4499 + $formtag .= '
4500 + <tr class="address2-row member-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4501 + <tr class="address3-row member-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4502 + <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4503 + <tr class="states-row member-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>';
4504 + if ( 1 < $target_market_count ) {
4505 + $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4506 + $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4507 + }
4508 + $formtag .= '
4509 + <tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>
4510 + <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4511 + <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4512 + $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4513 +
4514 + $shipping_address_info = '';
4515 + if ( isset( $values['delivery'] ) ) {
4516 + $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4517 + $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4518 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4519 + $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['delivery']['name2'] ) . ' ' . esc_html( $values['delivery']['name1'] )) ) . '</td></tr>';
4520 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_after', 'return' );
4521 + $shipping_address_info .= '
4522 + <tr class="address2-row delivery-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4523 + <tr class="address3-row delivery-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4524 + <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4525 + <tr class="states-row delivery-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>';
4526 + if ( 1 < $target_market_count ) {
4527 + $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4528 + $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4529 + }
4530 + $shipping_address_info .= '
4531 + <tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>
4532 + <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4533 + <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4534 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4535 + }
4536 + $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4537 + break;
2952 4538 }
2953 - $res = apply_filters('usces_filter_apply_addressform_confirm', $formtag, $type, $data);
2954 -
2955 - }else{
2956 -
2957 - switch ($applyform){
2958 -
2959 - case 'JP':
2960 - $formtag .= usces_custom_field_input($data, $type, 'name_pre', 'return');
2961 - $formtag .= '<tr class="inp1">
2962 - <th width="127" scope="row">' . usces_get_essential_mark('name1', $data) . __('Full name', 'usces').'</th>';
2963 - if( $nameform ){
2964 - $formtag .= '<td class="name_td">'.__('Given name', 'usces').'<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2965 - $formtag .= '<td class="name_td">'.__('Familly name', 'usces').'<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2966 - }else{
2967 - $formtag .= '<td class="name_td">'.__('Familly name', 'usces').'<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2968 - $formtag .= '<td class="name_td">'.__('Given name', 'usces').'<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2969 - }
2970 - $formtag .= '</tr>';
2971 - $furigana = '<tr class="inp1">
2972 - <th scope="row">' . usces_get_essential_mark('name3', $data).__('furigana', 'usces').'</th>';
2973 - if( $nameform ){
2974 - $furigana .= '<td>'.__('Given name', 'usces').'<input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr($values['name4']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2975 - $furigana .= '<td>'.__('Familly name', 'usces').'<input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr($values['name3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2976 - }else{
2977 - $furigana .= '<td>'.__('Familly name', 'usces').'<input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr($values['name3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2978 - $furigana .= '<td>'.__('Given name', 'usces').'<input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr($values['name4']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
2979 - }
2980 - $furigana .= '</tr>';
2981 - $formtag .= apply_filters( 'usces_filter_furigana_form', $furigana, $type, $values );
2982 - $formtag .= usces_custom_field_input($data, $type, 'name_after', 'return');
2983 - $formtag .= '<tr>
2984 - <th scope="row">' . usces_get_essential_mark('zipcode', $data).__('Zip/Postal Code', 'usces').'</th>
2985 - <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr($values['zipcode']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />'.apply_filters('usces_filter_addressform_zipcode', NULL, $type) . apply_filters( 'usces_filter_after_zipcode', '100-1000', $applyform ) . '</td>
2986 - </tr>';
2987 -//20131213_kitamura_start
2988 - if( count( $options['system']['target_market'] ) == 1 ){
2989 - $formtag .= '<input type="hidden" name="' .$type. '[country]" id="' .$type. '_country" value="' .$options['system']['target_market'][0]. '">';
2990 - }else{
2991 - $formtag .= '<tr>
2992 - <th scope="row">' . usces_get_essential_mark('country', $data) . __('Country', 'usces') . '</th>
2993 - <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', NULL, $applyform ) . '</td>
4539 + $res = apply_filters( 'usces_filter_apply_addressform_confirm', $formtag, $type, $data );
4540 +
4541 + } else {
4542 +
4543 + switch ( $applyform ) {
4544 +
4545 + case 'JP':
4546 + $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4547 + $formtag .= '<tr id="name_row" class="inp1">
4548 + <th width="127" scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4549 + if ( $nameform ) {
4550 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Given name', 'usces' ) . '</span><input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4551 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Familly name', 'usces' ) . '</span><input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4552 + } else {
4553 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Familly name', 'usces' ) . '</span><input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4554 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Given name', 'usces' ) . '</span><input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4555 + }
4556 + $formtag .= '</tr>';
4557 + $furigana = '<tr id="furikana_row" class="inp1">
4558 + <th scope="row">' . usces_get_essential_mark( 'name3', $data ) . __( 'furigana', 'usces' ) . '</th>';
4559 + if ( $nameform ) {
4560 + $furigana .= '<td><span class="member_furigana">' . _x( 'Given name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr( $values['name4'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4561 + $furigana .= '<td><span class="member_furigana">' . _x( 'Familly name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr( $values['name3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4562 + } else {
4563 + $furigana .= '<td><span class="member_furigana">' . _x( 'Familly name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr( $values['name3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4564 + $furigana .= '<td><span class="member_furigana">' . _x( 'Given name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr( $values['name4'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4565 + }
4566 + $furigana .= '</tr>';
4567 + $formtag .= apply_filters( 'usces_filter_furigana_form', $furigana, $type, $values );
4568 + $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4569 + $formtag .= '<tr id="zipcode_row">
4570 + <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip/Postal Code', 'usces' ) . '</th>
4571 + <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr( $values['zipcode'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . usces_postal_code_address_search( $type ) . apply_filters( 'usces_filter_addressform_zipcode', null, $type ) . apply_filters( 'usces_filter_after_zipcode', '100-1000', $applyform ) . '</td>
2994 4572 </tr>';
2995 - }
2996 -//20131213_kitamura_end
2997 - $formtag .= '<tr>
2998 - <th scope="row">' . usces_get_essential_mark('states', $data).__('Province', 'usces').'</th>
2999 - <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', NULL, $applyform ) . '</td>
3000 - </tr>
3001 - <tr class="inp2">
3002 - <th scope="row">' . usces_get_essential_mark('address1', $data).__('city', 'usces').'</th>
3003 - <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr($values['address1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address1', __('Kitakami Yokohama', 'usces'), $applyform ) . '</td>
3004 - </tr>
3005 - <tr>
3006 - <th scope="row">' . usces_get_essential_mark('address2', $data).__('numbers', 'usces').'</th>
3007 - <td colspan="2"><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr($values['address2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address2', '3-24-555', $applyform ) . '</td>
3008 - </tr>
3009 - <tr>
3010 - <th scope="row">' . usces_get_essential_mark('address3', $data).__('building name', 'usces').'</th>
3011 - <td colspan="2"><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr($values['address3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address3', __('tuhanbuild 4F', 'usces'), $applyform ) . '</td>
3012 - </tr>
3013 - <tr>
3014 - <th scope="row">' . usces_get_essential_mark('tel', $data).__('Phone number', 'usces').'</th>
3015 - <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr($values['tel']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . apply_filters( 'usces_filter_after_tel', '1000-10-1000', $applyform ) . '</td>
3016 - </tr>
3017 - <tr>
3018 - <th scope="row">' . usces_get_essential_mark('fax', $data).__('FAX number', 'usces').'</th>
3019 - <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr($values['fax']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . apply_filters( 'usces_filter_after_fax', '1000-10-1000', $applyform ) . '</td>
3020 - </tr>';
3021 - $formtag .= usces_custom_field_input($data, $type, 'fax_after', 'return');
3022 - break;
3023 -
3024 - case 'CN':
3025 - $formtag .= usces_custom_field_input($data, $type, 'name_pre', 'return');
3026 - $formtag .= '<tr class="inp1">
3027 - <th scope="row">' . usces_get_essential_mark('name1', $data) . __('Full name', 'usces') . '</th>';
3028 - if( $nameform ){
3029 - $formtag .= '<td>' . __('Given name', 'usces') . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3030 - $formtag .= '<td>' . __('Familly name', 'usces') . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3031 - }else{
3032 - $formtag .= '<td>' . __('Familly name', 'usces') . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3033 - $formtag .= '<td>' . __('Given name', 'usces') . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3034 - }
3035 - $formtag .= '</tr>';
3036 - $formtag .= usces_custom_field_input($data, $type, 'name_after', 'return');
3037 -//20131213_kitamura_start
3038 - if( count( $options['system']['target_market'] ) == 1 ){
3039 - $formtag .= '<input type="hidden" name="' .$type. '[country]" id="' .$type. '_country" value="' .$options['system']['target_market'][0]. '">';
3040 - }else{
3041 - $formtag .= '<tr>
3042 - <th scope="row">' . usces_get_essential_mark('country', $data) . __('Country', 'usces') . '</th>
3043 - <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', NULL, $applyform ) . '</td>
4573 + if ( 1 < $target_market_count ) {
4574 + $formtag .= '<tr id="country_row">
4575 + <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4576 + <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4577 + </tr>';
4578 + } else {
4579 + $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . $options['system']['target_market'][0] . '">';
4580 + }
4581 + $formtag .= '<tr id="states_row">
4582 + <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'Province', 'usces' ) . '</th>
4583 + <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4584 + </tr>
4585 + <tr id="address1_row" class="inp2">
4586 + <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4587 + <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr( $values['address1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address1', __( 'Kitakami Yokohama', 'usces' ), $applyform ) . '</td>
4588 + </tr>
4589 + <tr id="address2_row">
4590 + <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'numbers', 'usces' ) . '</th>
4591 + <td colspan="2"><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr( $values['address2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address2', '3-24-555', $applyform ) . '</td>
4592 + </tr>
4593 + <tr id="address3_row">
4594 + <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'building name', 'usces' ) . '</th>
4595 + <td colspan="2"><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr( $values['address3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address3', __( 'tuhanbuild 4F', 'usces' ), $applyform ) . '</td>
4596 + </tr>
4597 + <tr id="tel_row">
4598 + <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4599 + <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr( $values['tel'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . apply_filters( 'usces_filter_after_tel', '1000-10-1000', $applyform ) . '</td>
4600 + </tr>
4601 + <tr id="fax_row">
4602 + <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4603 + <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr( $values['fax'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . apply_filters( 'usces_filter_after_fax', '1000-10-1000', $applyform ) . '</td>
3044 4604 </tr>';
3045 - }
3046 -//20131213_kitamura_end
3047 - $formtag .= '<tr>
3048 - <th scope="row">' . usces_get_essential_mark('states', $data) . __('State', 'usces') . '</th>
3049 - <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', NULL, $applyform ) . '</td>
3050 - </tr>
3051 - <tr class="inp2">
3052 - <th scope="row">' . usces_get_essential_mark('address1', $data) . __('city', 'usces') . '</th>
3053 - <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr($values['address1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address1', NULL, $applyform ) . '</td>
3054 - </tr>
3055 - <tr>
3056 - <th scope="row">' . usces_get_essential_mark('address2', $data) . __('Address Line1', 'usces') . '</th>
3057 - <td colspan="2">' . __('Street address', 'usces') . '<br /><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr($values['address2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address2', NULL, $applyform ) . '</td>
3058 - </tr>
3059 - <tr>
3060 - <th scope="row">' . usces_get_essential_mark('address3', $data) . __('Address Line2', 'usces') . '</th>
3061 - <td colspan="2">' . __('Apartment, building, etc.', 'usces') . '<br /><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr($values['address3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address3', NULL, $applyform ) . '</td>
3062 - </tr>
3063 - <tr>
3064 - <th scope="row">' . usces_get_essential_mark('zipcode', $data) . __('Zip', 'usces') . '</th>
3065 - <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr($values['zipcode']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_zipcode', NULL, $applyform ) . '</td>
3066 - </tr>
3067 - <tr>
3068 - <th scope="row">' . usces_get_essential_mark('tel', $data) . __('Phone number', 'usces') . '</th>
3069 - <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr($values['tel']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_tel', NULL, $applyform ) . '</td>
3070 - </tr>
3071 - <tr>
3072 - <th scope="row">' . usces_get_essential_mark('fax', $data) . __('FAX number', 'usces') . '</th>
3073 - <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr($values['fax']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_fax', NULL, $applyform ) . '</td>
3074 - </tr>';
3075 - $formtag .= usces_custom_field_input($data, $type, 'fax_after', 'return');
3076 - break;
3077 -
3078 - case 'US':
3079 - default :
3080 - $formtag .= usces_custom_field_input($data, $type, 'name_pre', 'return');
3081 - $formtag .= '<tr class="inp1">
3082 - <th scope="row">' . usces_get_essential_mark('name1', $data) . __('Full name', 'usces') . '</th>';
3083 - if( $nameform ){
3084 - $formtag .= '<td>' . __('Given name', 'usces') . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3085 - $formtag .= '<td>' . __('Familly name', 'usces') . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3086 - }else{
3087 - $formtag .= '<td>' . __('Familly name', 'usces') . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3088 - $formtag .= '<td>' . __('Given name', 'usces') . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
3089 - }
3090 - $formtag .= '</tr>';
3091 - $formtag .= usces_custom_field_input($data, $type, 'name_after', 'return');
3092 - $formtag .= '
3093 - <tr>
3094 - <th scope="row">' . usces_get_essential_mark('address2', $data) . __('Address Line1', 'usces') . '</th>
3095 - <td colspan="2">' . __('Street address', 'usces') . '<br /><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr($values['address2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address2', NULL, $applyform ) . '</td>
3096 - </tr>
3097 - <tr>
3098 - <th scope="row">' . usces_get_essential_mark('address3', $data) . __('Address Line2', 'usces') . '</th>
3099 - <td colspan="2">' . __('Apartment, building, etc.', 'usces') . '<br /><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr($values['address3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address3', NULL, $applyform ) . '</td>
3100 - </tr>
3101 - <tr class="inp2">
3102 - <th scope="row">' . usces_get_essential_mark('address1', $data) . __('city', 'usces') . '</th>
3103 - <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr($values['address1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address1', NULL, $applyform ) . '</td>
3104 - </tr>
3105 - <tr>
3106 - <th scope="row">' . usces_get_essential_mark('states', $data) . __('State', 'usces') . '</th>
3107 - <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', NULL, $applyform ) . '</td>
3108 - </tr>';
3109 -//20131213_kitamura_start
3110 - if( count( $options['system']['target_market'] ) == 1 ){
3111 - $formtag .= '<input type="hidden" name="' .$type. '[country]" id="' .$type. '_country" value="' .$options['system']['target_market'][0]. '">';
3112 - }else{
3113 - $formtag .= '<tr>
3114 - <th scope="row">' . usces_get_essential_mark('country', $data) . __('Country', 'usces') . '</th>
3115 - <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', NULL, $applyform ) . '</td>
4605 + $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4606 + break;
4607 +
4608 + case 'CN':
4609 + $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4610 + $formtag .= '<tr id="name_row" class="inp1">
4611 + <th scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4612 + if ( $nameform ) {
4613 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4614 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4615 + } else {
4616 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4617 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4618 + }
4619 + $formtag .= '</tr>';
4620 + $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4621 + if ( 1 < $target_market_count ) {
4622 + $formtag .= '<tr id="country_row">
4623 + <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4624 + <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4625 + </tr>';
4626 + } else {
4627 + $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . $options['system']['target_market'][0] . '">';
4628 + }
4629 + $formtag .= '<tr id="states_row">
4630 + <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'State', 'usces' ) . '</th>
4631 + <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4632 + </tr>
4633 + <tr id="address1_row" class="inp2">
4634 + <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4635 + <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr( $values['address1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address1', null, $applyform ) . '</td>
4636 + </tr>
4637 + <tr id="address2_row">
4638 + <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'Address Line1', 'usces' ) . '</th>
4639 + <td colspan="2">' . __( 'Street address', 'usces' ) . '<br /><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr( $values['address2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address2', null, $applyform ) . '</td>
4640 + </tr>
4641 + <tr id="address3_row">
4642 + <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'Address Line2', 'usces' ) . '</th>
4643 + <td colspan="2">' . __( 'Apartment, building, etc.', 'usces' ) . '<br /><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr( $values['address3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address3', null, $applyform ) . '</td>
4644 + </tr>
4645 + <tr id="zipcode_row">
4646 + <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip', 'usces' ) . '</th>
4647 + <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr( $values['zipcode'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_zipcode', null, $applyform ) . '</td>
4648 + </tr>
4649 + <tr id="tel_row">
4650 + <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4651 + <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr( $values['tel'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_tel', null, $applyform ) . '</td>
4652 + </tr>
4653 + <tr id="fax_row">
4654 + <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4655 + <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr( $values['fax'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_fax', null, $applyform ) . '</td>
3116 4656 </tr>';
3117 - }
3118 -//20131213_kitamura_end
3119 - $formtag .= '<tr>
3120 - <th scope="row">' . usces_get_essential_mark('zipcode', $data) . __('Zip', 'usces') . '</th>
3121 - <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr($values['zipcode']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_zipcode', NULL, $applyform ) . '</td>
3122 - </tr>
3123 - <tr>
3124 - <th scope="row">' . usces_get_essential_mark('tel', $data) . __('Phone number', 'usces') . '</th>
3125 - <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr($values['tel']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_tel', NULL, $applyform ) . '</td>
3126 - </tr>
3127 - <tr>
3128 - <th scope="row">' . usces_get_essential_mark('fax', $data) . __('FAX number', 'usces') . '</th>
3129 - <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr($values['fax']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_fax', NULL, $applyform ) . '</td>
3130 - </tr>';
3131 - $formtag .= usces_custom_field_input($data, $type, 'fax_after', 'return');
3132 - break;
4657 + $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4658 + break;
4659 +
4660 + case 'US':
4661 + default:
4662 + $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4663 + $formtag .= '<tr id="name_row" class="inp1">
4664 + <th scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4665 + if ( $nameform ) {
4666 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4667 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4668 + } else {
4669 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4670 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4671 + }
4672 + $formtag .= '</tr>';
4673 + $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4674 + $formtag .= '
4675 + <tr id="address2_row">
4676 + <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'Address Line1', 'usces' ) . '</th>
4677 + <td colspan="2">' . __( 'Street address', 'usces' ) . '<br /><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr( $values['address2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address2', null, $applyform ) . '</td>
4678 + </tr>
4679 + <tr id="address3_row">
4680 + <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'Address Line2', 'usces' ) . '</th>
4681 + <td colspan="2">' . __( 'Apartment, building, etc.', 'usces' ) . '<br /><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr( $values['address3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address3', null, $applyform ) . '</td>
4682 + </tr>
4683 + <tr id="address1_row" class="inp2">
4684 + <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4685 + <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr( $values['address1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address1', null, $applyform ) . '</td>
4686 + </tr>
4687 + <tr id="states_row">
4688 + <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'State', 'usces' ) . '</th>
4689 + <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4690 + </tr>';
4691 + if ( 1 < $target_market_count ) {
4692 + $formtag .= '<tr id="country_row">
4693 + <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4694 + <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4695 + </tr>';
4696 + } else {
4697 + $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . esc_attr( $options['system']['target_market'][0] ) . '">';
4698 + }
4699 + $formtag .= '<tr id="zipcode_row">
4700 + <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip', 'usces' ) . '</th>
4701 + <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr( $values['zipcode'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_zipcode', null, $applyform ) . '</td>
4702 + </tr>
4703 + <tr id="tel_row">
4704 + <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4705 + <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr( $values['tel'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_tel', null, $applyform ) . '</td>
4706 + </tr>
4707 + <tr id="fax_row">
4708 + <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4709 + <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr( $values['fax'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_fax', null, $applyform ) . '</td>
4710 + </tr>';
4711 + $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4712 + break;
3133 4713 }
3134 - $res = apply_filters('usces_filter_apply_addressform', $formtag, $type, $data);
3135 -
4714 + $res = apply_filters( 'usces_filter_apply_addressform', $formtag, $type, $data );
3136 4715 }
3137 4716
3138 - if($out == 'return') {
4717 + if ( 'return' === $out ) {
3139 4718 return $res;
3140 4719 } else {
3141 - echo $res;
4720 + echo $res; // no escape due to filter.
3142 4721 }
3143 4722 }
3144 4723
3145 -function usces_item_option_fileds( $post_id, $sku, $label=1, $out='echo' ){
3146 - $options = usces_get_opts($post_id, 'sort');
3147 - if( 0 == count($options) )
4724 +/**
4725 + * Item option field
4726 + *
4727 + * @param int $post_id Post ID.
4728 + * @param string $sku SKU code.
4729 + * @param int $label Tabel.
4730 + * @param string $out Return value or echo.
4731 + * @return string|void
4732 + */
4733 +function usces_item_option_fileds( $post_id, $sku, $label = 1, $out = 'echo' ) {
4734 + $options = wel_get_opts( $post_id, 'sort' );
4735 + if ( ! $options || ! is_array( $options ) ) {
3148 4736 return false;
3149 -
3150 - $sku_enc = urlencode($sku);
3151 - $html ='';
3152 - foreach( $options as $opt ){
3153 - $name = $opt['name'];
3154 - $opt_code = urlencode($name);
3155 - $html .= "\n" . '<div class="opt_field" id="opt_' . $post_id . '_' . $sku_enc . '_' . $opt_code . '">';
3156 - if( $label ){
3157 - $html .= '<label for="itemOption[' . $post_id . '][' . $sku_enc . '][' . $opt_code . ']">' . esc_html($name) . '</label>';
4737 + }
4738 + if ( 0 === count( $options ) ) {
4739 + return false;
4740 + }
4741 + $sku_enc = urlencode( $sku );
4742 +
4743 + $html = '';
4744 + foreach ( $options as $opt ) {
4745 + $name = $opt['name'];
4746 + $opt_code = urlencode( $name );
4747 + $html .= '<div class="opt_field" id="opt_' . $post_id . '_' . $sku_enc . '_' . $opt_code . '">';
4748 + if ( $label ) {
4749 + $html .= '<label for="itemOption[' . $post_id . '][' . $sku_enc . '][' . $opt_code . ']">' . esc_html( $name ) . '</label>';
3158 4750 }
3159 - $html .= usces_get_itemopt_filed($post_id, $sku, $opt);
4751 + $html .= usces_get_itemopt_filed( $post_id, $sku, $opt );
3160 4752 $html .= '</div>';
3161 4753 }
3162 - if( $out == 'return' ){
3163 - return $html;
3164 - }else{
3165 - echo $html;
4754 + if ( 'return' === $out ) {
4755 + return wel_esc_script( $html );
4756 + } else {
4757 + wel_esc_script_e( $html );
3166 4758 }
3167 4759 }
3168 4760
3169 -function usces_facebook_like(){
4761 +/**
4762 + * Facebook
4763 + */
4764 +function usces_facebook_like() {
3170 4765 global $post, $usces;
3171 4766 $like = array(
3172 - 'url' => urlencode(get_permalink($post->ID)),
3173 - 'send' => 'false',
3174 - 'layout' => 'button_count', //standard, button_count, box_count
3175 - 'width' => '450',
3176 - 'height' => '35',
3177 - 'show_faces' => 'false',
3178 - 'action' => 'like', //like, recommend
4767 + 'url' => urlencode( get_permalink( $post->ID ) ),
4768 + 'send' => 'false',
4769 + 'layout' => 'button_count', /* standard, button_count, box_count */
4770 + 'width' => '450',
4771 + 'height' => '35',
4772 + 'show_faces' => 'false',
4773 + 'action' => 'like', /* like, recommend */
3179 4774 );
3180 4775 $like = apply_filters( 'usces_filter_facebook_like', $like, $post->ID );
3181 -?>
3182 -<iframe src="//www.facebook.com/plugins/like.php?href=<?php echo $like['url']; ?>&amp;send=<?php echo $like['send']; ?>&amp;layout=<?php echo $like['layout']; ?>&amp;width=<?php echo $like['width']; ?>&amp;show_faces=<?php echo $like['show_faces']; ?>&amp;action=<?php echo $like['action']; ?>&amp;colorscheme=light&amp;font=arial&amp;height=<?php echo $like['height']; ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:<?php echo $like['width']; ?>px; height:<?php echo $like['height']; ?>px;" allowTransparency="true"></iframe>
3183 -<?php
4776 + ?>
4777 +<iframe src="//www.facebook.com/plugins/like.php?href=<?php echo esc_url( $like['url'] ); ?>&amp;send=<?php echo esc_attr( $like['send'] ); ?>&amp;layout=<?php echo esc_attr( $like['layout'] ); ?>&amp;width=<?php echo esc_attr( $like['width'] ); ?>&amp;show_faces=<?php echo esc_attr( $like['show_faces'] ); ?>&amp;action=<?php echo esc_attr( $like['action'] ); ?>&amp;colorscheme=light&amp;font=arial&amp;height=<?php echo esc_attr( $like['height'] ); ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:<?php echo esc_attr( $like['width'] ); ?>px; height:<?php echo esc_attr( $like['height'] ); ?>px;" allowTransparency="true"></iframe>
4778 + <?php
3184 4779 }
3185 4780
3186 -function usces_action_confirm_page_point_inform_zeus() {
3187 - $html = usces_point_inform_zeus();
3188 - echo $html;
4781 +/**
4782 + * Checked
4783 + *
4784 + * @param string $chk Checked.
4785 + * @param string $key Key.
4786 + * @param string $out Return value or echo.
4787 + * @return string|void
4788 + */
4789 +function usces_checked( $chk, $key, $out = '' ) {
4790 + $checked = ( isset( $chk[ $key ] ) && 1 === (int) $chk[ $key ] );
4791 + if ( 'return' === $out ) {
4792 + return checked( $checked, true, false );
4793 + } else {
4794 + checked( $checked, true, true );
4795 + }
3189 4796 }
3190 4797
3191 -function usces_filter_confirm_point_inform_zeus( $html ) {
3192 - $html .= usces_point_inform_zeus();
3193 - return $html;
4798 +/**
4799 + * Custom field value
4800 + *
4801 + * @param string $field Field.
4802 + * @param string $key Key.
4803 + * @param string $id ID.
4804 + * @param string $out Return value or echo.
4805 + * @return string|void
4806 + */
4807 +function usces_get_custom_field_value( $field, $key, $id, $out = '' ) {
4808 + global $usces;
4809 +
4810 + $value = '';
4811 + switch ( $field ) {
4812 + case 'order':
4813 + $value = $usces->get_order_meta_value( 'csod_' . $key, $id );
4814 + break;
4815 + case 'customer':
4816 + $value = $usces->get_order_meta_value( 'cscs_' . $key, $id );
4817 + break;
4818 + case 'delivery':
4819 + $value = $usces->get_order_meta_value( 'csde_' . $key, $id );
4820 + break;
4821 + case 'member':
4822 + $value = $usces->get_member_meta_value( 'csmb_' . $key, $id );
4823 + break;
4824 + }
4825 +
4826 + if ( 'return' === $out ) {
4827 + return wel_esc_script( $value );
4828 + } else {
4829 + wel_esc_script_e( $value );
4830 + }
3194 4831 }
3195 4832
3196 -function usces_point_inform_zeus() {
3197 - global $usces, $usces_entries;
4833 +/**
4834 + * Address search button
4835 + *
4836 + * @param string $type Type.
4837 + * @param string $out Return value or echo.
4838 + * @return string|void
4839 + */
4840 +function usces_postal_code_address_search( $type, $out = 'return' ) {
4841 + global $usces;
4842 +
3198 4843 $html = '';
4844 + if ( isset( $usces->options['address_search'] ) && 'activate' === $usces->options['address_search'] ) {
4845 + $address_search_label = apply_filters( 'usces_filter_postal_code_address_search_label', '住所検索' );
4846 + $html = '<input type="button" id="search_zipcode" class="search-zipcode button" value="' . $address_search_label . '" onClick="AjaxZip3.zip2addr(\'' . esc_js( $type . '[zipcode]' ) . '\', \'\', \'' . esc_js( $type . '[pref]' ) . '\', \'' . esc_js( $type . '[address1]' ) . '\' );" >';
4847 + if ( 'delivery' === $type ) {
4848 + $entry = $usces->cart->get_entry();
4849 + $zipcode = ( isset( $entry['delivery']['zipcode'] ) ) ? $entry['delivery']['zipcode'] : '';
4850 + $html .= '<input type="hidden" id="search_zipcode_change" value="' . esc_attr( $zipcode ) . '">';
4851 + }
4852 + }
4853 + if ( 'return' === $out ) {
4854 + return wel_esc_script( $html );
4855 + } else {
4856 + wel_esc_script_e( $html );
4857 + }
4858 +}
3199 4859
3200 - $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
3201 - $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
4860 +/**
4861 + * Agreement Approval Field
4862 + *
4863 + * @param string $out Return value or echo.
4864 + * @return string|void
4865 + */
4866 +function usces_agree_member_field( $out = '' ) {
4867 + global $usces;
3202 4868
3203 - switch( $acting_flag ) {
3204 - case 'acting_zeus_card':
3205 - $html .= '<input type="hidden" name="cnum1" value="'.esc_attr($_POST['cnum1']).'">';
3206 - if( isset($_POST['securecode']) ) {
3207 - $html .= '<input type="hidden" name="securecode" value="'.esc_attr($_POST['securecode']).'">';
4869 + $html = '';
4870 + if ( usces_is_membersystem_state() ) {
4871 + $row = '';
4872 + if ( isset( $usces->options['agree_member'] ) && 'activate' === $usces->options['agree_member'] ) {
4873 + $row .= '<div class="agree_member_area">';
4874 + if ( isset( $usces->options['member_page_data']['agree_member_exp'] ) ) {
4875 + $row .= '<div class="at_exp_text">' . stripslashes( nl2br( $usces->options['member_page_data']['agree_member_exp'] ) ) . '</div>';
4876 + }
4877 + if ( isset( $usces->options['member_page_data']['agree_member_cont'] ) ) {
4878 + $row .= '<textarea name="at_cont_text" class="at_cont_text" readonly="readonly">' . $usces->options['member_page_data']['agree_member_cont'] . '</textarea>
4879 + <div class="at_check_area"><input name="agree_member_check" value="1" id="agree_member_check" class="at_check" type="checkbox"><label for="agree_member_check" style="cursor:pointer;"> ' . __( 'Accept the membership agreement', 'usces' ) . '</label></div>';
4880 + }
4881 + $row .= '</div>';
3208 4882 }
3209 - $html .= '<input type="hidden" name="expyy" value="'.esc_attr($_POST['expyy']).'">';
3210 - $html .= '<input type="hidden" name="expmm" value="'.esc_attr($_POST['expmm']).'">';
3211 - $html .= '<input type="hidden" name="username_card" value="'.esc_attr($_POST['username_card']).'">';
3212 - if( isset($usces_entries['order']['howpay']) ) {
3213 - $html .= '<input type="hidden" name="offer[howpay]" value="'.esc_attr($usces_entries['order']['howpay']).'">';
4883 + $html = apply_filters( 'usces_filter_agree_member_field', $row );
4884 + }
4885 +
4886 + if ( 'return' === $out ) {
4887 + return wel_esc_script( $html );
4888 + } else {
4889 + wel_esc_script_e( $html );
4890 + }
4891 +}
4892 +
4893 +/**
4894 + * No image
4895 + *
4896 + * @param array $size Size.
4897 + * @param string $alt Alt.
4898 + * @return string
4899 + */
4900 +function usces_get_attachment_noimage( $size = array( 60, 60 ), $alt = '' ) {
4901 + $size_class = join( 'x', $size );
4902 + return '<img width="' . $size[0] . '" height="' . $size[1] . '" src="' . USCES_PLUGIN_URL . '/images/default.png" class="attachment-' . $size_class . ' size-' . $size_class . '" alt="' . $alt . '">';
4903 +}
4904 +
4905 +/**
4906 + * Tax rate
4907 + *
4908 + * @param string $out Return value or echo.
4909 + * @return string|void
4910 + */
4911 +function usces_the_taxrate( $out = '' ) {
4912 + global $usces;
4913 +
4914 + if ( isset( $usces->itemsku['taxrate'] ) ) {
4915 + $taxrate = ( 'reduced' === $usces->itemsku['taxrate'] ) ? $usces->options['tax_rate_reduced'] : $usces->options['tax_rate'];
4916 + } else {
4917 + $taxrate = $usces->options['tax_rate'];
4918 + }
4919 + $the_taxrate = '<em class="tax">' . sprintf( __( "Tax Rate %s%%", 'usces' ), $taxrate ) . '</em>';
4920 + $the_taxrate = apply_filters( 'usces_filter_the_taxrate', $the_taxrate, $usces->itemsku, $out );
4921 +
4922 + if ( 'return' === $out ) {
4923 + return wel_esc_script( $the_taxrate );
4924 + } else {
4925 + wel_esc_script_e( $the_taxrate );
4926 + }
4927 +}
4928 +
4929 +/**
4930 + * Tax amount
4931 + *
4932 + * @param string $out Return value or echo.
4933 + * @return string|void
4934 + */
4935 +function usces_cart_tax( $out = '' ) {
4936 + global $usces;
4937 +
4938 + $total_items_price = $usces->get_total_price();
4939 + $materials = array(
4940 + 'total_items_price' => $total_items_price,
4941 + 'discount' => 0,
4942 + 'shipping_charge' => 0,
4943 + 'cod_fee' => 0,
4944 + 'use_point' => 0,
4945 + );
4946 + $tax = $usces->getTax( $total_items_price, $materials );
4947 +
4948 + if ( 'return' === $out ) {
4949 + return wel_esc_script( $tax );
4950 + } else {
4951 + wel_esc_script_e( $tax );
4952 + }
4953 +}
4954 +
4955 +/**
4956 + * Total tax amount
4957 + *
4958 + * @param string $out Return value or echo.
4959 + * @return string|void
4960 + */
4961 +function usces_confirm_tax( $out = '' ) {
4962 + global $usces;
4963 +
4964 + if ( $usces->is_reduced_taxrate() ) {
4965 + if ( 'include' === $usces->options['tax_mode'] ) {
4966 + $po = '( ';
4967 + $pc = ' )';
4968 + } else {
4969 + $po = '';
4970 + $pc = '';
3214 4971 }
3215 - if( isset($usces_entries['order']['cbrand']) ) {
3216 - $html .= '<input type="hidden" name="offer[cbrand]" value="'.esc_attr($usces_entries['order']['cbrand']).'">';
3217 - $html .= '<input type="hidden" name="offer[div_1]" value="'.esc_attr($usces_entries['order']['div_1']).'">';
3218 - $html .= '<input type="hidden" name="offer[div_2]" value="'.esc_attr($usces_entries['order']['div_2']).'">';
3219 - $html .= '<input type="hidden" name="offer[div_3]" value="'.esc_attr($usces_entries['order']['div_3']).'">';
4972 + $usces_tax = Welcart_Tax::get_instance();
4973 + $entry = wel_get_entry();
4974 + $shipping_charge = isset( $entry['order']['shipping_charge'] ) ? $entry['order']['shipping_charge'] : 0;
4975 + $cod_fee = isset( $entry['order']['cod_fee'] ) ? $entry['order']['cod_fee'] : 0;
4976 + $materials = compact( 'shipping_charge', 'cod_fee');
4977 + $usces_tax->get_order_tax( $materials );
4978 + $tax = sprintf( __( "Applies to %s%%", 'usces' ), $usces->options['tax_rate'] ) . '&nbsp;&nbsp;' . usces_crform( $usces_tax->subtotal_standard + $usces_tax->discount_standard, true, false, 'return' ) . '&nbsp;&nbsp;';
4979 + $tax .= sprintf( __( "%s%% consumption tax", 'usces' ), $usces->options['tax_rate'] ) . '&nbsp;&nbsp;' . $po . usces_crform( $usces_tax->tax_standard, true, false, 'return' ) . $pc . '<br />';
4980 + if ( 0 < $usces_tax->tax_rate_reduced ) {
4981 + $tax .= sprintf( __( "Applies to %s%%", 'usces' ), $usces->options['tax_rate_reduced'] ) . '&nbsp;&nbsp;' . usces_crform( $usces_tax->subtotal_reduced + $usces_tax->discount_reduced, true, false, 'return' ) . '&nbsp;&nbsp;';
4982 + $tax .= sprintf( __( "%s%% consumption tax", 'usces' ), $usces->options['tax_rate_reduced'] ) . '&nbsp;&nbsp;' . $po . usces_crform( $usces_tax->tax_reduced, true, false, 'return' ) . $pc;
3220 4983 }
3221 - break;
4984 + } else {
4985 + $tax = '';
4986 + }
3222 4987
3223 - case 'acting_zeus_conv':
3224 - if( isset($_POST['pay_cvs']) ) {
3225 - $html .= '<input type="hidden" name="offer[pay_cvs]" value="'.esc_attr($usces_entries['order']['pay_cvs']).'">';
3226 - $html .= '<input type="hidden" name="username_conv" value="'.esc_attr($_POST['username_conv']).'">';
4988 + $tax = apply_filters( 'usces_filter_confirm_tax', $tax, $out );
4989 +
4990 + if ( 'return' === $out ) {
4991 + return wel_esc_script( $tax );
4992 + } else {
4993 + wel_esc_script_e( $tax );
4994 + }
4995 +}
4996 +
4997 +/**
4998 + * Tax-included amount
4999 + *
5000 + * @param string $out Return value or echo.
5001 + * @return string|void
5002 + */
5003 +function usces_the_itemPrice_taxincluded( $out = '' ) {
5004 + global $post, $usces;
5005 + $usces_tax = Welcart_Tax::get_instance();
5006 +
5007 + if ( empty( $usces->itemsku['code'] ) ) {
5008 + $skus = $usces->get_skus( $post->ID );
5009 + $skucode = $skus[0]['code'];
5010 + $skuprice = $skus[0]['price'];
5011 + } else {
5012 + $skucode = $usces->itemsku['code'];
5013 + $skuprice = $usces->itemsku['price'];
5014 + }
5015 + $tax_rate = $usces_tax->get_sku_tax_rate( $post->ID, $skucode );
5016 + $tax = (float) sprintf( '%.3f', (float) $skuprice * (float) $tax_rate / 100 );
5017 + $tax = usces_tax_rounding_off( $tax );
5018 + $price = $skuprice + $tax;
5019 +
5020 + if ( 'return' === $out ) {
5021 + return $price;
5022 + } else {
5023 + echo number_format( $price );
5024 + }
5025 +}
5026 +
5027 +/**
5028 + * Tax-included normal amount
5029 + *
5030 + * @param string $out Return value or echo.
5031 + * @return string|void
5032 + */
5033 +function usces_the_itemCprice_taxincluded( $out = '' ) {
5034 + global $post, $usces;
5035 + $usces_tax = Welcart_Tax::get_instance();
5036 +
5037 + if ( empty( $usces->itemsku['code'] ) ) {
5038 + $skus = $usces->get_skus( $post->ID );
5039 + $skucode = $skus[0]['code'];
5040 + $skucprice = $skus[0]['cprice'];
5041 + } else {
5042 + $skucode = $usces->itemsku['code'];
5043 + $skucprice = $usces->itemsku['cprice'];
5044 + }
5045 + $tax_rate = $usces_tax->get_sku_tax_rate( $post->ID, $skucode );
5046 + $tax = (float) sprintf( '%.3f', (float) $skucprice * (float) $tax_rate / 100 );
5047 + $tax = usces_tax_rounding_off( $tax );
5048 + $price = $skucprice + $tax;
5049 + if ( 'return' === $out ) {
5050 + return $price;
5051 + } else {
5052 + echo number_format( $price );
5053 + }
5054 +}
5055 +
5056 +/**
5057 + * Formatted tax included amount
5058 + *
5059 + * @param string $out Return value or echo.
5060 + * @return string|void
5061 + */
5062 +function usces_the_itemPriceCr_taxincluded( $out = '' ) {
5063 + global $usces;
5064 + $usces_tax = Welcart_Tax::get_instance();
5065 +
5066 + $price_taxincluded = usces_the_itemPrice_taxincluded( 'return' );
5067 + $price = $usces->get_currency( $price_taxincluded, true, false );
5068 + $price = apply_filters( 'usces_filter_the_item_price_cr_taxincluded', $price, $price_taxincluded, $out );
5069 + if ( 'return' === $out ) {
5070 + return $price;
5071 + } else {
5072 + echo esc_html( $price );
5073 + }
5074 +}
5075 +
5076 +/**
5077 + * Formatted tax included normal amount
5078 + *
5079 + * @param string $out Return value or echo.
5080 + * @return string|void
5081 + */
5082 +function usces_the_itemCpriceCr_taxincluded( $out = '' ) {
5083 + global $usces;
5084 + $usces_tax = Welcart_Tax::get_instance();
5085 +
5086 + $price_taxincluded = usces_the_itemCprice_taxincluded( 'return' );
5087 + $price = $usces->get_currency( $price_taxincluded, true, false );
5088 + $price = apply_filters( 'usces_filter_the_item_cprice_cr_taxincluded', $price, $price_taxincluded, $out );
5089 + if ( 'return' === $out ) {
5090 + return $price;
5091 + } else {
5092 + echo esc_html( $price );
5093 + }
5094 +}
5095 +
5096 +/**
5097 + * Password policy
5098 + *
5099 + * @param string $out Return value or echo.
5100 + * @return string|void
5101 + */
5102 +function usces_password_policy_message( $out = '' ) {
5103 +
5104 + $usces_options = get_option( 'usces', array() );
5105 + $rules = array();
5106 + $sep = '';
5107 +
5108 + if ( ! empty( $usces_options['system']['member_pass_rule_max'] ) ) {
5109 + if ( $usces_options['system']['member_pass_rule_max'] === $usces_options['system']['member_pass_rule_min'] ) {
5110 + $rules[] = sprintf( __( '%s characters long', 'usces' ), $usces_options['system']['member_pass_rule_min'] );
5111 + } else {
5112 + $rules[] = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $usces_options['system']['member_pass_rule_min'], $usces_options['system']['member_pass_rule_max'] );
5113 + $sep = __( 'use', 'usces' );
3227 5114 }
3228 - break;
5115 + } else {
5116 + $rules[] = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $usces_options['system']['member_pass_rule_min'], '30' );
5117 + $sep = __( 'use', 'usces' );
3229 5118 }
3230 - return $html;
5119 +
5120 + $and = __( 'and', 'usces' );
5121 +
5122 + if ( ! empty( $usces_options['system']['member_pass_rule_digit'] ) ) {
5123 + $rules[] = __( 'numeric character', 'usces' );
5124 + }
5125 +
5126 + if ( ! empty( $usces_options['system']['member_pass_rule_lowercase'] ) ) {
5127 + $rules[] = __( 'lower-case alphabetics', 'usces' );
5128 + }
5129 +
5130 + if ( ! empty( $usces_options['system']['member_pass_rule_upercase'] ) ) {
5131 + $rules[] = __( 'upper-case alphabetics', 'usces' );
5132 + }
5133 +
5134 + if ( ! empty( $usces_options['system']['member_pass_rule_symbol'] ) ) {
5135 + $rules[] = __( 'symbolic character', 'usces' );
5136 + }
5137 +
5138 + $first = array_shift( $rules );
5139 + $ret = '';
5140 + if ( 0 === count( $rules ) ) {
5141 + $ret = sprintf( __( 'Password must be at least %s.', 'usces' ), $first );
5142 + } elseif ( 1 === count( $rules ) ) {
5143 + $rule1 = sprintf( __( ' and include one or more %s', 'usces' ), $rules[0] );
5144 + $ret = sprintf( __( 'Password must be at least %1$s%2$s.', 'usces' ), $first, $rule1 );
5145 + } else {
5146 + $rule2 = '';
5147 + foreach ( $rules as $rule ) {
5148 + if ( '' !== $rule2 ) {
5149 + $rule2 .= __( ',', 'usces' );
5150 + }
5151 + $rule2 .= $rule;
5152 + }
5153 + $rule1 = sprintf( __( ' and include one or more %s', 'usces' ), $rule2 );
5154 + $ret = sprintf( __( 'Password must be at least %1$s%2$s.', 'usces' ), $first, $rule1 );
5155 + }
5156 +
5157 + $ret = apply_filters( 'usces_filter_password_policy_message', $ret );
5158 + if ( 'return' === $out ) {
5159 + return $ret;
5160 + }
5161 +
5162 + echo '<p class="password_policy">' . esc_html( $ret ) . '</p>';
3231 5163 }
3232 5164
3233 -function usces_checked( $chk, $key, $out = '' ) {
3234 - $checked = ( isset($chk[$key]) and $chk[$key] == 1 ) ? ' checked' : '';
3235 - if( $out == 'return' ) {
3236 - return $checked;
5165 +/**
5166 + * Formatted tax included amount
5167 + *
5168 + * @param bool $label_pre Forward label.
5169 + * @param string $label Label.
5170 + * @param string $start_tag Start tag.
5171 + * @param string $end_tag End tag.
5172 + * @param bool $symbol_pre Forward symbol.
5173 + * @param bool $symbol_post Backward symbol.
5174 + * @param bool $seperator_flag Seperator.
5175 + * @param string $out Return value or echo.
5176 + * @return string|void
5177 + */
5178 +function usces_crform_the_itemPriceCr_taxincluded( $label_pre = true, $label = '', $start_tag = '', $end_tag = '', $symbol_pre = true, $symbol_post = false, $seperator_flag = true, $out = '' ) {
5179 + global $usces;
5180 +
5181 + if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
5182 + $res = '';
3237 5183 } else {
3238 - echo $checked;
5184 + $price_taxincluded = usces_the_itemPrice_taxincluded( 'return' );
5185 + $price = esc_html( $usces->get_currency( $price_taxincluded, $symbol_pre, $symbol_post, $seperator_flag ) );
5186 + if ( empty( $label ) ) {
5187 + $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
5188 + } else {
5189 + $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
5190 + }
5191 + if ( empty( $start_tag ) ) {
5192 + $start_tag = '<p class="tax_inc_block">( ';
5193 + }
5194 + if ( $label_pre ) {
5195 + $start_tag = $start_tag . $label_tag;
5196 + }
5197 + if ( empty( $end_tag ) ) {
5198 + $end_tag = ' )</p>';
5199 + }
5200 + if ( true !== $label_pre ) {
5201 + $end_tag = $label_tag . $end_tag;
5202 + }
5203 + $res = apply_filters( 'usces_filter_crform_the_itemPriceCr_taxincluded', $start_tag . $price . $end_tag, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
3239 5204 }
5205 + if ( 'return' === $out ) {
5206 + return wel_esc_script( $res );
5207 + } else {
5208 + wel_esc_script_e( $res );
5209 + }
3240 5210 }
3241 5211
3242 -function usces_get_custom_field_value( $field, $key, $id, $out = '' ) {
5212 +/**
5213 + * Tax-included amount
5214 + *
5215 + * @param int $post_id Post ID.
5216 + * @return float
5217 + */
5218 +function usces_itemPrice_taxincluded( $post_id = null ) {
3243 5219 global $usces;
3244 5220
3245 - $value = '';
3246 - switch( $field ) {
3247 - case 'order':
3248 - $value = $usces->get_order_meta_value( 'csod_'.$key, $id );
3249 - break;
3250 - case 'customer':
3251 - $value = $usces->get_order_meta_value( 'cscs_'.$key, $id );
3252 - break;
3253 - case 'delivery':
3254 - $value = $usces->get_order_meta_value( 'csde_'.$key, $id );
3255 - break;
3256 - case 'member':
3257 - $value = $usces->get_member_meta_value( 'csmb_'.$key, $id );
3258 - break;
5221 + if ( null === $post_id ) {
5222 + global $post;
5223 + $post_id = $post->ID;
3259 5224 }
5225 + $usces_tax = Welcart_Tax::get_instance();
3260 5226
3261 - if( $out == 'return' ) {
3262 - return $value;
5227 + $skus = $usces->get_skus( $post_id );
5228 + $skucode = $skus[0]['code'];
5229 + $skuprice = $skus[0]['price'];
5230 + $tax_rate = $usces_tax->get_sku_tax_rate( $post_id, $skucode );
5231 + $tax = (float) sprintf( '%.3f', (float) $skuprice * (float) $tax_rate / 100 );
5232 + $tax = usces_tax_rounding_off( $tax );
5233 + $price = $skuprice + $tax;
5234 + return $price;
5235 +}
5236 +
5237 +/**
5238 + * Tax-included normal amount
5239 + *
5240 + * @param int $post_id Post ID.
5241 + * @param bool $label_pre Forward label.
5242 + * @param string $label Label.
5243 + * @param string $start_tag Start tag.
5244 + * @param string $end_tag End tag.
5245 + * @param bool $symbol_pre Forward symbol.
5246 + * @param bool $symbol_post Backward symbol.
5247 + * @param bool $seperator_flag Seperator.
5248 + * @return string
5249 + */
5250 +function usces_crform_itemPriceCr_taxincluded( $post_id = null, $label_pre = true, $label = '', $start_tag = '', $end_tag = '', $symbol_pre = true, $symbol_post = false, $seperator_flag = true ) {
5251 + global $usces;
5252 +
5253 + if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
5254 + $res = '';
3263 5255 } else {
3264 - echo $value;
5256 + $price_taxincluded = usces_itemPrice_taxincluded( $post_id );
5257 + $price = esc_html( $usces->get_currency( $price_taxincluded, $symbol_pre, $symbol_post, $seperator_flag ) );
5258 + if ( empty( $label ) ) {
5259 + $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
5260 + } else {
5261 + $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
5262 + }
5263 + if ( empty( $start_tag ) ) {
5264 + $start_tag = '<p class="tax_inc_block">( ';
5265 + }
5266 + if ( $label_pre ) {
5267 + $start_tag = $start_tag . $label_tag;
5268 + }
5269 + if ( empty( $end_tag ) ) {
5270 + $end_tag = ' )</p>';
5271 + }
5272 + if ( true !== $label_pre ) {
5273 + $end_tag = $label_tag . $end_tag;
5274 + }
5275 + $res = apply_filters( 'usces_filter_crform_itemPriceCr_taxincluded', $start_tag . $price . $end_tag, $post_id, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
3265 5276 }
5277 + return $res;
3266 5278 }
3267 5279
3268 -?>
5280 +/**
5281 + * Cart Totals
5282 + *
5283 + * @param string $out Return value or echo.
5284 + * @return string|void
5285 + */
5286 +function usces_get_cart_total_rows( $out = '' ) {
5287 + global $usces;
5288 +
5289 + $res = '';
5290 + if ( isset( $usces->options['tax_display'] ) && 'deactivate' !== $usces->options['tax_display'] ) {
5291 + if ( isset( $usces->options['tax_mode'] ) && 'include' !== $usces->options['tax_mode'] ) {
5292 + $total = usces_total_price( 'return' );
5293 + $tax = usces_cart_tax( 'return' );
5294 + $res .= ' <tr>
5295 + <th class="num"></th>
5296 + <th class="thumbnail"></th>
5297 + <th colspan="3" scope="row" class="aright">' . __( 'Total', 'usces' ) . '</th>
5298 + <th class="aright amount">' . usces_crform( $total, true, false, true ) . '</th>
5299 + <th class="stock"></th>
5300 + <th class="action"></th>
5301 + </tr>' . "\n";
5302 + $res .= ' <tr class="tax">
5303 + <th class="num"></th>
5304 + <th class="thumbnail"></th>
5305 + <th colspan="3" scope="row" class="aright tax">' . __( 'Tax', 'usces' ) . '</th>
5306 + <th class="aright amount tax">' . usces_crform( usces_cart_tax( 'return' ), true, false, true ) . '</th>
5307 + <th class="stock"></th>
5308 + <th class="action"></th>
5309 + </tr>' . "\n";
5310 + $res .= ' <tr>
5311 + <th class="num"></th>
5312 + <th class="thumbnail"></th>
5313 + <th colspan="3" scope="row" class="aright">' . __( 'total items', 'usces' ) . '</th>
5314 + <th class="aright amount">' . usces_crform( $total + $tax, true, false, true ) . '</th>
5315 + <th class="stock"></th>
5316 + <th class="action"></th>
5317 + </tr>' . "\n";
5318 + } else {
5319 + $total = usces_total_price( 'return' );
5320 + $tax = usces_internal_tax( array( 'total_items_price' => $total ), 'return' );
5321 + $res .= ' <tr class="tax">
5322 + <th class="num"></th>
5323 + <th class="thumbnail"></th>
5324 + <th colspan="3" scope="row" class="aright tax">' . __( 'Internal tax', 'usces' ) . '</th>
5325 + <th class="aright amount tax">( ' . usces_crform( $tax, true, false, true ) . ' )</th>
5326 + <th class="stock"></th>
5327 + <th class="action"></th>
5328 + </tr>' . "\n";
5329 + $res .= ' <tr>
5330 + <th class="num"></th>
5331 + <th class="thumbnail"></th>
5332 + <th colspan="3" scope="row" class="aright">' . __( 'total items', 'usces' ) . '</th>
5333 + <th class="aright amount">' . usces_crform( $total, true, false, true ) . '</th>
5334 + <th class="stock"></th>
5335 + <th class="action"></th>
5336 + </tr>' . "\n";
5337 + }
5338 + }
5339 + if ( 'return' === $out ) {
5340 + return wel_esc_script( $res );
5341 + } else {
5342 + wel_esc_script_e( $res );
5343 + }
5344 +}
5345 +
5346 +if ( ! function_exists( 'welcart_assistance_excerpt_length' ) ) {
5347 + /**
5348 + * Assistance excerpt length
5349 + *
5350 + * @param int $length Length.
5351 + * @return int
5352 + */
5353 + function welcart_assistance_excerpt_length( $length ) {
5354 + return 10;
5355 + }
5356 +}
5357 +
5358 +if ( ! function_exists( 'welcart_assistance_excerpt_mblength' ) ) {
5359 + /**
5360 + * Assistance excerpt mobile length
5361 + *
5362 + * @param int $length Length.
5363 + * @return int
5364 + */
5365 + function welcart_assistance_excerpt_mblength( $length ) {
5366 + return 40;
5367 + }
5368 +}