PluginProbe
Welcart e-Commerce / 2.11.31
Welcart e-Commerce v2.11.31
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
usc-e-shop / functions / template_func.php

template_func.php in Welcart e-Commerce 2.11.31, at functions/template_func.php

5,368 lines 189.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
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 ) {
16 global $usces;
17
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 }
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 }
49 }
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 = 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 = 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' => 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 */
264 function usces_currency_symbol( $out = '' ) {
265 global $usces;
266
267 if ( 'return' === $out ) {
268 return $usces->getCurrencySymbol();
269 } else {
270 echo esc_html( $usces->getCurrencySymbol() );
271 }
272 }
273
274 /**
275 * Error Verification
276 *
277 * @return bool
278 */
279 function usces_is_error_message() {
280 global $usces;
281
282 if ( '' !== $usces->error_message ) {
283 return true;
284 } else {
285 return false;
286 }
287 }
288
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 ) {
297 global $post;
298 if ( empty( $post->ID ) ) {
299 return false;
300 }
301 $post_id = $post->ID;
302 }
303 $product = wel_get_product( $post_id );
304 if ( isset( $product['_pst'] ) && 'item' === $product['_pst']->post_mime_type ) {
305 return true;
306 } else {
307 return false;
308 }
309 }
310
311 /**
312 * Item code
313 *
314 * @param string $out Return value or echo.
315 * @return string|void
316 */
317 function usces_the_itemCode( $out = '' ) {
318 global $post;
319
320 $product = wel_get_product( $post->ID );
321 $str = $product['itemCode'];
322
323 if ( 'return' === $out ) {
324 return $str;
325 } else {
326 echo esc_html( $str );
327 }
328 }
329
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 ) {
339 global $post;
340 }
341
342 $product = wel_get_product( $post );
343 $str = $product['itemName'];
344
345 if ( 'return' === $out ) {
346 return $str;
347 } else {
348 echo esc_html( $str );
349 }
350 }
351
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 = '' ) {
359 global $post;
360
361 $product = wel_get_product( $post );
362 $str = $product['itemPointrate'];
363 $rate = (int) $str;
364
365 if ( 'return' === $out ) {
366 return $rate;
367 } else {
368 echo esc_html( $rate );
369 }
370 }
371
372 /**
373 * Shipment
374 *
375 * @param string $out Return value or echo.
376 * @return string|void
377 */
378 function usces_the_shipment_aim( $out = '' ) {
379 global $post;
380
381 $product = wel_get_product( $post );
382 $str = $product['itemShipping'];
383 $no = (int) $str;
384 if ( 0 === $no ) {
385 return '';
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 }
394 }
395
396 /**
397 * Current item
398 */
399 function usces_the_item() {
400 global $usces, $post;
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
407 return;
408 }
409
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 ) {
434 return $value;
435 } else {
436 echo esc_html( $value );
437 }
438 }
439
440 /**
441 * Count SKU
442 *
443 * @return int
444 */
445 function usces_sku_num() {
446 global $usces;
447
448 $sku_num = ( ! empty( $usces->itemskus ) && is_array( $usces->itemskus ) ) ? count( $usces->itemskus ) : 0;
449 return $sku_num;
450 }
451
452 /**
453 * Is SKU
454 *
455 * @return bool
456 */
457 function usces_is_skus() {
458 global $usces;
459
460 if ( ! empty( $usces->itemskus ) && is_array( $usces->itemskus ) && 0 < count( $usces->itemskus ) ) {
461 $usces->current_itemsku = -1;
462 reset( $usces->itemskus );
463 $usces->itemsku = array();
464 return true;
465 } else {
466 return false;
467 }
468 }
469
470 /**
471 * Reset SKU
472 */
473 function usces_reset_skus() {
474 global $usces;
475
476 $usces->current_itemsku = -1;
477 reset( $usces->itemskus );
478 }
479
480 /**
481 * Have SKU
482 *
483 * @return bool
484 */
485 function usces_have_skus() {
486 global $usces;
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 ];
495 return true;
496 } else {
497 return false;
498 }
499 }
500
501 /**
502 * SKU data
503 *
504 * @param string $out Return value or echo.
505 * @return string|void
506 */
507 function usces_the_itemSku( $out = '' ) {
508 global $usces;
509
510 $skucode = isset( $usces->itemsku['code'] ) ? $usces->itemsku['code'] : '';
511 if ( 'return' === $out ) {
512 return $skucode;
513 } else {
514 echo esc_attr( $skucode );
515 }
516 }
517
518 /**
519 * SKU price
520 *
521 * @param string $out Return value or echo.
522 * @return int|void
523 */
524 function usces_the_itemPrice( $out = '' ) {
525 global $usces;
526
527 if ( 'return' === $out ) {
528 return $usces->itemsku['price'];
529 } else {
530 echo number_format( $usces->itemsku['price'] );
531 }
532 }
533
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 = '' ) {
541 global $usces;
542
543 if ( 'return' === $out ) {
544 return $usces->itemsku['cprice'];
545 } else {
546 echo number_format( $usces->itemsku['cprice'] );
547 }
548 }
549
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 = '' ) {
557 global $usces;
558
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 ) {
563 return $res;
564 } else {
565 echo esc_html( $res );
566 }
567 }
568
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 = '' ) {
576 global $usces;
577
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 ) {
582 return $res;
583 } else {
584 echo esc_html( $res );
585 }
586 }
587
588 /**
589 * Currency code
590 *
591 * @param string $out Return value or echo.
592 * @return string|void
593 */
594 function usces_crcode( $out = '' ) {
595 global $usces;
596
597 $res = esc_html( $usces->get_currency_code() );
598
599 if ( 'return' === $out ) {
600 return $res;
601 } else {
602 echo __( $res, 'usces' );
603 }
604 }
605
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 = '' ) {
614 global $usces;
615
616 $res = $usces->getCurrencySymbol();
617 if ( 'js' === $js && '&yen;' == $res ) {
618 $res = mb_convert_encoding( $res, 'UTF-8', 'HTML-ENTITIES' );
619 }
620 if ( 'return' === $out ) {
621 return $res;
622 } else {
623 echo esc_html( $res );
624 }
625 }
626
627 /**
628 * Stock
629 *
630 * @param string $out Return value or echo.
631 * @return string|void
632 */
633 function usces_the_itemZaiko( $out = '' ) {
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 }
656 }
657
658 if ( 'return' === $out ) {
659 return $res;
660 } else {
661 echo esc_html( $res );
662 }
663 }
664
665 /**
666 * Stock status
667 *
668 * @param string $out Return value or echo.
669 * @return string|void
670 */
671 function usces_the_itemZaikoStatus( $out = '' ) {
672 global $usces;
673
674 if ( 'return' === $out ) {
675 return usces_get_itemZaiko( 'name' );
676 } else {
677 echo esc_html( usces_get_itemZaiko( 'name' ) );
678 }
679 }
680
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 ) {
690 global $usces;
691
692 if ( null === $post_id ) {
693 global $post;
694 $post_id = $post->ID;
695 }
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 ) {
710 $res = $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 }
722 }
723 return $res;
724 }
725
726 /**
727 * SKU stock
728 *
729 * @param string $out Return value or echo.
730 * @return int|void
731 */
732 function usces_the_itemZaikoNum( $out = '' ) {
733 global $usces;
734
735 if ( ! isset( $usces->itemsku['stocknum'] ) ) {
736 return false;
737 }
738
739 $num = $usces->itemsku['stocknum'];
740 if ( '' !== $num ) {
741 $num = (int) $num;
742 }
743
744 if ( 'return' === $out ) {
745 return $num;
746 } else {
747 echo number_format( $num );
748 }
749 }
750
751 /**
752 * SKU title
753 *
754 * @param string $out Return value or echo.
755 * @return string|void
756 */
757 function usces_the_itemSkuDisp( $out = '' ) {
758 global $usces;
759
760 if ( ! isset( $usces->itemsku['name'] ) ) {
761 return false;
762 }
763
764 if ( 'return' === $out ) {
765 return $usces->itemsku['name'];
766 } else {
767 echo esc_html( $usces->itemsku['name'] );
768 }
769 }
770
771 /**
772 * SKU unit
773 *
774 * @param string $out Return value or echo.
775 * @return string|void
776 */
777 function usces_the_itemSkuUnit( $out = '' ) {
778 global $usces;
779
780 if ( ! isset( $usces->itemsku['unit'] ) ) {
781 return false;
782 }
783
784 if ( 'return' === $out ) {
785 return $usces->itemsku['unit'];
786 } else {
787 echo esc_html( $usces->itemsku['unit'] );
788 }
789 }
790
791 /**
792 * Top SKU code
793 *
794 * @param string $out Return value or echo.
795 * @return string|void
796 */
797 function usces_the_firstSku( $out = '' ) {
798 global $post, $usces;
799
800 $post_id = $post->ID;
801 $skus = wel_get_skus( $post_id );
802
803 if ( null === $skus || ! isset( $skus[0]['code'] ) ) {
804 return false;
805 }
806
807 if ( 'return' === $out ) {
808 return $skus[0]['code'];
809 } else {
810 echo esc_html( $skus[0]['code'] );
811 }
812 }
813
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 ) {
822 global $usces;
823
824 if ( null === $post ) {
825 global $post;
826 }
827 $post_id = $post->ID;
828 $skus = wel_get_skus( $post_id );
829
830 if ( empty( $skus ) ) {
831 $price = null;
832 } else {
833 $price = $skus[0]['price'];
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 }
843 }
844
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 ) {
853 global $usces;
854
855 if ( null === $post ) {
856 global $post;
857 }
858 $post_id = $post->ID;
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 ) {
866 return $skus[0]['cprice'];
867 } else {
868 echo number_format( $skus[0]['cprice'] );
869 }
870 }
871
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 ) {
880 global $usces;
881
882 if ( null === $post ) {
883 global $post;
884 }
885 $post_id = $post->ID;
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 }
893
894 if ( 'return' === $out ) {
895 return $price;
896 } else {
897 echo esc_html( $price );
898 }
899 }
900
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 ) {
909 global $usces;
910
911 if ( null === $post ) {
912 global $post;
913 }
914 $post_id = $post->ID;
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 }
922
923 if ( 'return' === $out ) {
924 return $cprice;
925 } else {
926 echo esc_html( $cprice );
927 }
928 }
929
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 }
943 $post_id = $post->ID;
944 $skus = wel_get_skus( $post_id );
945
946 if ( 'return' === $out ) {
947 return $skus[0]['stock'];
948 } else {
949 echo esc_html( $skus[0]['stock'] );
950 }
951 }
952
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 }
966 $post_id = $post->ID;
967 $skus = wel_get_skus( $post_id );
968 $sku = end( $skus );
969
970 if ( 'return' === $out ) {
971 return $sku['code'];
972 } else {
973 echo esc_html( $sku['code'] );
974 }
975 }
976
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 }
990 $post_id = $post->ID;
991 $skus = wel_get_skus( $post_id );
992 $sku = end( $skus );
993
994 if ( 'return' === $out ) {
995 return $sku['price'];
996 } else {
997 echo number_format( $sku['price'] );
998 }
999 }
1000
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 }
1014 $post_id = $post->ID;
1015 $skus = wel_get_skus( $post_id );
1016 $sku = end( $skus );
1017
1018 if ( 'return' === $out ) {
1019 return $sku['stock'];
1020 } else {
1021 echo esc_html( $sku['stock'] );
1022 }
1023 }
1024
1025 /**
1026 * In stock
1027 *
1028 * @return bool
1029 */
1030 function usces_have_zaiko() {
1031 global $post, $usces;
1032 return $usces->is_item_zaiko( $post->ID, $usces->itemsku['code'] );
1033 }
1034
1035 /**
1036 * In stock
1037 *
1038 * @param int $post_id Post ID.
1039 * @return bool
1040 */
1041 function usces_have_zaiko_anyone( $post_id = null ) {
1042 global $post, $usces;
1043
1044 if ( null === $post_id ) {
1045 $post_id = $post->ID;
1046 }
1047
1048 $skus = wel_get_skus( $post_id );
1049 $status = false;
1050
1051 foreach ( $skus as $sku ) {
1052 if ( $usces->is_item_zaiko( $post_id, $sku['code'] ) ) {
1053 $status = true;
1054 break;
1055 }
1056 }
1057 return apply_filters( 'usces_have_zaiko_anyone', $status, $post_id, $skus );
1058 }
1059
1060 /**
1061 * Low or not stock
1062 *
1063 * @param int $post_id Post ID.
1064 * @return bool
1065 */
1066 function usces_have_fewstock( $post_id = null ) {
1067 global $post, $usces;
1068
1069 if ( null === $post_id ) {
1070 $post_id = $post->ID;
1071 }
1072
1073 $skus = wel_get_skus( $post_id );
1074 $res = false;
1075 foreach ( $skus as $sku ) {
1076 if ( 1 === (int) $sku['stock'] ) {
1077 $res = true;
1078 break;
1079 }
1080 }
1081 return $res;
1082 }
1083
1084 /**
1085 * Is applied large-lot discount
1086 *
1087 * @param int $post_id Post ID.
1088 * @param string $sku SKU code.
1089 * @param int $quant Quantity.
1090 * @return bool
1091 */
1092 function usces_is_gptekiyo( $post_id, $sku, $quant ) {
1093 global $usces;
1094 return $usces->is_gptekiyo( $post_id, $sku, $quant );
1095 }
1096
1097 /**
1098 * Large-lot discount
1099 *
1100 * @param string $out Return value or echo.
1101 * @return string|void
1102 */
1103 function usces_the_itemGpExp( $out = '' ) {
1104 global $post, $usces;
1105
1106 $post_id = $post->ID;
1107 $sku = $usces->itemsku['code'];
1108 $gpn1 = $usces->getItemGpNum1( $post_id );
1109 $gpn2 = $usces->getItemGpNum2( $post_id );
1110 $gpn3 = $usces->getItemGpNum3( $post_id );
1111 $gpd1 = $usces->getItemGpDis1( $post_id );
1112 $gpd2 = $usces->getItemGpDis2( $post_id );
1113 $gpd3 = $usces->getItemGpDis3( $post_id );
1114 $unit = $usces->getItemSkuUnit( $post_id, $sku );
1115 $price = $usces->getItemPrice( $post_id, $sku );
1116
1117 if ( ( 0 === (int) $usces->itemsku['gp'] ) || empty( $gpn1 ) || empty( $gpd1 ) ) {
1118 return;
1119 }
1120
1121 if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
1122 $tax_rate = 0;
1123 } else {
1124 $usces_tax = Welcart_Tax::get_instance();
1125 $tax_rate = $usces_tax->get_sku_tax_rate( $post_id, $sku );
1126 }
1127
1128 $html = "<dl class='itemGpExp'>\n<dt>" . apply_filters( 'usces_filter_itemGpExp_title', __( 'Business package discount', 'usces' ) ) . "</dt>\n<dd>\n<ul>\n";
1129 if ( ! empty( $gpn1 ) && ! empty( $gpd1 ) ) {
1130 if ( empty( $gpn2 ) || empty( $gpd2 ) ) {
1131 $price1 = wel_gp_price_discount( $price, $gpd1 );
1132 $html .= '<li>';
1133 $html .= sprintf( __( '<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces' ),
1134 $usces->get_currency( $price1, true, false ),
1135 $usces->getGuidTax(),
1136 esc_html( $unit ),
1137 $gpn1,
1138 "'price'"
1139 );
1140 if ( 0 < $tax_rate ) {
1141 $html .= usces_crform_the_itemGpExp_taxincluded( $price1, $tax_rate );
1142 }
1143 $html .= "</li>\n";
1144 } else {
1145 $price1 = wel_gp_price_discount( $price, $gpd1 );
1146 $html .= '<li>';
1147 $html .= sprintf( __( '<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces' ),
1148 $usces->get_currency( $price1, true, false ),
1149 $usces->getGuidTax(),
1150 esc_html( $unit ),
1151 $gpn1,
1152 $gpn2 - 1,
1153 "'price'"
1154 );
1155 if ( 0 < $tax_rate ) {
1156 $html .= usces_crform_the_itemGpExp_taxincluded( $price1, $tax_rate );
1157 }
1158 $html .= "</li>\n";
1159 if ( empty( $gpn3 ) || empty( $gpd3 ) ) {
1160 $price2 = wel_gp_price_discount( $price, $gpd2 );
1161 $html .= '<li>';
1162 $html .= sprintf( __( '<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces' ),
1163 $usces->get_currency( $price2, true, false ),
1164 $usces->getGuidTax(),
1165 esc_html( $unit ),
1166 $gpn2,
1167 "'price'"
1168 );
1169 if ( 0 < $tax_rate ) {
1170 $html .= usces_crform_the_itemGpExp_taxincluded( $price2, $tax_rate );
1171 }
1172 $html .= "</li>\n";
1173 } else {
1174 $price2 = wel_gp_price_discount( $price, $gpd2 );
1175 $html .= '<li>';
1176 $html .= sprintf( __( '<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces' ),
1177 $usces->get_currency( $price2, true, false ),
1178 $usces->getGuidTax(),
1179 esc_html( $unit ),
1180 $gpn2,
1181 $gpn3 - 1,
1182 "'price'"
1183 );
1184 if ( 0 < $tax_rate ) {
1185 $html .= usces_crform_the_itemGpExp_taxincluded( $price2, $tax_rate );
1186 }
1187 $html .= "</li>\n";
1188 $price3 = wel_gp_price_discount( $price, $gpd3 );
1189 $html .= '<li>';
1190 $html .= sprintf( __( '<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces' ),
1191 $usces->get_currency( $price3, true, false ),
1192 $usces->getGuidTax(),
1193 esc_html( $unit ),
1194 $gpn3,
1195 "'price'"
1196 );
1197 if ( 0 < $tax_rate ) {
1198 $html .= usces_crform_the_itemGpExp_taxincluded( $price3, $tax_rate );
1199 }
1200 $html .= "</li>\n";
1201 }
1202 }
1203 }
1204 $html .= '</ul></dd></dl>';
1205
1206 $html = apply_filters( 'usces_filter_itemGpExp', $html );
1207
1208 if ( 'return' === $out ) {
1209 return $html;
1210 } else {
1211 echo $html; // no escape due to filter.
1212 }
1213 }
1214
1215 /**
1216 * Calculation of the discount based on the unit price per float.
1217 *
1218 * @param float $price Price.
1219 * @param int $rate Discount rate.
1220 * @return float
1221 */
1222 function wel_gp_price_discount( $price, $rate ) {
1223 global $usces;
1224
1225 $decimal = $usces->get_currency_decimal();
1226 if ( 0 === (int) $decimal ) {
1227 $discount = round( $price * ( 100 - $rate ) / 100 );
1228 } else {
1229 $discount = (float) sprintf( "%.{$decimal}f", (float) $price * ( 100 - $rate ) / 100 );
1230 }
1231 return $discount;
1232 }
1233
1234 /**
1235 * Formatted tax included amount
1236 *
1237 * @param float $price Price.
1238 * @param float $tax_rate Tax rate.
1239 * @param bool $label_pre Forward label.
1240 * @param string $label Label.
1241 * @param string $start_tag Start tag.
1242 * @param string $end_tag End tag.
1243 * @param bool $symbol_pre Forward symbol.
1244 * @param bool $symbol_post Backward symbol.
1245 * @param bool $seperator_flag Seperator.
1246 * @return string
1247 */
1248 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 ) {
1249 global $usces;
1250
1251 if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
1252 $res = '';
1253 } else {
1254 $tax = (float) sprintf( '%.3f', (float) $price * (float) $tax_rate / 100 );
1255 $tax = usces_tax_rounding_off( $tax );
1256 $price_gpexp = esc_html( $usces->get_currency( $price + $tax, $symbol_pre, $symbol_post, $seperator_flag ) );
1257 if ( empty( $label ) ) {
1258 $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
1259 } else {
1260 $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
1261 }
1262 if ( empty( $start_tag ) ) {
1263 $start_tag = '<span class="tax_inc_block">( ';
1264 }
1265 if ( $label_pre ) {
1266 $start_tag = $start_tag . $label_tag;
1267 }
1268 if ( empty( $end_tag ) ) {
1269 $end_tag = ' )</span>';
1270 }
1271 if ( true !== $label_pre ) {
1272 $end_tag = $label_tag . $end_tag;
1273 }
1274 $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 );
1275 }
1276 return $res;
1277 }
1278
1279 /**
1280 * Quantity field
1281 *
1282 * @param string $out Return value or echo.
1283 * @return string|void
1284 */
1285 function usces_the_itemQuant( $out = '' ) {
1286 global $usces, $post;
1287
1288 $post_id = $post->ID;
1289 $sku = urlencode( $usces->itemsku['code'] );
1290 $value = isset( $_SESSION['usces_singleitem']['quant'][ $post_id ][ $sku ] ) ? $_SESSION['usces_singleitem']['quant'][ $post_id ][ $sku ] : 1;
1291 $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;}\" />";
1292 $html = apply_filters( 'usces_filter_the_itemQuant', $quant, $post );
1293
1294 if ( 'return' === $out ) {
1295 return $html;
1296 } else {
1297 echo $html; // no escape due to filter.
1298 }
1299 }
1300
1301 /**
1302 * Add to Cart
1303 *
1304 * @param mixed $value Value.
1305 * @param int $type Submit or button.
1306 * @param string $out Return value or echo.
1307 * @return string|void
1308 */
1309 function usces_the_itemSkuButton( $value, $type = 0, $out = '' ) {
1310 global $usces, $post;
1311
1312 $post_id = (int) $post->ID;
1313 $zaikonum = esc_attr( $usces->itemsku['stocknum'] );
1314 $zaiko_status = esc_attr( $usces->itemsku['stock'] );
1315 $gptekiyo = esc_attr( $usces->itemsku['gp'] );
1316 $skuprice = esc_attr( $usces->getItemPrice( $post_id, $usces->itemsku['code'] ) );
1317 $value = esc_attr( apply_filters( 'usces_filter_incart_button_label', $value ) );
1318 $sku = esc_attr( urlencode( $usces->itemsku['code'] ) );
1319
1320 if ( 1 === (int) $type ) {
1321 $type = 'button';
1322 } else {
1323 $type = 'submit';
1324 }
1325 $html = "<input name=\"zaikonum[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku}]\" value=\"{$zaikonum}\" />\n";
1326 $html .= "<input name=\"zaiko[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku}]\" value=\"{$zaiko_status}\" />\n";
1327 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku}]\" value=\"{$gptekiyo}\" />\n";
1328 $html .= "<input name=\"skuPrice[{$post_id}][{$sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku}]\" value=\"{$skuprice}\" />\n";
1329 if ( $usces->use_js ) {
1330 $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}' )\" />";
1331 } else {
1332 $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$sku}]\" type=\"{$type}\" id=\"inCart[{$post_id}][{$sku}]\" class=\"skubutton\" value=\"{$value}\" />";
1333 }
1334 $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
1335 $html = apply_filters( 'usces_filter_item_sku_button', $html, $value, $type );
1336
1337 if ( 'return' === $out ) {
1338 return $html;
1339 } else {
1340 echo $html; // no escape due to filter.
1341 }
1342 }
1343
1344 /**
1345 * Add to Cart ( direct mode )
1346 *
1347 * @param int $post_id Post ID.
1348 * @param string $sku SKU code.
1349 * @param bool $force Force.
1350 * @param mixed $value Value.
1351 * @param bool $options Have options.
1352 * @param string $out Return value or echo.
1353 * @return string|void
1354 */
1355 function usces_direct_intoCart( $post_id, $sku, $force = false, $value = null, $options = null, $out = '' ) {
1356 global $usces;
1357
1358 if ( empty( $value ) ) {
1359 $value = __( 'Add To Cart', 'usces' );
1360 }
1361 $skus = wel_get_skus( $post_id, 'code' );
1362
1363 $zaikonum = $skus[ $sku ]['stocknum'];
1364 $zaiko = $skus[ $sku ]['stock'];
1365 $gptekiyo = $skus[ $sku ]['gp'];
1366 $skuprice = $skus[ $sku ]['price'];
1367 $enc_sku = urlencode( $sku );
1368
1369 $usces->itemopts = wel_get_opts( $post_id, 'sort' );
1370 $usces->current_itemopt = -1;
1371
1372 $usces->itemsku = $skus[ $sku ];
1373
1374 $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\" name=\"" . $post_id . '-' . $enc_sku . "\">\n";
1375 $html .= "<input name=\"zaikonum[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $zaikonum ) . "\" />\n";
1376 $html .= "<input name=\"zaiko[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $zaiko ) . "\" />\n";
1377 $html .= "<input name=\"gptekiyo[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $gptekiyo ) . "\" />\n";
1378 $html .= "<input name=\"skuPrice[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $skuprice ) . "\" />\n";
1379
1380 if ( $options && usces_is_options() ) {
1381 while ( usces_have_options() ) {
1382 $html .= '<div class="itemopt_row">' . usces_get_itemopt_filed( $post_id, $sku, $usces->itemopt ) . "</div>\n";
1383 }
1384 }
1385
1386 $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 ) . ' />';
1387 $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
1388 if ( $force ) {
1389 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
1390 }
1391 $html = apply_filters( 'usces_filter_single_item_inform', $html );
1392
1393 $html .= '</form>';
1394 $html .= '<div class="direct_error_message">' . usces_singleitem_error_message( $post_id, $sku, 'return' ) . '</div>' . "\n";
1395
1396 if ( 'return' === $out ) {
1397 return $html;
1398 } else {
1399 echo $html; // no escape due to filter.
1400 }
1401 }
1402
1403 /**
1404 * Product Image
1405 *
1406 * @param int $number Image number.
1407 * @param int $width Width.
1408 * @param int $height Height.
1409 * @param object $post Post data.
1410 * @param string $out Return value or echo.
1411 * @param string $media Media.
1412 * @return string|void
1413 */
1414 function usces_the_itemImage( $number = 0, $width = 60, $height = 60, $post = '', $out = '', $media = 'item' ) {
1415 global $usces;
1416
1417 if ( '' === $post ) {
1418 global $post;
1419 }
1420 $post_id = $post->ID;
1421
1422 $ptitle = '';
1423 if ( is_string( $number ) ) {
1424 $ptitle = $number;
1425 }
1426 if ( $ptitle ) {
1427
1428 $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1429 $pictid = ( $picposts->have_posts() ) ? $picposts[0]->ID : 0;
1430 $html = wp_get_attachment_image( $pictid, array( $width, $height ), false );
1431 if ( 'item' === $media ) {
1432 $product = wel_get_product( $post_id );
1433 $code = $product['itemCode'];
1434 if ( ! $code ) {
1435 return false;
1436 }
1437 $name = $product['itemName'];
1438
1439 $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1440 if ( empty( $alt ) ) {
1441 $alt = $code;
1442 }
1443 $alt = 'alt="' . esc_attr( $alt ) . '"';
1444 $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1445
1446 $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1447
1448 $title = 'title="' . esc_attr( $name ) . '"';
1449 $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1450
1451 $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1452 $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height );
1453 }
1454
1455 } else {
1456
1457 $product = wel_get_product( $post_id );
1458 $code = $product['itemCode'];
1459 if ( ! $code ) {
1460 return false;
1461 }
1462 $name = $product['itemName'];
1463
1464 if ( 0 === (int) $number ) {
1465
1466 $pictid = (int) $usces->get_mainpictid( $code );
1467 $html = wp_get_attachment_image( $pictid, array( $width, $height ), true );/* '<img src="#" height="60" width="60" alt="" />'; */
1468 if ( 'item' === $media ) {
1469 $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1470 if ( empty( $alt ) ) {
1471 $alt = $code;
1472 }
1473 $alt = 'alt="' . esc_attr( $alt ) . '"';
1474 $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1475
1476 $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1477
1478 $title = 'title="' . esc_attr( $name ) . '"';
1479 $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1480
1481 $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1482 $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height );
1483 }
1484
1485 } else {
1486
1487 $pictids = $usces->get_pictids( $code );
1488 $ind = $number - 1;
1489 $pictid = ( isset( $pictids[ $ind ] ) && (int) $pictids[ $ind ] ) ? $pictids[ $ind ] : 0;
1490 $html = wp_get_attachment_image( $pictid, array( $width, $height ), false );/* '<img src="#" height="60" width="60" alt="" />'; */
1491 if ( 'item' === $media ) {
1492 $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1493 if ( empty( $alt ) ) {
1494 $alt = $code;
1495 }
1496 $alt = 'alt="' . esc_attr( $alt ) . '"';
1497 $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1498
1499 $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1500
1501 $title = 'title="' . esc_attr( $name ) . '"';
1502 $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1503
1504 $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1505 $html = apply_filters( 'usces_filter_sub_img', $html, $post_id, $pictid, $width, $height );
1506 }
1507 }
1508 }
1509
1510 if ( 'return' === $out ) {
1511 return wel_esc_script( $html );
1512 } else {
1513 wel_esc_script_e( $html );
1514 }
1515 }
1516
1517 /**
1518 * Product Image URL
1519 *
1520 * @param int $number Image number.
1521 * @param string $out Return value or echo.
1522 * @param object $post Post data.
1523 * @return string|void
1524 */
1525 function usces_the_itemImageURL( $number = 0, $out = '', $post = '' ) {
1526 global $usces;
1527
1528 $ptitle = $number;
1529 if ( $ptitle && is_string( $number ) ) {
1530
1531 $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1532 $pictid = ( $picposts->have_posts() ) ? $picposts[0]->ID : 0;
1533 $html = wp_get_attachment_url( $pictid );
1534
1535 } else {
1536
1537 if ( '' === $post ) {
1538 global $post;
1539 }
1540 $post_id = $post->ID;
1541 $product = wel_get_product( $post_id );
1542 $code = $product['itemCode'];
1543 if ( ! $code ) {
1544 return false;
1545 }
1546 $name = $product['itemName'];
1547 if ( 0 === (int) $number ) {
1548 $pictid = (int) $usces->get_mainpictid( $code );
1549 $html = wp_get_attachment_url( $pictid );
1550 } else {
1551 $pictids = $usces->get_pictids( $code );
1552 $ind = $number - 1;
1553 $pictid = ( isset( $pictids[ $ind ] ) && (int) $pictids[ $ind ] ) ? $pictids[ $ind ] : 0;
1554 $html = wp_get_attachment_url( $pictid );
1555 }
1556 }
1557
1558 if ( 'return' === $out ) {
1559 return wel_esc_script( $html );
1560 } else {
1561 wel_esc_script_e( $html );
1562 }
1563 }
1564
1565 /**
1566 * Product Image caption
1567 *
1568 * @param int $number Image number.
1569 * @param object $post Post data.
1570 * @param string $out Return value or echo.
1571 * @return string|void
1572 */
1573 function usces_the_itemImageCaption( $number = 0, $post = '', $out = '' ) {
1574 global $usces;
1575
1576 $ptitle = $number;
1577 if ( $ptitle && 0 === (int) $number ) {
1578
1579 $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1580 $excerpt = ( $picposts->have_posts() ) ? $picposts[0]->post_excerpt : '';
1581
1582 } else {
1583
1584 if ( '' === $post ) {
1585 global $post;
1586 }
1587 $post_id = $post->ID;
1588 $product = wel_get_product( $post_id );
1589
1590 $code = $product['itemCode'];
1591 if ( ! $code ) {
1592 return false;
1593 }
1594 $name = $product['itemName'];
1595
1596 if ( 0 === (int) $number ) {
1597 $pictid = $usces->get_mainpictid( $code );
1598 if ( $pictid ) {
1599 $attach_ob = get_post( $pictid );
1600 $excerpt = ( isset( $attach_ob->post_excerpt ) ) ? $attach_ob->post_excerpt : '';
1601 } else {
1602 $excerpt = '';
1603 }
1604 } else {
1605 $pictids = $usces->get_pictids( $code );
1606 $ind = $number - 1;
1607 if ( isset( $pictids[ $ind ] ) ) {
1608 $attach_ob = get_post( $pictids[ $ind ] );
1609 $excerpt = ( isset( $attach_ob->post_excerpt ) ) ? $attach_ob->post_excerpt : '';
1610 } else {
1611 $excerpt = '';
1612 }
1613 }
1614 }
1615
1616 if ( 'return' === $out ) {
1617 return $excerpt;
1618 } else {
1619 echo esc_html( $excerpt );
1620 }
1621 }
1622
1623 /**
1624 * Product Image description
1625 *
1626 * @param int $number Image number.
1627 * @param object $post Post data.
1628 * @param string $out Return value or echo.
1629 * @return string|void
1630 */
1631 function usces_the_itemImageDescription( $number = 0, $post = '', $out = '' ) {
1632 global $usces;
1633
1634 $ptitle = $number;
1635 if ( $ptitle && 0 === (int) $number ) {
1636
1637 $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1638 $description = ( $picposts->have_posts() ) ? $picposts[0]->post_content : '';
1639
1640 } else {
1641
1642 if ( '' === $post ) {
1643 global $post;
1644 }
1645 $post_id = $post->ID;
1646 $product = wel_get_product( $post_id );
1647
1648 $code = $product['itemCode'];
1649 if ( ! $code ) {
1650 return false;
1651 }
1652 $name = $product['itemName'];
1653
1654 if ( 0 === (int) $number ) {
1655 $pictid = $usces->get_mainpictid( $code );
1656 if ( $pictid ) {
1657 $attach_ob = get_post( $pictid );
1658 $description = ( isset( $attach_ob->post_content ) ) ? $attach_ob->post_content : '';
1659 } else {
1660 $description = '';
1661 }
1662 } else {
1663 $pictids = $usces->get_pictids( $code );
1664 $ind = $number - 1;
1665 if ( isset( $pictids[ $ind ] ) ) {
1666 $attach_ob = get_post( $pictids[ $ind ] );
1667 $description = ( isset( $attach_ob->post_content ) ) ? $attach_ob->post_content : '';
1668 } else {
1669 $description = '';
1670 }
1671 }
1672 }
1673
1674 if ( 'return' === $out ) {
1675 return $description;
1676 } else {
1677 echo esc_html( $description );
1678 }
1679 }
1680
1681 /**
1682 * Product sub image
1683 *
1684 * @return array
1685 */
1686 function usces_get_itemSubImageNums() {
1687 global $post, $usces;
1688
1689 $post_id = $post->ID;
1690 $res = array();
1691
1692 $product = wel_get_product( $post_id );
1693 $code = $product['itemCode'];
1694 if ( ! $code ) {
1695 return false;
1696 }
1697 $name = $product['itemName'];
1698
1699 $pictids = $usces->get_pictids( $code );
1700 $pictids_count = ( $pictids && is_array( $pictids ) ) ? count( $pictids ) : 0;
1701 for ( $i = 1; $i <= $pictids_count; $i++ ) {
1702 $res[] = $i;
1703 }
1704 return $res;
1705 }
1706
1707 /**
1708 * Is item option
1709 *
1710 * @return bool
1711 */
1712 function usces_is_options() {
1713 global $usces;
1714
1715 if ( ! empty( $usces->itemopts ) && is_array( $usces->itemopts ) && 0 < count( $usces->itemopts ) ) {
1716 reset( $usces->itemopts );
1717 $usces->itemopt = array();
1718 $usces->current_itemopt = -1;
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 }
1724
1725 /**
1726 * Have item option
1727 *
1728 * @return bool
1729 */
1730 function usces_have_options() {
1731 global $usces;
1732
1733 if ( null === $usces->current_itemopt ) {
1734 $usces->current_itemopt = -1;
1735 }
1736
1737 if ( ! empty( $usces->itemopts ) && is_array( $usces->itemopts ) && ( $usces->current_itemopt + 1 < count( $usces->itemopts ) ) ) {
1738 $usces->current_itemopt++;
1739 $usces->itemopt = ( isset( $usces->itemopts[ $usces->current_itemopt ] ) ) ? $usces->itemopts[ $usces->current_itemopt ] : array();
1740 return true;
1741 } else {
1742 return false;
1743 }
1744 }
1745
1746 /**
1747 * Item option name
1748 *
1749 * @return string
1750 */
1751 function usces_getItemOptName() {
1752 global $usces;
1753 return $usces->itemopt['name'];
1754 }
1755
1756 /**
1757 * Item option name
1758 *
1759 * @param string $out Return value or echo.
1760 * @return string|void
1761 */
1762 function usces_the_itemOptName( $out = '' ) {
1763 global $usces;
1764
1765 if ( 'return' === $out ) {
1766 return $usces->itemopt['name'];
1767 } else {
1768 echo esc_html( $usces->itemopt['name'] );
1769 }
1770 }
1771
1772 /**
1773 * Item option field
1774 *
1775 * @param string $name Option name.
1776 * @param string $label Label.
1777 * @param string $out Return value or echo.
1778 * @return string|void
1779 */
1780 function usces_the_itemOption( $name, $label = '#default#', $out = '' ) {
1781 global $post, $usces;
1782 $post_id = $post->ID;
1783
1784 if ( '#default#' === $label ) {
1785 $label = $name;
1786 }
1787
1788 $opts = wel_get_opts( $post_id, 'name' );
1789 if ( ! $opts || ! isset( $opts[ $name ] ) ) {
1790 return false;
1791 }
1792
1793 $opt = $opts[ $name ];
1794 $opt['value'] = usces_change_line_break( $opt['value'] );
1795 $means = (int) $opt['means'];
1796 $essential = (int) $opt['essential'];
1797
1798 $sku = esc_attr( urlencode( $usces->itemsku['code'] ) );
1799 $optcode = esc_attr( urlencode( $name ) );
1800 $name = esc_attr( $name );
1801 $label = esc_attr( $label );
1802
1803 $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] ) ? $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] : null;
1804
1805 $html = '';
1806 $html .= "\n<label for='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_label'>{$label}</label>\n";
1807
1808 switch ( $means ) {
1809 case 0: // Single-select.
1810 case 1: // Multi-select.
1811 $selects = explode( "\n", $opt['value'] );
1812 $multiple = ( 0 === $means ) ? '' : ' multiple';
1813 $multiple_array = ( 0 === $means ) ? '' : '[]';
1814
1815 $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";
1816 if ( 1 === $essential ) {
1817 if ( 0 === $means && ( '#NONE#' === $session_value || null === $session_value ) ) {
1818 $selected = ' selected="selected"';
1819 } else {
1820 $selected = '';
1821 }
1822 $html .= "\t<option value='#NONE#'{$selected}>" . __( 'Choose', 'usces' ) . "</option>\n";
1823 }
1824 $i = 0;
1825 foreach ( (array) $selects as $v ) {
1826 $v = trim( $v );
1827 if ( ( 0 === $i && 0 === $essential && null === $session_value ) || esc_attr( $v ) === $session_value ) {
1828 $selected = ' selected="selected"';
1829 } else {
1830 $selected = '';
1831 }
1832 $html .= "\t<option value='" . esc_attr( $v ) . "'{$selected}>" . esc_attr( $v ) . "</option>\n";
1833 $i++;
1834 }
1835 $html .= "</select>\n";
1836 break;
1837 case 2: // Text.
1838 $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";
1839 break;
1840 case 3: // Radio-button.
1841 $selects = explode( "\n", $opt['value'] );
1842 $i = 0;
1843 foreach ( (array) $selects as $v ) {
1844 $v = trim( $v );
1845 if ( $v === $session_value ) {
1846 $checked = ' checked="checked"';
1847 } else {
1848 $checked = '';
1849 }
1850 $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";
1851 $i++;
1852 }
1853 break;
1854 case 4: // Check-box.
1855 $selects = explode( "\n", $opt['value'] );
1856 $i = 0;
1857 foreach ( (array) $selects as $v ) {
1858 $v = trim( $v );
1859 if ( $v === $session_value ) {
1860 $checked = ' checked="checked"';
1861 } else {
1862 $checked = '';
1863 }
1864 $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";
1865 $i++;
1866 }
1867 break;
1868 case 5: // Text-area.
1869 $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr( $session_value ) . "</textarea>\n";
1870 break;
1871 }
1872
1873 $html = apply_filters( 'usces_filter_the_itemOption', $html, $opts, $name, $label, $post_id, $usces->itemsku['code'] );
1874
1875 if ( 'return' === $out ) {
1876 return $html;
1877 } else {
1878 echo $html; // no escape due to filter.
1879 }
1880 }
1881
1882 /**
1883 * Display cart
1884 */
1885 function usces_the_cart() {
1886 global $usces;
1887 $usces->display_cart();
1888 }
1889
1890 /**
1891 * Is cart page
1892 *
1893 * @return bool
1894 */
1895 function usces_is_cart_page() {
1896 global $usces;
1897
1898 if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
1899 if ( 'cart' === $usces->page ) {
1900 return true;
1901 }
1902 if ( 'customer' !== $usces->page && 'delivery' !== $usces->page && 'confirm' !== $usces->page && 'ordercompletion' !== $usces->page && 'error' !== $usces->page && 'search_item' !== $usces->page ) {
1903 return true;
1904 }
1905 }
1906 return false;
1907 }
1908
1909 /**
1910 * Is cart
1911 *
1912 * @return bool
1913 */
1914 function usces_is_cart() {
1915 global $usces;
1916
1917 if ( 0 < $usces->cart->num_row() ) {
1918 if ( apply_filters( 'usces_is_cart_check', true ) ) {
1919 return true;
1920 } else {
1921 return false;
1922 }
1923 } else {
1924 return false;
1925 }
1926 }
1927
1928 /**
1929 * Is category
1930 *
1931 * @param string $str categpry slug.
1932 * @return bool
1933 */
1934 function usces_is_category( $str ) {
1935
1936 $cat = get_the_category();
1937 $slugs = array();
1938 foreach ( $cat as $value ) {
1939 $slugs[] = $value->slug;
1940 }
1941
1942 $str = utf8_uri_encode( $str );
1943
1944 if ( in_array( $str, $slugs, true ) ) {
1945 return true;
1946 } else {
1947 return false;
1948 }
1949 }
1950
1951 /**
1952 * Pref field
1953 *
1954 * @param string $flag Member or not.
1955 * @param string $out Return value or echo.
1956 * @return string|void
1957 */
1958 function usces_the_pref( $flag, $out = '' ) {
1959 global $usces;
1960
1961 $usces_entries = $usces->cart->get_entry();
1962 $name = esc_attr( $flag ) . '[pref]';
1963 $pref = $usces_entries[ $flag ]['pref'];
1964 if ( 'member' === $flag ) {
1965 $usces_members = $usces->get_member();
1966 $pref = $usces_members['pref'];
1967 }
1968 $html = "<select name=\"" . esc_attr( $name ) . "\" id=\"pref\" class=\"pref\">\n";
1969 $prefs = get_usces_states( usces_get_local_addressform() );
1970 foreach ( $prefs as $value ) {
1971 $selected = ( $pref === $value ) ? ' selected="selected"' : '';
1972 $html .= "\t<option value=\"" . esc_attr( $value ) . "\"{$selected}>" . esc_html( $value ) . "</option>\n";
1973 }
1974 $html .= "</select>\n";
1975
1976 if ( 'return' === $out ) {
1977 return wel_esc_script( $html );
1978 } else {
1979 wel_esc_script_e( $html );
1980 }
1981 }
1982
1983 /**
1984 * Company name
1985 */
1986 function usces_the_company_name() {
1987 global $usces;
1988 echo esc_html( $usces->options['company_name'] );
1989 }
1990
1991 /**
1992 * Zip code
1993 */
1994 function usces_the_zip_code() {
1995 global $usces;
1996 echo esc_html( $usces->options['zip_code'] );
1997 }
1998
1999 /**
2000 * Address1
2001 */
2002 function usces_the_address1() {
2003 global $usces;
2004 echo esc_html( $usces->options['address1'] );
2005 }
2006
2007 /**
2008 * Address2
2009 */
2010 function usces_the_address2() {
2011 global $usces;
2012 echo esc_html( $usces->options['address2'] );
2013 }
2014
2015 /**
2016 * Tel number
2017 */
2018 function usces_the_tel_number() {
2019 global $usces;
2020 echo esc_html( $usces->options['tel_number'] );
2021 }
2022
2023 /**
2024 * Fax number
2025 */
2026 function usces_the_fax_number() {
2027 global $usces;
2028 echo esc_html( $usces->options['fax_number'] );
2029 }
2030
2031 /**
2032 * Inquiry email address
2033 */
2034 function usces_the_inquiry_mail() {
2035 global $usces;
2036 echo esc_html( $usces->options['inquiry_mail'] );
2037 }
2038
2039 /**
2040 * Postage privilege
2041 */
2042 function usces_the_postage_privilege() {
2043 global $usces;
2044 echo esc_html( $usces->options['postage_privilege'] );
2045 }
2046
2047 /**
2048 * Initial point
2049 */
2050 function usces_the_start_point() {
2051 global $usces;
2052 echo esc_html( $usces->options['start_point'] );
2053 }
2054
2055 /**
2056 * Point rate
2057 *
2058 * @param int $post_id Post ID.
2059 * @param string $out Return value or echo.
2060 * @return string|void
2061 */
2062 function usces_point_rate( $post_id = null, $out = '' ) {
2063 global $usces;
2064
2065 if ( null === $post_id ) {
2066 $rate = $usces->options['point_rate'];
2067 } else {
2068 $product = wel_get_product( $post_id );
2069 $str = $product['itemPointrate'];
2070 $rate = (int) $str;
2071 }
2072 if ( 'return' === $out ) {
2073 return wel_esc_script( $rate );
2074 } else {
2075 wel_esc_script_e( $rate );
2076 }
2077 }
2078
2079 /**
2080 * Point discount
2081 *
2082 * @param int $post_id Post ID.
2083 * @param string $out Return value or echo.
2084 * @return string|void
2085 */
2086 function usces_point_rate_discount( $post_id = null, $out = '' ) {
2087 global $post, $usces;
2088
2089 if ( null === $post_id ) {
2090 $post_id = $post->ID;
2091 }
2092
2093 $product = wel_get_product( $post_id );
2094 $str = $product['itemPointrate'];
2095 $rate = (int) $str;
2096 if ( 'point' === $usces->options['campaign_privilege'] ) {
2097 if ( in_category( (int) $usces->options['campaign_category'], $post_id ) ) {
2098 $rate *= $usces->options['privilege_point'];
2099 }
2100 }
2101 if ( 'return' === $out ) {
2102 return wel_esc_script( $rate );
2103 } else {
2104 wel_esc_script_e( $rate );
2105 }
2106 }
2107
2108 /**
2109 * Item point
2110 *
2111 * @param int $post_id Post ID.
2112 * @param string $sku_code SKU code.
2113 * @return int
2114 */
2115 function usces_get_point( $post_id, $sku_code ) {
2116 global $usces;
2117
2118 if ( null === $post_id ) {
2119 $rate = $usces->options['point_rate'];
2120 } else {
2121 $product = wel_get_product( $post_id );
2122 $str = $product['itemPointrate'];
2123 $rate = (int) $str;
2124 }
2125
2126 $skus = wel_get_skus( $post_id, 'code' );
2127 $point = ceil( $skus[ $sku_code ]['price'] * $rate / 100 );
2128
2129 return $point;
2130 }
2131
2132 /**
2133 * Payment method field
2134 *
2135 * @param string $value Value.
2136 * @param string $out Return value or echo.
2137 * @return string|void
2138 */
2139 function usces_the_payment_method( $value = '', $out = '' ) {
2140 global $usces;
2141
2142 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
2143 $payments = apply_filters( 'usces_fiter_the_payment_method', $payments, $value );
2144
2145 if ( defined( 'WCEX_DLSELLER_VERSION' ) && version_compare( WCEX_DLSELLER_VERSION, '2.2-beta', '<=' ) ) {
2146 $cart = $usces->cart->get_cart();
2147 $have_continue_charge = usces_have_continue_charge( $cart );
2148 $continue_payment_method = apply_filters( 'usces_filter_the_continue_payment_method', array( 'acting_remise_card', 'acting_paypal_ec' ) );
2149 }
2150
2151 $list = '';
2152 $payment_ct = ( $payments && is_array( $payments ) ) ? count( $payments ) : 0;
2153 foreach ( (array) $payments as $id => $payment ) {
2154 if ( defined( 'WCEX_DLSELLER_VERSION' ) && version_compare( WCEX_DLSELLER_VERSION, '2.2-beta', '<=' ) ) {
2155 if ( $have_continue_charge ) {
2156 if ( ! in_array( $payment['settlement'], $continue_payment_method, true ) ) {
2157 $payment_ct--;
2158 continue;
2159 }
2160 if ( isset( $usces->options['acting_settings']['remise']['continuation'] ) && 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' === $payment['settlement'] ) {
2161 $payment_ct--;
2162 continue;
2163 } elseif ( isset( $usces->options['acting_settings']['paypal']['continuation'] ) && 'on' !== $usces->options['acting_settings']['paypal']['continuation'] && 'acting_paypal_ec' === $payment['settlement'] ) {
2164 $payment_ct--;
2165 continue;
2166 }
2167 }
2168 }
2169 if ( '' !== $payment['name'] && 'deactivate' !== $payment['use'] ) {
2170 $module = trim( $payment['module'] );
2171 if ( ! WCUtils::is_blank( $value ) ) {
2172 $checked = ( $payment['name'] === $value ) ? ' checked' : '';
2173 } elseif ( 1 === $payment_ct ) {
2174 $checked = ' checked';
2175 } else {
2176 $checked = '';
2177 }
2178 $payment_row = '';
2179 $checked = apply_filters( 'usces_fiter_the_payment_method_checked', $checked, $payment, $value );
2180 $explanation = apply_filters( 'usces_fiter_the_payment_method_explanation', $payment['explanation'], $payment, $value );
2181 if ( ( empty( $module ) || ! file_exists( $usces->options['settlement_path'] . $module ) ) && 'acting' === $payment['settlement'] ) {
2182 $checked = '';
2183 $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>';
2184 } else {
2185 $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>';
2186 }
2187 if ( ! empty( $explanation ) ) {
2188 $explanation = wel_esc_script( $explanation );
2189 $payment_row .= '<dd class="payment_' . $id . '">' . $explanation . '</dd>';
2190 }
2191 $payment_row = apply_filters( 'usces_filter_the_payment_method_row', $payment_row, $id, $payment, $checked, $module, $value, $explanation );
2192 if ( ! empty( $payment_row ) ) {
2193 $list .= $payment_row;
2194 }
2195 }
2196 }
2197
2198 if ( ! empty( $list ) ) {
2199 $html = '<dl>' . $list . '</dl>';
2200 } else {
2201 $html = '<div>' . __( 'Not yet ready for the payment method. Please refer to a manager.', 'usces' ) . '</div>';
2202 }
2203
2204 $html = apply_filters( 'usces_filter_the_payment_method_choices', $html, $payments );
2205 if ( 'return' === $out ) {
2206 return $html;
2207 } else {
2208 echo $html; // no escape due to filter.
2209 }
2210 }
2211
2212 /**
2213 * Payment method
2214 *
2215 * @param string $name Payment method name.
2216 * @return array
2217 */
2218 function usces_get_payments_by_name( $name ) {
2219
2220 $init = array(
2221 'id' => null,
2222 'name' => null,
2223 'explanation' => null,
2224 'settlement' => null,
2225 'module' => null,
2226 'sort' => null,
2227 'use' => null,
2228 );
2229 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
2230 if ( empty( $payments ) ) {
2231 return $init;
2232 }
2233 if ( isset( $payments[ $name ] ) ) {
2234 return $payments[ $name ];
2235 }
2236
2237 return $init;
2238 }
2239
2240 /**
2241 * Delivery method field
2242 *
2243 * @param string $value Value.
2244 * @param string $out Return value or echo.
2245 * @return string|void
2246 */
2247 function usces_the_delivery_method( $value = '', $out = '' ) {
2248 global $usces;
2249
2250 $deli_id = apply_filters( 'usces_filter_get_available_delivery_method', $usces->get_available_delivery_method() );
2251 if ( empty( $deli_id ) ) {
2252 $html = '<p>' . __( 'No valid shipping methods.', 'usces' ) . '</p>';
2253 } else {
2254 $cdeliid = ( is_array( $deli_id ) ) ? count( $deli_id ) : 0;
2255 $html = '<select name="offer[delivery_method]" id="delivery_method_select" class="delivery_time" onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
2256 foreach ( (array) $deli_id as $id ) {
2257 $index = $usces->get_delivery_method_index( $id );
2258 if ( 0 <= $index ) {
2259 $selected = ( (string) $id === (string) $value || 1 === $cdeliid ) ? ' selected="selected"' : '';
2260 $html .= "\t<option value=\"{$id}\"{$selected}>" . esc_html( $usces->options['delivery_method'][ $index ]['name'] ) . "</option>\n";
2261 }
2262 }
2263 $html .= "</select>\n";
2264 }
2265
2266 $html = apply_filters( 'usces_filter_the_delivery_method', $html, $deli_id );
2267
2268 if ( 'return' === $out ) {
2269 return $html;
2270 } else {
2271 echo $html; // no escape due to filter.
2272 }
2273 }
2274
2275 /**
2276 * Delivery date field
2277 *
2278 * @param string $value Value.
2279 * @param string $out Return value or echo.
2280 * @return string|void
2281 */
2282 function usces_the_delivery_date( $value = '', $out = '' ) {
2283
2284 $html = "<select name=\"offer[delivery_date]\" id=\"delivery_date_select\" class=\"delivery_date\">\n";
2285 $html .= "</select>\n";
2286 $html = apply_filters( 'the_delivery_date', $html );
2287
2288 if ( 'return' === $out ) {
2289 return $html;
2290 } else {
2291 echo $html; // no escape due to filter.
2292 }
2293 }
2294
2295 /**
2296 * Delivery time field
2297 *
2298 * @param string $value Value.
2299 * @param string $out Return value or echo.
2300 * @return string|void
2301 */
2302 function usces_the_delivery_time( $value = '', $out = '' ) {
2303
2304 $html = "<div id=\"delivery_time_limit_message\"></div>\n";
2305 $html .= "<select name=\"offer[delivery_time]\" id=\"delivery_time_select\" class=\"delivery_time\">\n";
2306 $html .= "</select>\n";
2307 $html = apply_filters( 'the_delivery_time', $html );
2308
2309 if ( 'return' === $out ) {
2310 return $html;
2311 } else {
2312 echo $html; // no escape due to filter.
2313 }
2314 }
2315
2316 /**
2317 * Campaign Schedule
2318 *
2319 * @param string $flag Flag.
2320 * @param string $kind Kind.
2321 */
2322 function usces_the_campaign_schedule( $flag, $kind ) {
2323 global $usces;
2324
2325 $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' );
2326 $starttime = $usces->options['campaign_schedule']['start']['hour'] . __( 'hour', 'usces' ) . $usces->options['campaign_schedule']['start']['min'] . __( 'min', 'usces' );
2327 $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' );
2328 $endtime = $usces->options['campaign_schedule']['end']['hour'] . __( 'hour', 'usces' ) . $usces->options['campaign_schedule']['end']['min'] . __( 'min', 'usces' );
2329 if ( 'start' === $flag ) {
2330 if ( 'date' === $kind ) {
2331 echo esc_html( $startdate );
2332 } elseif ( 'datetime' === $kind ) {
2333 echo esc_html( $startdate . ' ' . $starttime );
2334 }
2335 } elseif ( 'end' === $flag ) {
2336 if ( 'date' === $kind ) {
2337 echo esc_html( $enddate );
2338 } elseif ( 'datetime' === $kind ) {
2339 echo esc_html( $enddate . ' ' . $endtime );
2340 }
2341 }
2342 }
2343
2344 /**
2345 * Display cart confirm
2346 */
2347 function usces_the_confirm() {
2348 global $usces;
2349 $usces->display_cart_confirm();
2350 }
2351
2352 /**
2353 * Inquiry
2354 */
2355 function usces_inquiry_condition() {
2356 global $error_message, $reserve, $inq_name, $inq_mailaddress, $inq_contents;
2357 require USCES_PLUGIN_DIR . '/includes/inquiry_condition.php';
2358 }
2359
2360 /**
2361 * Inquiry form
2362 */
2363 function usces_the_inquiry_form() {
2364 global $usces;
2365
2366 $error_message = '';
2367 if ( isset( $_POST['inq_name'] ) && ! WCUtils::is_blank( $_POST['inq_name'] ) ) {
2368 $inq_name = trim( wp_unslash( $_POST['inq_name'] ) );
2369 } else {
2370 $inq_name = '';
2371 if ( 'deficiency' === $usces->page ) {
2372 $error_message .= __( 'Please input your name.', 'usces' ) . '<br />';
2373 }
2374 }
2375 if ( isset( $_POST['inq_mailaddress'] ) && is_email( trim( wp_unslash( $_POST['inq_mailaddress'] ) ) ) ) {
2376 $inq_mailaddress = trim( wp_unslash( $_POST['inq_mailaddress'] ) );
2377 } elseif ( isset( $_POST['inq_mailaddress'] ) && ! is_email( trim( wp_unslash( $_POST['inq_mailaddress'] ) ) ) ) {
2378 $inq_mailaddress = trim( wp_unslash( $_POST['inq_mailaddress'] ) );
2379 if ( 'deficiency' === $usces->page ) {
2380 $error_message .= __( 'E-mail address is not correct', 'usces' ) . '<br />';
2381 }
2382 } else {
2383 $inq_mailaddress = '';
2384 if ( 'deficiency' === $usces->page ) {
2385 $error_message .= __( 'Please input your e-mail address.', 'usces' ) . '<br />';
2386 }
2387 }
2388 if ( isset( $_POST['inq_contents'] ) && ! WCUtils::is_blank( $_POST['inq_contents'] ) ) {
2389 $inq_contents = trim( wp_unslash( $_POST['inq_contents'] ) );
2390 } else {
2391 $inq_contents = '';
2392 if ( 'deficiency' === $usces->page ) {
2393 $error_message .= __( 'Please input contents.', 'usces' );
2394 }
2395 }
2396
2397 if ( 'inquiry_comp' === $usces->page ) :
2398 $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' ) );
2399 ?>
2400 <div class="inquiry_comp"><?php esc_html_e( 'sending completed', 'usces' ); ?></div>
2401 <div class="compbox"><?php wel_esc_script_e( $inq_message ); ?></div>
2402 <?php
2403 elseif ( 'inquiry_error' === $usces->page ) :
2404 ?>
2405 <div class="inquiry_comp"><?php esc_html_e( 'Failure in sending', 'usces' ); ?></div>
2406 <?php
2407 else :
2408 ?>
2409 <?php if ( ! empty( $error_message ) ) : ?>
2410 <div class="error_message"><?php wel_esc_script_e( $error_message ); ?></div>
2411 <?php endif; ?>
2412 <form name="inquiry_form" method="post">
2413 <input type="hidden" name="kakuninyou" />
2414 <table border="0" cellpadding="0" cellspacing="0" class="inquiry_table">
2415 <tr>
2416 <th scope="row"><?php esc_html_e( 'Full name', 'usces' ); ?></th>
2417 <td><input name="inq_name" type="text" class="inquiry_name" value="<?php echo esc_attr( $inq_name ); ?>" /></td>
2418 </tr>
2419 <tr>
2420 <th scope="row"><?php esc_html_e( 'e-mail adress', 'usces' ); ?></th>
2421 <td><input name="inq_mailaddress" type="text" class="inquiry_mailaddress" value="<?php echo esc_attr( $inq_mailaddress ); ?>" /></td>
2422 </tr>
2423 <tr>
2424 <th scope="row"><?php esc_html_e( 'contents', 'usces' ); ?></th>
2425 <td><textarea name="inq_contents" class="inquiry_contents"><?php echo esc_attr( $inq_contents ); ?></textarea></td>
2426 </tr>
2427 </table>
2428 <div class="send"><input name="inquiry_button" type="submit" value="<?php esc_attr_e( 'Admit to send it with this information.', 'usces' ); ?>" /></div>
2429 </form>
2430 <?php
2431 endif;
2432 }
2433
2434 /**
2435 * Get Category ID
2436 *
2437 * @param string $slug Slag.
2438 * @return int
2439 */
2440 function usces_get_cat_id( $slug ) {
2441 $cat = get_category_by_slug( $slug );
2442 $term_id = $cat->term_id ?? 0;
2443 return $term_id;
2444 }
2445
2446 /**
2447 * Widget Calendar
2448 */
2449 function usces_the_calendar() {
2450 global $usces;
2451 include USCES_PLUGIN_DIR . '/includes/widget_calendar.php';
2452 }
2453
2454 /**
2455 * Login/Logout link
2456 *
2457 * @param string $out Return value or echo.
2458 * @return string|void
2459 */
2460 function usces_loginout( $out = '' ) {
2461 global $usces;
2462
2463 if ( ! $usces->is_member_logged_in() ) {
2464 $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>';
2465 } else {
2466 $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>';
2467 }
2468 if ( 'return' === $out ) {
2469 return wel_esc_script( $res );
2470 } else {
2471 wel_esc_script_e( $res );
2472 }
2473 }
2474
2475 /**
2476 * Is Login
2477 *
2478 * @return bool
2479 */
2480 function usces_is_login() {
2481 global $usces;
2482
2483 if ( false === $usces->is_member_logged_in() ) {
2484 $res = false;
2485 } else {
2486 $res = true;
2487 }
2488 return $res;
2489 }
2490
2491 /**
2492 * Member Name
2493 *
2494 * @param string $out Return value or echo.
2495 * @return string|void
2496 */
2497 function usces_the_member_name( $out = '' ) {
2498 global $usces;
2499
2500 $usces->get_current_member();
2501 $res = esc_html( $usces->current_member['name'] );
2502 if ( 'return' === $out ) {
2503 return wel_esc_script( $res );
2504 } else {
2505 wel_esc_script_e( $res );
2506 }
2507 }
2508
2509 /**
2510 * Membership Point
2511 *
2512 * @param string $out Return value or echo.
2513 * @return string|void
2514 */
2515 function usces_the_member_point( $out = '' ) {
2516 global $usces;
2517
2518 if ( ! $usces->is_member_logged_in() ) {
2519 return;
2520 }
2521
2522 $member = $usces->get_member();
2523
2524 if ( 'return' === $out ) {
2525 return $member['point'];
2526 } else {
2527 echo number_format( $member['point'] );
2528 }
2529 }
2530
2531 /**
2532 * Membership Rank
2533 *
2534 * @param string $out Return value or echo.
2535 * @return string|void
2536 */
2537 function usces_the_member_status( $out = '' ) {
2538 global $usces;
2539
2540 if ( ! $usces->is_member_logged_in() ) {
2541 return;
2542 }
2543
2544 $usces->get_current_member();
2545 $member = $usces->get_member_info( $usces->current_member['id'] );
2546 $status_name = $usces->member_status[ $member['mem_status'] ];
2547
2548 if ( 'return' === $out ) {
2549 return $status_name;
2550 } else {
2551 echo esc_html( $status_name );
2552 }
2553 }
2554
2555 /**
2556 * Related item list
2557 *
2558 * @param int $post_id Post ID.
2559 * @return array
2560 */
2561 function usces_get_assistance_id_list( $post_id ) {
2562 global $usces;
2563
2564 $names = $usces->get_tag_names( $post_id );
2565 $list = '';
2566 foreach ( (array) $names as $itemname ) {
2567 $list .= $usces->get_ID_byItemName( $itemname, 'publish' ) . ',';
2568 }
2569 $list = trim( $list, ',' );
2570 return $list;
2571 }
2572
2573 /**
2574 * Related item
2575 *
2576 * @param int $post_id Post ID.
2577 * @return array
2578 */
2579 function usces_get_assistance_ids( $post_id ) {
2580 global $usces;
2581
2582 $names = $usces->get_tag_names( $post_id );
2583 $ids = array();
2584 foreach ( $names as $itemname ) {
2585 $ids[] = $usces->get_ID_byItemName( $itemname, 'publish' );
2586 }
2587 return $ids;
2588 }
2589
2590 /**
2591 * Forgot account
2592 *
2593 * @param string $out Return value or echo.
2594 * @return string|void
2595 */
2596 function usces_remembername( $out = '' ) {
2597 global $usces;
2598
2599 $value = $usces->get_cookie();
2600 if ( 'return' === $out ) {
2601 // if ( isset( $value['name'] ) )
2602 // return $value['name'];
2603 // else
2604 return '';
2605 } else {
2606 // if ( isset( $value['name'] ) )
2607 // echo esc_html( $value['name'] );
2608 // else
2609 echo '';
2610 }
2611 }
2612
2613 /**
2614 * Forgot password
2615 *
2616 * @param string $out Return value or echo.
2617 * @return string|void
2618 */
2619 function usces_rememberpass( $out = '' ) {
2620 global $usces;
2621
2622 $value = $usces->get_cookie();
2623 if ( 'return' === $out ) {
2624 // if ( isset( $value['pass'] ) )
2625 // return $value['pass'];
2626 // else
2627 return '';
2628 } else {
2629 // if ( isset( $value['pass'] ) )
2630 // echo esc_html( $value['pass'] );
2631 // else
2632 echo '';
2633 }
2634 }
2635
2636 /**
2637 * Forgot account check
2638 *
2639 * @param string $out Return value or echo.
2640 * @return string|void
2641 */
2642 function usces_remembercheck( $out = '' ) {
2643 global $usces;
2644
2645 $value = $usces->get_cookie();
2646 if ( 'return' === $out ) {
2647 // if ( isset( $value['name'] ) && $value['name'] != '' )
2648 // return ' checked="checked"';
2649 // else
2650 return '';
2651 } else {
2652 // if ( isset( $value['name'] ) && $value['name'] != '' )
2653 // echo ' checked="checked"';
2654 // else
2655 echo '';
2656 }
2657 }
2658
2659 /**
2660 * Shipping charge table
2661 *
2662 * @param string $index Index.
2663 */
2664 function usces_shippingchargeTR( $index = '' ) {
2665 global $usces;
2666
2667 if ( '' === $index ) {
2668 $index = 0;
2669 }
2670 $list = '';
2671 if ( ! isset( $usces->options['shipping_charge'][ $index ] ) ) {
2672 return;
2673 }
2674 $shipping_charge = $usces->options['shipping_charge'][ $index ];
2675 $entry = $usces->cart->get_entry();
2676 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
2677 foreach ( $shipping_charge[ $country ] as $pref => $value ) {
2678 $list .= '<tr><th>' . esc_html( $pref ) . "</th>\n";
2679 $list .= '<td class="rightnum">' . number_format( $value ) . "</td>\n";
2680 $list .= "</tr>\n";
2681 }
2682 wel_esc_script_e( $list );
2683 }
2684
2685 /**
2686 * Shipping charge
2687 */
2688 function usces_sc_shipping_charge() {
2689 global $usces;
2690 echo esc_html( $usces->sc_shipping_charge() );
2691 }
2692
2693 /**
2694 * Postage privilege
2695 */
2696 function usces_sc_postage_privilege() {
2697 global $usces;
2698 echo esc_html( $usces->sc_postage_privilege() );
2699 }
2700
2701 /**
2702 * Payment title
2703 */
2704 function usces_sc_payment_title() {
2705 global $usces;
2706 wel_esc_script_e( $usces->sc_payment_title() );
2707 }
2708
2709 /**
2710 * Posts offset
2711 *
2712 * @param object $posts Post data.
2713 * @return int
2714 */
2715 function usces_posts_random_offset( $posts ) {
2716 $ids = array();
2717 foreach ( (array) $posts as $post ) {
2718 $ids[] = $post->ID;
2719 }
2720 $ct = count( $ids );
2721 $index = rand( 0, ( $ct - 1 ) );
2722 return $index;
2723 }
2724
2725 /**
2726 * Get category link
2727 *
2728 * @param string $slug Slug.
2729 */
2730 function usces_get_category_link_by_slug( $slug ) {
2731 $category = get_category_by_slug( $slug );
2732 echo get_category_link( $category->term_id );
2733 }
2734
2735 /**
2736 * Get page ID
2737 *
2738 * @param string $post_name Post name.
2739 * @param string $return Return value or echo.
2740 * @return string|void
2741 */
2742 function usces_get_page_ID_by_pname( $post_name, $return = 'echo' ) {
2743 $page = get_page_by_path( $post_name );
2744 if ( 'return' === $return ) {
2745 return $page->ID;
2746 } else {
2747 echo esc_attr( $page->ID );
2748 }
2749 }
2750
2751 /**
2752 * Bestseller
2753 *
2754 * @param int $num Number.
2755 * @param string $days Days.
2756 */
2757 function usces_list_bestseller( $num, $days = '' ) {
2758 global $usces;
2759
2760 $ids = $usces->get_bestseller_ids( $days );
2761 $htm = '';
2762 for ( $i = 0; $i < $num; $i++ ) {
2763 if ( isset( $ids[ $i ] ) ) {
2764 $post_id = (int) $ids[ $i ];
2765 $product = wel_get_product( $post_id );
2766 $post = $product['_pst'];
2767
2768 if ( false === $product ) {
2769 continue;
2770 }
2771
2772 $disp_text = apply_filters( 'usces_widget_bestseller_auto_text', esc_html( $post->post_title ), $post_id );
2773 $list = '<li><a href="' . get_permalink( $post_id ) . '">' . $disp_text . "</a></li>\n";
2774 $htm .= apply_filters( 'usces_filter_bestseller', $list, $post_id, $i );
2775 }
2776 }
2777 wp_reset_postdata();
2778 wel_esc_script_e( $htm );
2779 }
2780
2781 /**
2782 * Post list
2783 *
2784 * @param string $slug Slug.
2785 * @param string $rownum Page number.
2786 * @param string $widget_id Widget ID.
2787 */
2788 function usces_list_post( $slug, $rownum, $widget_id = null ) {
2789 global $post;
2790
2791 usces_remove_filter();
2792
2793 $li = '';
2794 $infolist = new WP_Query( array( 'category_name' => $slug, 'post_status' => 'publish', 'posts_per_page' => $rownum, 'order' => 'DESC', 'orderby' => 'date' ) );
2795 if ( null !== $widget_id && $infolist->have_posts() ) {
2796 remove_filter( 'excerpt_length', 'welcart_excerpt_length' );
2797 remove_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' );
2798 remove_filter( 'excerpt_more', 'welcart_auto_excerpt_more' );
2799 if ( function_exists( 'welcart_widget_post_excerpt_length_' . $widget_id ) ) {
2800 add_filter( 'excerpt_length', 'welcart_widget_post_excerpt_length_' . $widget_id );
2801 }
2802 if ( function_exists( 'welcart_widget_post_excerpt_mblength_' . $widget_id ) ) {
2803 add_filter( 'excerpt_mblength', 'welcart_widget_post_excerpt_mblength_' . $widget_id );
2804 }
2805 }
2806 $list_index = 0;
2807 while ( $infolist->have_posts() ) {
2808 $infolist->the_post();
2809 $list = '<li class="post_list' . apply_filters( 'usces_filter_post_list_class', null, $list_index, $infolist->post_count ) . '">' . "\n";
2810 $list .= "<div class='title'><a href='" . get_permalink( $post->ID ) . "'>" . get_the_title() . "</a></div>\n";
2811 $list .= '<p>' . get_the_excerpt() . "</p>\n";
2812 $list .= "</li>\n";
2813 $li .= apply_filters( 'usces_filter_widget_post', $list, $post, $slug, $list_index );
2814 $list_index++;
2815 }
2816 wp_reset_postdata();
2817 usces_reset_filter();
2818 if ( null !== $widget_id && $infolist->have_posts() ) {
2819 add_filter( 'excerpt_length', 'welcart_excerpt_length' );
2820 add_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' );
2821 add_filter( 'excerpt_more', 'welcart_auto_excerpt_more' );
2822 }
2823 wel_esc_script_e( $li );
2824 }
2825
2826 /**
2827 * Category checkbox
2828 *
2829 * @param string $output Return value or echo.
2830 * @return string|void
2831 */
2832 function usces_categories_checkbox( $output = '' ) {
2833
2834 $retcats = apply_filters( 'usces_search_retcats', usces_search_categories() );
2835 $parent_id = apply_filters( 'usces_search_categories_checkbox_parent', USCES_ITEM_CAT_PARENT_ID );
2836 $htm = usces_get_categories_checkbox( $parent_id );
2837 $htm = apply_filters( 'usces_filter_categories_checkbox', $htm, $parent_id );
2838
2839 if ( '' === $output || 'echo' === $output ) {
2840 wel_esc_script_e( $htm );
2841 } else {
2842 return wel_esc_script( $htm );
2843 }
2844 }
2845
2846 /**
2847 * Category checkbox
2848 *
2849 * @param int $parent_id Parent category ID.
2850 */
2851 function usces_get_categories_checkbox( $parent_id ) {
2852 global $usces;
2853
2854 $htm = '';
2855 $retcats = usces_search_categories();
2856 $parent_cat = get_category( $parent_id );
2857 $categories = get_categories( 'parent=' . $parent_id . '&hide_empty=0&orderby=' . $usces->options['fukugo_category_orderby'] . '&order=' . $usces->options['fukugo_category_order'] );
2858 $htm .= '<fieldset class="catfield-' . $parent_cat->term_id . '"><legend>' . $parent_cat->cat_name . "</legend><ul>\n";
2859 foreach ( $categories as $cat ) {
2860 $children = get_categories( 'parent=' . $cat->term_id . '&hide_empty=0' );
2861 if ( 0 === count( $children ) ) {
2862 $checked = in_array( $cat->term_id, $retcats ) ? ' checked="checked"' : '';
2863 $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";
2864 }
2865 }
2866 $htm .= "</ul>\n";
2867 foreach ( $categories as $cat ) {
2868 $children = get_categories( 'parent=' . $cat->term_id . '&hide_empty=0' );
2869 if ( 0 < count( $children ) ) {
2870 $htm .= usces_get_categories_checkbox( $cat->term_id );
2871 }
2872 }
2873 $htm .= "</fieldset>\n";
2874
2875 return $htm;
2876 }
2877
2878 /**
2879 * Search categories
2880 *
2881 * @return array
2882 */
2883 function usces_search_categories() {
2884 $cats = array();
2885 if ( isset( $_REQUEST['category'] ) ) {
2886 $cats = wp_unslash( $_REQUEST['category'] );
2887 } else {
2888 $cats[] = USCES_ITEM_CAT_PARENT_ID;
2889 }
2890 sort( $cats );
2891 return $cats;
2892 }
2893
2894 /**
2895 * Delivery method name
2896 *
2897 * @param int $id Delivery ID.
2898 * @param string $out Return value or echo.
2899 * @return string|void
2900 */
2901 function usces_delivery_method_name( $id, $out = '' ) {
2902 global $usces;
2903
2904 $id = $usces->get_delivery_method_index( $id );
2905 if ( $id > -1 ) {
2906 $name = $usces->options['delivery_method'][ $id ]['name'];
2907 } else {
2908 $name = __( 'No preference', 'usces' );
2909 }
2910
2911 if ( 'return' === $out ) {
2912 return $name;
2913 } else {
2914 echo esc_html( $name );
2915 }
2916 }
2917
2918 /**
2919 * Use membership system
2920 *
2921 * @return bool
2922 */
2923 function usces_is_membersystem_state() {
2924 global $usces;
2925
2926 if ( 'activate' === $usces->options['membersystem_state'] ) {
2927 return true;
2928 } else {
2929 return false;
2930 }
2931 }
2932
2933 /**
2934 * Use membership point
2935 *
2936 * @return bool
2937 */
2938 function usces_is_membersystem_point() {
2939 global $usces;
2940
2941 if ( 'activate' === $usces->options['membersystem_point'] ) {
2942 return true;
2943 } else {
2944 return false;
2945 }
2946 }
2947
2948 /**
2949 * Copyright
2950 */
2951 function usces_copyright() {
2952 global $usces;
2953 echo esc_html( $usces->options['copyright'] );
2954 }
2955
2956 /**
2957 * Total amount in cart
2958 */
2959 function usces_totalprice_in_cart() {
2960 global $usces;
2961 echo number_format( $usces->get_total_price() );
2962 }
2963
2964 /**
2965 * Total quantities in cart
2966 */
2967 function usces_totalquantity_in_cart() {
2968 global $usces;
2969 echo number_format( $usces->get_total_quantity() );
2970 }
2971
2972 /**
2973 * Page mode
2974 *
2975 * @return string
2976 */
2977 function usces_get_page_mode() {
2978 global $usces;
2979 return $usces->page;
2980 }
2981
2982 /**
2983 * Is in item category
2984 *
2985 * @param int $cat_id Category ID.
2986 * @return bool
2987 */
2988 function usces_is_cat_of_item( $cat_id ) {
2989 global $usces;
2990
2991 $ids = $usces->get_item_cat_ids();
2992 $ids[] = USCES_ITEM_CAT_PARENT_ID;
2993 if ( in_array( $cat_id, $ids ) ) {
2994 return true;
2995 } else {
2996 return false;
2997 }
2998 }
2999
3000 /**
3001 * Item custom field
3002 *
3003 * @param int $post_id Post ID.
3004 * @param string $type Type.
3005 * @param string $out Return value or echo.
3006 * @return string|void
3007 */
3008 function usces_get_item_custom( $post_id, $type = 'list', $out = '' ) {
3009 global $usces;
3010
3011 $cfields = wel_get_extra_data( $post_id );
3012 $html = '';
3013
3014 switch ( $type ) {
3015 case 'list':
3016 $list = '';
3017 $html = '<ul class="item_custom_field">' . "\n";
3018 foreach ( $cfields as $key => $values ) {
3019 if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3020 if ( is_array( $values ) ) {
3021 foreach ( $values as $value ) {
3022 $list .= '<li>' . esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $value ) ) . '</li>' . "\n";
3023 }
3024 } else {
3025 $list .= '<li>' . esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $values ) ) . '</li>' . "\n";
3026 }
3027 }
3028 }
3029 if ( empty( $list ) ) {
3030 $html = '';
3031 } else {
3032 $html .= $list . '</ul>' . "\n";
3033 }
3034 break;
3035
3036 case 'table':
3037 $list = '';
3038 $html = '<table class="item_custom_field">' . "\n";
3039 foreach ( $cfields as $key => $values ) {
3040 if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3041 if ( is_array( $values ) ) {
3042 foreach ( $values as $value ) {
3043 $list .= '<tr><th>' . esc_html( substr( $key, 5 ) ) . '</th><td>' . nl2br( esc_html( $value ) ) . '</td></tr>' . "\n";
3044 }
3045 } else {
3046 $list .= '<tr><th>' . esc_html( substr( $key, 5 ) ) . '</th><td>' . nl2br( esc_html( $values ) ) . '</td></tr>' . "\n";
3047 }
3048 }
3049 }
3050 if ( empty( $list ) ) {
3051 $html = '';
3052 } else {
3053 $html .= $list . '</table>' . "\n";
3054 }
3055 break;
3056
3057 case 'notag':
3058 $list = '';
3059 foreach ( $cfields as $key => $values ) {
3060 if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3061 if ( is_array( $values ) ) {
3062 foreach ( $values as $value ) {
3063 $list .= esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $value ) ) . "\r\n";
3064 }
3065 } else {
3066 $list .= esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $values ) ) . "\r\n";
3067 }
3068 }
3069 }
3070 if ( empty( $list ) ) {
3071 $html = '';
3072 } else {
3073 $html = $list;
3074 }
3075 break;
3076
3077 case 'mail_html':
3078 $list = '';
3079 foreach ( $cfields as $key => $values ) {
3080 if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3081 if ( is_array( $values ) ) {
3082 foreach ( $values as $value ) {
3083 $list .= '<tr>
3084 <td style="padding: 0 0 10px; text-align: left; width: 100px; font-weight: normal; vertical-align: text-top;">' . esc_html( substr( $key, 5 ) ) . '</td>
3085 <td style="padding: 0 0 10px 50px; width: calc( 100% - 100px );">' . nl2br( esc_html( $value ) ) . '</td>
3086 </tr>';
3087 }
3088 } else {
3089 $list .= '<tr>
3090 <td style="padding: 0 0 10px; text-align: left; width: 100px; font-weight: normal; vertical-align: text-top;">' . esc_html( substr( $key, 5 ) ) . '</td>
3091 <td style="padding: 0 0 10px 50px; width: calc( 100% - 100px );">' . nl2br( esc_html( $values ) ) . '</td>
3092 </tr>';
3093 }
3094 }
3095 }
3096 if ( empty( $list ) ) {
3097 $html = '';
3098 } else {
3099 $html = '<table style="font-size: 14px; width: 100%; border-collapse: collapse;">';
3100 $html .= '<tbody><tr><td style="background-color: #f9f9f9; padding: 30px;">';
3101 $html .= '<table style="width: 100%;"><tbody>';
3102 $html .= $list;
3103 $html .= '</tbody></table></td></tr></tbody></table>';
3104 }
3105 break;
3106 }
3107 $html = apply_filters( 'usces_filter_item_custom', $html, $post_id, $type );
3108
3109 if ( 'return' === $out ) {
3110 return $html;
3111 } else {
3112 echo $html; // no escape due to filter.
3113 }
3114 }
3115
3116 /**
3117 * Settlement information
3118 *
3119 * @param int $order_id Order ID.
3120 * @param string $type Type.
3121 * @param string $out Return value or echo.
3122 * @return string|void
3123 */
3124 function usces_settle_info_field( $order_id, $type = 'nl', $out = 'echo' ) {
3125 global $usces;
3126
3127 $str = '';
3128 $fields = $usces->get_settle_info_field( $order_id );
3129 $acting = isset( $fields['acting'] ) ? $fields['acting'] : '';
3130 $keys = array(
3131 'acting',
3132 'order_no',
3133 'tracking_no',
3134 'status',
3135 'error_message',
3136 'money',
3137 'pay_cvs',
3138 'pay_no1',
3139 'pay_no2',
3140 'pay_limit',
3141 'error_code',
3142 'settlement_id',
3143 'RECDATE',
3144 'JOB_ID',
3145 'S_TORIHIKI_NO',
3146 'TOTAL',
3147 'CENDATE',
3148 'gid',
3149 'rst',
3150 'ap',
3151 'ec',
3152 'god',
3153 'ta',
3154 'cv',
3155 'no',
3156 'cu',
3157 'mf',
3158 'nk',
3159 'nkd',
3160 'bank',
3161 'exp',
3162 'txn_id',
3163 'order_number',
3164 'res_tracking_id',
3165 'res_payment_date',
3166 'res_payinfo_key',
3167 'settltment_status',
3168 'settltment_errmsg',
3169 'stran',
3170 'mbtran',
3171 'bktrans',
3172 'tranid',
3173 'TransactionId',
3174 'mStatus',
3175 'vResultCode',
3176 'orderId',
3177 'cvsType',
3178 'receiptNo',
3179 'receiptDate',
3180 'rcvAmount',
3181 'trading_id',
3182 'payment_type',
3183 'seq_payment_id',
3184 'sendpoint',
3185 'option',
3186 'LINK_KEY',
3187 );
3188 $keys = apply_filters( 'usces_filter_settle_info_field_keys', $keys, $fields );
3189 foreach ( $fields as $key => $value ) {
3190 if ( ! in_array( $key, $keys, true ) ) {
3191 continue;
3192 }
3193
3194 if ( 'jpayment_conv' === $acting ) {
3195 if ( 'rst' === $key ) {
3196 if ( '1' === $value ) {
3197 $value = 'OK';
3198 } elseif ( '2' === $value ) {
3199 $value = 'NG';
3200 }
3201 } elseif ( 'ap' === $key ) {
3202 if ( 'CPL_PRE' === $value ) {
3203 $value = 'コンビニペーパーレス決済識別コード';
3204 } elseif ( 'CPL' === $value ) {
3205 $value = '�
3206 �金確定';
3207 } elseif ( 'CVS_CAN' === $value ) {
3208 $value = '�
3209 �金取消';
3210 }
3211 } elseif ( 'cv' === $key ) {
3212 $value = esc_html( usces_get_conv_name( $value ) );
3213 } else {
3214 continue;
3215 }
3216 } elseif ( 'jpayment_bank' === $acting ) {
3217 if ( 'rst' === $key ) {
3218 if ( '1' === $value ) {
3219 $value = 'OK';
3220 } elseif ( '2' === $value ) {
3221 $value = 'NG';
3222 }
3223 } elseif ( 'ap' === $key ) {
3224 if ( 'BANK' === $value ) {
3225 $value = '受付完了';
3226 } elseif ( 'BAN_SAL' === $value ) {
3227 $value = '�
3228 �金完了';
3229 }
3230 } elseif ( 'mf' === $key ) {
3231 if ( '1' === $value ) {
3232 $value = 'マッチ';
3233 } elseif ( '2' === $value ) {
3234 $value = '過少';
3235 } elseif ( '3' === $value ) {
3236 $value = '過剰';
3237 }
3238 } elseif ( 'nkd' === $key ) {
3239 $value = substr( $value, 0, 4 ) . '' . substr( $value, 4, 2 ) . '' . substr( $value, 6, 2 ) . '';
3240 } elseif ( 'exp' === $key ) {
3241 $value = substr( $value, 0, 4 ) . '' . substr( $value, 4, 2 ) . '' . substr( $value, 6, 2 ) . '';
3242 } else {
3243 continue;
3244 }
3245 } elseif ( 'veritrans_conv' === $acting ) {
3246 if ( 'cvsType' === $key ) {
3247 switch ( $value ) {
3248 case 'sej':
3249 $value = 'セブン-イレブン';
3250 break;
3251 case 'econ-lw':
3252 $value = 'ローソン';
3253 break;
3254 case 'econ-fm':
3255 $value = 'ファミリーマート';
3256 break;
3257 case 'econ-mini':
3258 $value = 'ミニストップ';
3259 break;
3260 case 'econ-other':
3261 $value = 'セイコーマート';
3262 break;
3263 case 'econ-sn':
3264 $value = 'サンクス';
3265 break;
3266 case 'econ-ck':
3267 $value = 'サークルK';
3268 break;
3269 }
3270 }
3271 }
3272 $value = apply_filters( 'usces_filter_settle_info_field_value', $value, $key, $acting );
3273 switch ( $type ) {
3274 case 'nl':
3275 $str .= $key . ' : ' . $value . "<br />\n";
3276 break;
3277 case 'tr':
3278 $str .= '<tr><td class="label">' . $key . '</td><td>' . $value . "</td></tr>\n";
3279 break;
3280 case 'li':
3281 $str .= '<li>' . $key . ' : ' . $value . "</li>\n";
3282 break;
3283 }
3284 }
3285 if ( 'return' === $out ) {
3286 return wel_esc_script( $str );
3287 } else {
3288 wel_esc_script_e( $str );
3289 }
3290 }
3291
3292 /**
3293 * Custom field
3294 *
3295 * @param array $data Order data.
3296 * @param string $custom_field Custom field.
3297 * @param string $position Position.
3298 * @param string $out Return value or echo.
3299 * @return string|void
3300 */
3301 function usces_custom_field_input( $data, $custom_field, $position, $out = '' ) {
3302
3303 $html = '';
3304
3305 switch ( $custom_field ) {
3306 case 'order':
3307 $label = 'custom_order';
3308 $field = 'usces_custom_order_field';
3309 break;
3310 case 'customer':
3311 $label = 'custom_customer';
3312 $field = 'usces_custom_customer_field';
3313 break;
3314 case 'delivery':
3315 $label = 'custom_delivery';
3316 $field = 'usces_custom_delivery_field';
3317 break;
3318 case 'member':
3319 $label = 'custom_member';
3320 $field = 'usces_custom_member_field';
3321 break;
3322 default:
3323 return;
3324 }
3325
3326 $meta = usces_has_custom_field_meta( $custom_field );
3327
3328 if ( ! empty( $meta ) && is_array( $meta ) ) {
3329 foreach ( $meta as $key => $entry ) {
3330 if ( 'order' === $custom_field || $entry['position'] === $position ) {
3331 $name = $entry['name'];
3332 $means = (int) $entry['means'];
3333 $essential = (int) $entry['essential'];
3334 $value = '';
3335 if ( is_array( $entry['value'] ) ) {
3336 foreach ( $entry['value'] as $k => $v ) {
3337 $value .= $v . "\n";
3338 }
3339 }
3340 $value = usces_change_line_break( $value );
3341
3342 $e = ( 1 === $essential ) ? '<em>' . __( '*', 'usces' ) . '</em>' : '';
3343 $html .= '
3344 <tr class="customkey_' . $key . '">
3345 <th scope="row">' . $e . esc_html( $name ) . apply_filters( 'usces_filter_custom_field_input_label', null, $key, $entry ) . '</th>';
3346 $html .= apply_filters( 'usces_filter_custom_field_input_td', '<td colspan="2">', $key, $entry );
3347 switch ( $means ) {
3348 case 0: // Single-select.
3349 case 1: // Multi-select.
3350 $selects = explode( "\n", $value );
3351 $multiple = ( 0 === $means ) ? '' : ' multiple';
3352 $multiple_array = ( 0 === $means ) ? '' : '[]';
3353 $html .= '<select name="' . $label . '[' . esc_attr( $key ) . ']' . $multiple_array . '" class="iopt_select"' . $multiple . '>';
3354 if ( 1 === $essential ) {
3355 $html .= '
3356 <option value="#NONE#">' . __( 'Choose', 'usces' ) . '</option>';
3357 }
3358 foreach ( (array) $selects as $v ) {
3359 $selected = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' selected' : '';
3360 $html .= '
3361 <option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_html( $v ) . '</option>';
3362 }
3363 $html .= '
3364 </select>';
3365 break;
3366 case 2: // Text.
3367 $text = isset( $data[ $label ][ $key ] ) ? $data[ $label ][ $key ] : '';
3368 $html .= '<input type="text" name="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_text" value="' . esc_attr( $text ) . '" />';
3369 break;
3370 case 3: // Radio-button.
3371 $selects = explode( "\n", $value );
3372 foreach ( (array) $selects as $v ) {
3373 $checked = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' checked' : '';
3374 $html .= '
3375 <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>';
3376 }
3377 break;
3378 case 4: // Check-box.
3379 $selects = explode( "\n", $value );
3380 foreach ( $selects as $v ) {
3381 if ( isset( $data[ $label ][ $key ] ) && is_array( $data[ $label ][ $key ] ) ) {
3382 $checked = ( isset( $data[ $label ][ $key ] ) && array_key_exists( $v, $data[ $label ][ $key ] ) ) ? ' checked' : '';
3383 } else {
3384 $checked = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' checked' : '';
3385 }
3386 $html .= '
3387 <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 }
3389 break;
3390 case 5: // Text-area.
3391 $text = ( isset( $data[ $label ][ $key ] ) ) ? $data[ $label ][ $key ] : '';
3392 $html .= '<textarea name="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_textarea">' . esc_attr( $text ) . '</textarea>';
3393 break;
3394 }
3395 $html .= apply_filters( 'usces_filter_custom_field_input_value', null, $key, $entry ) . '</td>';
3396 $html .= '
3397 </tr>';
3398 }
3399 }
3400 }
3401
3402 $html = apply_filters( 'usces_filter_custom_field_input', $html, $data, $custom_field, $position );
3403
3404 if ( 'return' === $out ) {
3405 return stripslashes( $html );
3406 } else {
3407 echo stripslashes( $html );
3408 }
3409 }
3410
3411 /**
3412 * Custom field information
3413 *
3414 * @param array $data Order data.
3415 * @param string $custom_field Custom field.
3416 * @param string $position Position.
3417 * @param string $out Return value or echo.
3418 * @return string|void
3419 */
3420 function usces_custom_field_info( $data, $custom_field, $position, $out = '' ) {
3421
3422 $html = '';
3423 switch ( $custom_field ) {
3424 case 'order':
3425 $label = 'custom_order';
3426 $field = 'usces_custom_order_field';
3427 break;
3428 case 'customer':
3429 $label = 'custom_customer';
3430 $field = 'usces_custom_customer_field';
3431 break;
3432 case 'delivery':
3433 $label = 'custom_delivery';
3434 $field = 'usces_custom_delivery_field';
3435 break;
3436 case 'member':
3437 $label = 'custom_member';
3438 $field = 'usces_custom_member_field';
3439 break;
3440 default:
3441 return;
3442 }
3443
3444 $meta = usces_has_custom_field_meta( $custom_field );
3445
3446 if ( ! empty( $meta ) && is_array( $meta ) ) {
3447 foreach ( $meta as $key => $entry ) {
3448 if ( 'order' === $custom_field || $entry['position'] === $position ) {
3449 $name = $entry['name'];
3450 $means = (int) $entry['means'];
3451
3452 $html .= '<tr>
3453 <th>' . esc_html( $name ) . '</th>
3454 <td>';
3455 if ( ! empty( $data[ $label ][ $key ] ) ) {
3456 switch ( $means ) {
3457 case 0: // Single-select.
3458 case 2: // Text.
3459 case 3: // Radio-button.
3460 case 5: // Text-area.
3461 $html .= esc_html( $data[ $label ][ $key ] );
3462 break;
3463 case 1: // Multi-select.
3464 case 4: // Check-box.
3465 if ( is_array( $data[ $label ][ $key ] ) ) {
3466 $c = '';
3467 foreach ( $data[ $label ][ $key ] as $v ) {
3468 $html .= $c . esc_html( $v );
3469 $c = ', ';
3470 }
3471 } else {
3472 if ( ! empty( $data[ $label ][ $key ] ) ) {
3473 $html .= esc_html( $data[ $label ][ $key ] );
3474 }
3475 }
3476 break;
3477 }
3478 }
3479 $html .= '
3480 </td>
3481 </tr>';
3482 }
3483 }
3484 }
3485
3486 $html = apply_filters( 'usces_filter_custom_field_info', $html, $data, $custom_field, $position );
3487
3488 if ( 'return' === $out ) {
3489 return stripslashes( $html );
3490 } else {
3491 echo stripslashes( $html );
3492 }
3493 }
3494
3495 /**
3496 * Admin Custom field
3497 *
3498 * @param array $meta Order meta data.
3499 * @param string $custom_field Custom field.
3500 * @param string $position Position.
3501 * @param string $out Return value or echo.
3502 * @return string|void
3503 */
3504 function usces_admin_custom_field_input( $meta, $custom_field, $position, $out = '' ) {
3505
3506 $html = '';
3507 switch ( $custom_field ) {
3508 case 'order':
3509 $label = 'custom_order';
3510 $class = '';
3511 break;
3512 case 'customer':
3513 $label = 'custom_customer';
3514 $class = ' class="col2"';
3515 break;
3516 case 'delivery':
3517 $label = 'custom_delivery';
3518 $class = ' class="col3"';
3519 break;
3520 case 'member':
3521 $label = 'custom_member';
3522 $class = '';
3523 break;
3524 case 'admin_member':
3525 $label = 'admin_custom_member';
3526 $class = '';
3527 break;
3528 default:
3529 return;
3530 }
3531
3532 if ( ! empty( $meta ) && is_array( $meta ) ) {
3533 foreach ( $meta as $key => $entry ) {
3534 if ( 'order' === $custom_field || $entry['position'] === $position ) {
3535 $name = $entry['name'];
3536 $means = (int) $entry['means'];
3537 $essential = (int) $entry['essential'];
3538 $value = '';
3539 if ( is_array( $entry['value'] ) ) {
3540 foreach ( $entry['value'] as $k => $v ) {
3541 $value .= $v . "\n";
3542 }
3543 }
3544 $value = usces_change_line_break( $value );
3545 $value = apply_filters( 'usces_filter_admin_custom_field_input_value', $value, $key, $entry, $custom_field );
3546 $data = ( isset( $entry['data'] ) ) ? $entry['data'] : null;
3547
3548 $html .= '
3549 <tr>
3550 <td class="label">' . esc_html( $name ) . '</td>';
3551 switch ( $means ) {
3552 case 0: /* Single-select */
3553 case 1: /* Multi-select */
3554 $selects = explode( "\n", $value );
3555 $multiple = ( 0 === $means ) ? '' : ' multiple';
3556 $multiple_array = ( 0 === $means ) ? '' : '[]';
3557 $html .= '
3558 <td' . $class . '>
3559 <select name="' . $label . '[' . esc_attr( $key ) . ']' . $multiple_array . '" id="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_select"' . $multiple . '>';
3560 if ( 1 === $essential ) {
3561 $html .= '
3562 <option value="#NONE#">' . __( 'Choose', 'usces' ) . '</option>';
3563 }
3564 foreach ( $selects as $v ) {
3565 $selected = ( $data == $v ) ? ' selected' : '';
3566 $html .= '
3567 <option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_html( $v ) . '</option>';
3568 }
3569 $html .= '
3570 </select></td>';
3571 break;
3572 case 2: /* Text */
3573 $html .= '
3574 <td' . $class . '><input type="text" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . ']" size="30" value="' . esc_attr( $data ) . '" /></td>';
3575 break;
3576 case 3: /* Radio-button */
3577 $selects = explode( "\n", $value );
3578 $html .= '
3579 <td' . $class . '>';
3580 foreach ( $selects as $v ) {
3581 $checked = ( $data == $v ) ? ' checked' : '';
3582 $html .= '
3583 <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>';
3584 }
3585 $html .= '
3586 </td>';
3587 break;
3588 case 4: /* Check-box */
3589 $selects = explode( "\n", $value );
3590 $html .= '
3591 <td' . $class . '>';
3592 foreach ( $selects as $v ) {
3593 if ( is_array( $data ) ) {
3594 $checked = ( array_key_exists( $v, $data ) ) ? ' checked' : '';
3595 } else {
3596 $checked = ( $data == $v ) ? ' checked' : '';
3597 }
3598 $html .= '
3599 <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>';
3600 }
3601 $html .= '
3602 </td>';
3603 break;
3604 case 5: /* Text-area */
3605 $html .= '
3606 <td' . $class . '><textarea name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . ']" >' . esc_attr( $data ) . '</textarea></td>';
3607 break;
3608 }
3609 $html .= '
3610 </tr>';
3611 }
3612 }
3613 }
3614 $html = apply_filters( 'usces_filter_admin_custom_field_input', $html, $meta, $custom_field, $position, $out );
3615
3616 if ( 'return' === $out ) {
3617 return stripslashes( $html );
3618 } else {
3619 echo stripslashes( $html );
3620 }
3621 }
3622
3623 /**
3624 * Required Custom Field
3625 *
3626 * @return string
3627 */
3628 function has_custom_customer_field_essential() {
3629
3630 $mes = '';
3631 $essential = array();
3632
3633 $csmb_meta = usces_has_custom_field_meta( 'member' );
3634 if ( ! empty( $csmb_meta ) && is_array( $csmb_meta ) ) {
3635 foreach ( $csmb_meta as $key => $entry ) {
3636 if ( 1 === (int) $entry['essential'] ) {
3637 $essential[ $key ] = $key;
3638 }
3639 }
3640 }
3641 if ( ! empty( $essential ) ) {
3642 $cscs_meta = usces_has_custom_field_meta( 'customer' );
3643 if ( ! empty( $cscs_meta ) && is_array( $cscs_meta ) ) {
3644 foreach ( $cscs_meta as $key => $entry ) {
3645 if ( 1 === (int) $entry['essential'] ) {
3646 if ( ! array_key_exists( $key, $essential ) ) {
3647 if ( 2 === (int) $entry['means'] ) { // Text.
3648 $mes .= sprintf( __( "Input the %s", 'usces' ), esc_html( $entry['name'] ) ) . '<br />';
3649 } else {
3650 $mes .= sprintf( __( "Chose the %s", 'usces' ), esc_html( $entry['name'] ) ) . '<br />';
3651 }
3652 }
3653 }
3654 }
3655 }
3656 }
3657 return $mes;
3658 }
3659
3660 /**
3661 * Discount
3662 *
3663 * @param string $out Return value or echo.
3664 * @return string|void
3665 */
3666 function usces_order_discount( $out = '' ) {
3667 global $usces;
3668
3669 $res = abs( $usces->get_order_discount() );
3670
3671 if ( 'return' === $out ) {
3672 return $res;
3673 } else {
3674 echo number_format( $res );
3675 }
3676 }
3677
3678 /**
3679 * Item discount
3680 *
3681 * @param string $out Return value or echo.
3682 * @param int $post_id Post ID.
3683 * @param string $sku SKU code.
3684 * @return string|void
3685 */
3686 function usces_item_discount( $out = '', $post_id = '', $sku = '' ) {
3687 global $usces, $post;
3688
3689 if ( '' === $post_id ) {
3690 $post_id = $post->ID;
3691 }
3692 if ( '' === $sku ) {
3693 $sku = $usces->itemsku['code'];
3694 }
3695 $res = $usces->getItemDiscount( $post_id, $sku );
3696
3697 if ( 'return' === $out ) {
3698 return $res;
3699 } else {
3700 echo number_format( $res );
3701 }
3702 }
3703
3704 /**
3705 * Item page error message
3706 *
3707 * @param int $post_id Post ID.
3708 * @param string $skukey SKU code.
3709 * @param string $out Return value or echo.
3710 * @return string|void
3711 */
3712 function usces_singleitem_error_message( $post_id, $skukey, $out = '' ) {
3713 if ( ! isset( $_SESSION['usces_singleitem']['error_message'][ $post_id ][ $skukey ] ) ) {
3714 $ret = '';
3715 } else {
3716 $ret = $_SESSION['usces_singleitem']['error_message'][ $post_id ][ $skukey ];
3717 }
3718 if ( 'return' === $out ) {
3719 return wel_esc_script( $ret );
3720 } else {
3721 wel_esc_script_e( $ret );
3722 }
3723 }
3724
3725 /**
3726 * Amount Formatting
3727 *
3728 * @param float $float Price.
3729 * @param bool $symbol_pre Forward symbol.
3730 * @param bool $symbol_post Backward symbol.
3731 * @param string $out Return value or echo.
3732 * @param bool $seperator_flag Seperator.
3733 * @return string|void
3734 */
3735 function usces_crform( $float, $symbol_pre = true, $symbol_post = true, $out = '', $seperator_flag = true ) {
3736 global $usces;
3737
3738 $price = esc_html( $usces->get_currency( $float, $symbol_pre, $symbol_post, $seperator_flag ) );
3739 $res = apply_filters( 'usces_filter_crform', $price, $float );
3740
3741 if ( 'return' === $out ) {
3742 return $res;
3743 } else {
3744 echo $res; // no escape due to filter.
3745 }
3746 }
3747
3748 /**
3749 * Member Information
3750 *
3751 * @param string $key Key.
3752 * @param string $out Return value or echo.
3753 * @return string|void
3754 */
3755 function usces_memberinfo( $key, $out = '' ) {
3756 global $usces, $wpdb;
3757
3758 $info = $usces->get_member();
3759
3760 if ( empty( $key ) ) {
3761 return $info;
3762 }
3763
3764 switch ( $key ) {
3765 case 'registered':
3766 $res = mysql2date( __( 'Mj, Y', 'usces' ), $info['registered'] );
3767 break;
3768 case 'point':
3769 $member_table = usces_get_tablename( 'usces_member' );
3770 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table WHERE ID = %d", $info['ID'] );
3771 $res = $wpdb->get_var( $query );
3772 break;
3773 default:
3774 $res = isset( $info[ $key ] ) ? $info[ $key ] : '';
3775 }
3776
3777 if ( 'return' === $out ) {
3778 return $res;
3779 } else {
3780 echo esc_html( $res );
3781 }
3782 }
3783
3784 /**
3785 * Member Purchase History
3786 *
3787 * @param string $out Return value or echo.
3788 * @return string|void
3789 */
3790 function usces_member_history( $out = '' ) {
3791 global $usces;
3792
3793 $usces_members = $usces->get_member();
3794 $history = $usces->get_member_history( $usces_members['ID'], true );
3795 $usces_member_history = apply_filters( 'usces_filter_get_member_history', $history, $usces_members['ID'] );
3796
3797 $usces_member_history_count = ( $usces_member_history && is_array( $usces_member_history ) ) ? count( $usces_member_history ) : 0;
3798
3799 $html = usces_load_filter_purchase_date();
3800 $html .= '<div class="history-area">';
3801 if ( 0 === $usces_member_history_count ) {
3802 $no_history_message = apply_filters( 'usces_filter_no_history_message', __( 'There is no purchase history during the period.', 'usces' ) );
3803 $html .= '<table id="history_head"><tr>
3804 <td>' . $no_history_message . '</td>
3805 </tr></table>';
3806 } else {
3807 $management_status = apply_filters( 'usces_filter_management_status', get_option( 'usces_management_status' ) );
3808 foreach ( $usces_member_history as $umhs ) {
3809 $condition = $umhs['condition'];
3810 $tax_display = ( isset( $condition['tax_display'] ) ) ? $condition['tax_display'] : usces_get_tax_display();
3811 $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : usces_get_tax_mode();
3812 $tax_target = ( isset( $condition['tax_target'] ) ) ? $condition['tax_target'] : usces_get_tax_target();
3813 $tax_label = ( 'exclude' === $tax_mode ) ? __( 'consumption tax', 'usces' ) : __( 'Internal tax', 'usces' );
3814 $member_system_point = ( isset( $condition['membersystem_point'] ) && 'activate' === $condition['membersystem_point'] ) ? true : usces_is_membersystem_point();
3815 $point_coverage = ( isset( $condition['point_coverage'] ) ) ? (int) $condition['point_coverage'] : (int) usces_point_coverage();
3816 $cart = $umhs['cart'];
3817 $value = $umhs['order_status'];
3818
3819 $p_status = '';
3820 if ( $usces->is_status( 'duringorder', $value ) ) {
3821 $p_status = isset( $management_status['duringorder'] ) ? esc_html( $management_status['duringorder'] ) : '';
3822 } elseif ( $usces->is_status( 'cancel', $value ) ) {
3823 $p_status = isset( $management_status['cancel'] ) ? esc_html( $management_status['cancel'] ) : '';
3824 } elseif ( $usces->is_status( 'completion', $value ) ) {
3825 $p_status = isset( $management_status['completion'] ) ? esc_html( $management_status['completion'] ) : '';
3826 } else {
3827 $p_status = esc_html( __( 'new order', 'usces' ) );
3828 }
3829 $p_status = apply_filters( 'usces_filter_orderlist_process_status', $p_status, $value, $management_status, $umhs['ID'] );
3830
3831 $r_status = '';
3832 if ( $usces->is_status( 'noreceipt', $value ) ) {
3833 $r_status = isset( $management_status['noreceipt'] ) ? esc_html( $management_status['noreceipt'] ) : '';
3834 } elseif ( $usces->is_status( 'pending', $value ) ) {
3835 $r_status = isset( $management_status['pending'] ) ? esc_html( $management_status['pending'] ) : '';
3836 } elseif ( $usces->is_status( 'receipted', $value ) ) {
3837 $r_status = isset( $management_status['receipted'] ) ? esc_html( $management_status['receipted'] ) : '';
3838 }
3839 $r_status = apply_filters( 'usces_filter_orderlist_receipt_status', $r_status, $value, $management_status, $umhs['ID'] );
3840
3841 $shipping = usces_have_shipped( $cart );
3842 $delivery_company = '';
3843 $tracking_number = '';
3844 $delivery_company_url = '';
3845 if ( $shipping ) {
3846 $tracking_number = $usces->get_order_meta_value( apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' ), $umhs['ID'] );
3847 $delivery_company = $usces->get_order_meta_value( 'delivery_company', $umhs['ID'] );
3848 $delivery_company_url = usces_get_delivery_company_url( $delivery_company, $tracking_number );
3849 }
3850
3851 $head_col = 4;
3852 $history_member_head = '<table id="history_head"><thead>
3853 <tr class="order_head_label">
3854 <th class="historyrow order_number">' . __( 'Order number', 'usces' ) . '</th>
3855 <th class="historyrow purchase_date">' . __( 'Purchase date', 'usces' ) . '</th>';
3856 if ( ! empty( $p_status ) ) {
3857 $history_member_head .= '<th class="historyrow processing_status">' . __( 'Processing status', 'usces' ) . '</th>';
3858 $head_col++;
3859 }
3860 if ( ! empty( $r_status ) ) {
3861 $history_member_head .= '<th class="historyrow transfer_statement">' . __( 'transfer statement', 'usces' ) . '</th>';
3862 $head_col++;
3863 }
3864 $history_member_head .= '<th class="historyrow purchase_price">' . __( 'Purchase price', 'usces' ) . '</th>
3865 <th class="historyrow discount">' . apply_filters( 'usces_member_discount_label', __( 'Discount', 'usces' ), $umhs['ID'] ) . '</th>';
3866 if ( $tax_display && 'products' === $tax_target ) {
3867 $history_member_head .= '<th class="historyrow tax">' . $tax_label . '</th>';
3868 $head_col++;
3869 }
3870 if ( $member_system_point && 0 === $point_coverage ) {
3871 $history_member_head .= '<th class="historyrow used_point">' . __( 'Used points', 'usces' ) . '</th>';
3872 $head_col++;
3873 }
3874 if ( $shipping ) {
3875 $history_member_head .= '<th class="historyrow shipping">' . __( 'Shipping', 'usces' ) . '</th>';
3876 $head_col++;
3877 }
3878 if ( ! empty( $umhs['cod_fee'] ) ) {
3879 $payment = usces_get_payments_by_name( $umhs['payment_name'] );
3880 $cod_label = ( isset( $payment['settlement'] ) && 'COD' === $payment['settlement'] ) ? __( 'C.O.D', 'usces' ) : __( 'Fee', 'usces' );
3881 $cod_label = apply_filters( 'usces_filter_member_history_cod_label', $cod_label, $umhs['ID'] );
3882 $history_member_head .= '<th class="historyrow cod">' . $cod_label . '</th>';
3883 $head_col++;
3884 }
3885 if ( $tax_display && 'all' === $tax_target ) {
3886 $history_member_head .= '<th class="historyrow tax">' . $tax_label . '</th>';
3887 $head_col++;
3888 }
3889 if ( $member_system_point && 1 === $point_coverage ) {
3890 $history_member_head .= '<th class="historyrow used_point">' . __( 'Used points', 'usces' ) . '</th>';
3891 $head_col++;
3892 }
3893 if ( $member_system_point ) {
3894 $history_member_head .= '<th class="historyrow get_point">' . __( 'Acquired points', 'usces' ) . '</th>';
3895 $head_col++;
3896 }
3897 if ( ! empty( $tracking_number ) ) {
3898 $history_member_head .= '<th class="historyrow">' . __( 'Tracking number', 'usces' ) . '</th>';
3899 $head_col++;
3900 }
3901 $total_price = $umhs['total_items_price'] - $umhs['usedpoint'] + $umhs['discount'] + $umhs['shipping_charge'] + $umhs['cod_fee'] + $umhs['tax'];
3902 if ( $total_price < 0 ) {
3903 $total_price = 0;
3904 }
3905 $history_member_head .= '</tr></thead>
3906 <tbody>
3907 <tr class="order_head_value">
3908 <td class="order_number" data-label="' . __( 'Order number', 'usces' ) . '">' . usces_get_deco_order_id( $umhs['ID'] ) . '</td>
3909 <td class="date purchase_date" data-label="' . __( 'Purchase date', 'usces' ) . '">' . $umhs['date'] . '</td>';
3910 if ( ! empty( $p_status ) ) {
3911 $history_member_head .= '<td class="rightnum" data-label="' . __( 'Processing status', 'usces' ) . '">' . $p_status . '</td>';
3912 }
3913 if ( ! empty( $r_status ) ) {
3914 $history_member_head .= '<td class="rightnum" data-label="' . __( 'transfer statement', 'usces' ) . '">' . $r_status . '</td>';
3915 }
3916 $history_member_head .= '<td class="rightnum purchase_price" data-label="' . __( 'Purchase price', 'usces' ) . '">' . usces_crform( $total_price, true, false, 'return' ) . '</td>
3917 <td class="rightnum discount" data-label="' . apply_filters( 'usces_filter_discount_label', __( 'Discount', 'usces' ) ) . '">' . usces_crform( $umhs['discount'], true, false, 'return' ) . '</td>';
3918 if ( $tax_display && 'products' === $tax_target ) {
3919 $history_member_head .= '<td class="rightnum tax" data-label="' . $tax_label . '">' . usces_order_history_tax( $umhs, $tax_mode ) . '</td>';
3920 }
3921 if ( $member_system_point && 0 === $point_coverage ) {
3922 $history_member_head .= '<td class="rightnum used_point" data-label="' . __( 'Used points', 'usces' ) . '">' . number_format( $umhs['usedpoint'] ) . '</td>';
3923 }
3924 if ( $shipping ) {
3925 $history_member_head .= '<td class="rightnum shipping" data-label="' . __( 'Shipping', 'usces' ) . '">' . usces_crform( $umhs['shipping_charge'], true, false, 'return' ) . '</td>';
3926 }
3927 if ( ! empty( $umhs['cod_fee'] ) ) {
3928 $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>';
3929 }
3930 if ( $tax_display && 'all' === $tax_target ) {
3931 $history_member_head .= '<td class="rightnum tax" data-label="' . $tax_label . '">' . usces_order_history_tax( $umhs, $tax_mode ) . '</td>';
3932 }
3933 if ( $member_system_point && 1 === $point_coverage ) {
3934 $history_member_head .= '<td class="rightnum used_point" data-label="' . __( 'Used points', 'usces' ) . '">' . number_format( $umhs['usedpoint'] ) . '</td>';
3935 }
3936 if ( $member_system_point ) {
3937 $history_member_head .= '<td class="rightnum get_point" data-label="' . __( 'Acquired points', 'usces' ) . '">' . number_format( $umhs['getpoint'] ) . '</td>';
3938 }
3939 if ( ! empty( $tracking_number ) ) {
3940 if ( ! empty( $delivery_company_url ) ) {
3941 $history_member_head .= '<td data-label="' . __( 'Tracking number', 'usces' ) . '"><a href="' . esc_url( $delivery_company_url ) . '">' . esc_attr( $tracking_number ) . '</a></td>';
3942 } else {
3943 $history_member_head .= '<td data-label="' . __( 'Tracking number', 'usces' ) . '">' . esc_attr( $tracking_number ) . '</td>';
3944 }
3945 }
3946 $history_member_head .= '</tr>';
3947 $html .= apply_filters( 'usces_filter_history_member_head', $history_member_head, $umhs );
3948 $html .= apply_filters( 'usces_filter_member_history_header', null, $umhs, $head_col );
3949 $html .= '</tbody></table>
3950 <table id="retail_table_' . $umhs['ID'] . '" class="retail">';
3951 $history_cart_head = '<thead><tr>
3952 <th scope="row" class="cartrownum">No.</th>
3953 <th class="thumbnail">&nbsp;</th>
3954 <th class="productname">' . __( 'Items', 'usces' ) . '</th>
3955 <th class="price">' . __( 'Unit price', 'usces' ) . '</th>
3956 <th class="quantity">' . __( 'Quantity', 'usces' ) . '</th>
3957 <th class="subtotal">' . __( 'Amount', 'usces' ) . '</th>
3958 </tr></thead><tbody>';
3959 $html .= apply_filters( 'usces_filter_history_cart_head', $history_cart_head, $umhs );
3960 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
3961 for ( $i = 0; $i < $cart_count; $i++ ) {
3962 $cart_row = $cart[ $i ];
3963 $ordercart_id = $cart_row['cart_id'];
3964 $post_id = $cart_row['post_id'];
3965 $sku = $cart_row['sku'];
3966 $sku_code = urldecode( $cart_row['sku'] );
3967 $quantity = $cart_row['quantity'];
3968 $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
3969 $itemCode = $cart_row['item_code'];
3970 $itemName = $cart_row['item_name'];
3971 $cartItemName = $usces->getCartItemName_byOrder( $cart_row );
3972 $skuPrice = $cart_row['price'];
3973 $pictid = (int) $usces->get_mainpictid( $itemCode );
3974 $optstr = '';
3975 if ( is_array( $options ) && count( $options ) > 0 ) {
3976 foreach ( $options as $key => $value ) {
3977 if ( ! empty( $key ) ) {
3978 $key = urldecode( $key );
3979 $value = maybe_unserialize( $value );
3980 if ( is_array( $value ) ) {
3981 $c = '';
3982 $optstr .= esc_html( $key ) . ' : ';
3983 foreach ( $value as $v ) {
3984 $optstr .= $c . nl2br( esc_html( rawurldecode( $v ) ) );
3985 $c = ', ';
3986 }
3987 $optstr .= "<br />\n";
3988 } else {
3989 $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( rawurldecode( $value ) ) ) . "<br />\n";
3990 }
3991 }
3992 }
3993 $optstr = apply_filters( 'usces_filter_option_history', $optstr, $options );
3994 }
3995 $optstr = apply_filters( 'usces_filter_option_info_history', $optstr, $umhs, $cart_row, $i );
3996 $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
3997
3998 $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 );
3999 $cart_item_name = apply_filters( 'usces_filter_history_cart_item_name', $cart_item_name, $cartItemName, $optstr, $cart_row, $i, $umhs );
4000
4001 $history_cart_row = '<tr>
4002 <td class="cartrownum">' . ( $i + 1 ) . '</td>
4003 <td class="thumbnail">';
4004 $cart_thumbnail = '<a href="' . get_permalink( $post_id ) . '">' . wp_get_attachment_image( $pictid, array( 60, 60 ), true ) . '</a>';
4005 $history_cart_row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4006 $history_cart_row .= '</td>
4007 <td class="aleft productname" data-label="' . __( 'Items', 'usces' ) . '">' . $cart_item_name . '</td>
4008 <td class="rightnum price" data-label="' . __( 'Unit price', 'usces' ) . '">' . usces_crform( $skuPrice, true, false, 'return' ) . '</td>
4009 <td class="rightnum quantity" data-label="' . __( 'Quantity', 'usces' ) . '">' . number_format( $cart_row['quantity'] ) . '</td>
4010 <td class="rightnum subtotal" data-label="' . __( 'Amount', 'usces' ) . '">' . usces_crform( $skuPrice * $cart_row['quantity'], true, false, 'return' ) . '</td>
4011 </tr>';
4012 $materials = compact( 'cart_thumbnail', 'post_id', 'pictid', 'cartItemName', 'optstr' );
4013 $html .= apply_filters( 'usces_filter_history_cart_row', $history_cart_row, $umhs, $cart_row, $i, $materials );
4014 }
4015 $html .= '</tbody></table>';
4016 $html .= apply_filters( 'usces_filter_member_history_row', '', $umhs, $cart );
4017 }
4018 }
4019 $html .= '</div>';
4020 $html = apply_filters( 'usces_filter_member_history', $html, $usces_member_history );
4021
4022 if ( 'return' === $out ) {
4023 return $html;
4024 } else {
4025 echo $html; // no escape due to filter.
4026 }
4027 }
4028
4029 /**
4030 * Load select list filter purchase history.
4031 */
4032 function usces_load_filter_purchase_date() {
4033 global $usces;
4034
4035 $pur_date = $usces->usces_get_member_cookies( 'pur-date' );
4036 $current_year = (int) gmdate( 'Y' );
4037 $year_filter = 11;
4038 $arr_filter = array(
4039 '' => __( 'All of period', 'usces' ),
4040 'm_0' => __( 'This month', 'usces' ),
4041 'm_1' => __( 'Previous month', 'usces' ),
4042 'm_2' => __( 'Two months ago', 'usces' ),
4043 'd_30' => __( 'Last 30 days', 'usces' ),
4044 'd_60' => __( 'Last 60 days', 'usces' ),
4045 );
4046 for ( $i = 0; $i < $year_filter; $i++ ) {
4047 $year = $current_year - $i;
4048 $arr_filter[ 'y_' . $year ] = $year . __( 'year', 'usces' );
4049 }
4050 $exclude_cancel = $usces->usces_get_member_cookies( 'ord_ex_cancel' );
4051 $add_ex_args = array(
4052 'ord_ex_cancel' => ( 'on' === (string) $exclude_cancel ) ? 'off' : 'on',
4053 'pur-date' => $pur_date,
4054 );
4055 $url_ex_filter = add_query_arg( $add_ex_args, USCES_MEMBER_URL ) . '#usces_history';
4056 $html = '<div id="usces_history" class="usces_filter_history">';
4057 $content = '<div class="exclude_cancel">';
4058 $content .= '<label for="ord_exclude_cancel">';
4059 $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 ) . ' />';
4060 $content .= __( 'Exclude cancellations', 'usces' ) . '</label>';
4061 $content .= '</div>';
4062 $content .= '<div class="usce_period">';
4063 $content .= '<span>' . __( 'Period', 'usces' ) . '</span>';
4064 $content .= '<select name="usces_purdate" id="usces_purdate" onchange="memberOrderHistory.onChangeFilter(this);">';
4065 foreach ( $arr_filter as $key => $name ) {
4066 $selected = '';
4067 $add_args = array(
4068 'pur-date' => $key,
4069 );
4070 if ( (string) $key === (string) $pur_date ) {
4071 $selected = 'selected';
4072 }
4073 $url_filter = add_query_arg( $add_args, USCES_MEMBER_URL ) . '#usces_history';
4074 $content .= '<option cvalue="' . $key . '" value="' . esc_url( $url_filter ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $name ) . '</option>';
4075 }
4076 $content .= '</select>';
4077 $content .= '</div>';
4078 $html .= apply_filters( 'usces_filter_member_history_top_navi', $content );
4079 $html .= '</div>';
4080 return $html;
4081 }
4082
4083 /**
4084 * New registration button
4085 *
4086 * @param string $member_regmode Registration mode.
4087 */
4088 function usces_newmember_button( $member_regmode ) {
4089 $html = '<input name="member_regmode" type="hidden" value="' . $member_regmode . '" />';
4090 $newmemberbutton = '<input name="regmember" type="submit" value="' . __( 'transmit a message', 'usces' ) . '" />';
4091 $html .= apply_filters( 'usces_filter_newmember_button', $newmemberbutton );
4092 wel_esc_script_e( $html );
4093 }
4094
4095 /**
4096 * Login button
4097 */
4098 function usces_login_button() {
4099 $loginbutton = '<input type="submit" name="member_login" id="member_login" class="member_login_button" value="' . __( 'Log-in', 'usces' ) . '" />';
4100 $html = apply_filters( 'usces_filter_login_button', $loginbutton );
4101 wel_esc_script_e( $html );
4102 }
4103
4104 /**
4105 * Related item
4106 *
4107 * @param int $post_id Post ID.
4108 * @param string $title Title.
4109 */
4110 function usces_assistance_item( $post_id, $title ) {
4111 if ( usces_get_assistance_id_list( $post_id ) ) :
4112 global $post;
4113 $r = new WP_Query( array( 'post__in' => usces_get_assistance_ids( $post_id ), 'ignore_sticky_posts' => 1 ) );
4114 if ( $r->have_posts() ) :
4115 add_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
4116 add_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
4117 $width = apply_filters( 'usces_filter_assistance_item_width', 100 );
4118 $height = apply_filters( 'usces_filter_assistance_item_height', 100 );
4119 ?>
4120 <div class="assistance_item">
4121 <h3><?php wel_esc_script_e( $title ); ?></h3>
4122 <ul class="clearfix">
4123 <?php
4124 while ( $r->have_posts() ) :
4125 $r->the_post();
4126 usces_remove_filter();
4127 usces_the_item();
4128 ob_start();
4129 ?>
4130 <li>
4131 <div class="listbox clearfix">
4132 <div class="slit">
4133 <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 </div>
4135 <div class="detail">
4136 <div class="assist_excerpt">
4137 <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 <?php the_excerpt(); ?>
4139 </div>
4140 <?php if ( usces_is_skus() ) : ?>
4141 <div class="assist_price">
4142 <?php usces_crform( usces_the_firstPrice( 'return' ), true, false ); ?>
4143 </div>
4144 <?php usces_crform_the_itemPriceCr_taxincluded(); ?>
4145 <?php endif; ?>
4146 </div>
4147 </div>
4148 </li>
4149 <?php
4150 $list = ob_get_contents();
4151 ob_end_clean();
4152 echo apply_filters( 'usces_filter_assistance_item_list', $list, $post );
4153 endwhile;
4154 ?>
4155 </ul>
4156 </div><!-- end of assistance_item -->
4157 <?php
4158 wp_reset_postdata();
4159 usces_reset_filter();
4160 remove_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
4161 remove_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
4162 endif;
4163 endif;
4164 }
4165
4166 /**
4167 * Cart Item Details
4168 *
4169 * @param string $out Return value or echo.
4170 * @return string|void
4171 */
4172 function usces_get_cart_rows( $out = '' ) {
4173 global $usces, $usces_gp;
4174
4175 $cart = $usces->cart->get_cart();
4176 $usces_gp = 0;
4177 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
4178 $res = '';
4179
4180 for ( $i = 0; $i < $cart_count; $i++ ) {
4181 $cart_row = $cart[ $i ];
4182 $post_id = (int) $cart_row['post_id'];
4183 $sku = $cart_row['sku'];
4184 $sku_code = urldecode( $cart_row['sku'] );
4185 $quantity = $cart_row['quantity'];
4186 $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
4187 $advance = ( ! empty( $cart_row['advance'] ) ) ? $cart_row['advance'] : '';
4188 $itemCode = $usces->getItemCode( $post_id );
4189 $itemName = $usces->getItemName( $post_id );
4190 $cartItemName = $usces->getCartItemName( $post_id, $sku_code );
4191 $itemRestriction = $usces->getItemRestriction( $post_id );
4192 $itemOrderAcceptable = $usces->getItemOrderAcceptable( $post_id );
4193 $skuPrice = $cart_row['price'];
4194 $skuZaikonum = $usces->getItemZaikonum( $post_id, $sku_code );
4195 $stockid = $usces->getItemZaikoStatusId( $post_id, $sku_code );
4196 $stock = $usces->getItemZaiko( $post_id, $sku_code );
4197 $red = ( 1 < $stockid ) ? 'class="signal_red stock"' : 'class="stock"';
4198 $pictid = (int) $usces->get_mainpictid( $itemCode );
4199 $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
4200
4201 $row = '';
4202 $row .= '<tr>
4203 <td class="num">' . ( $i + 1 ) . '</td>
4204 <td class="thumbnail">';
4205 $cart_thumbnail = '<a href="' . get_permalink( $post_id ) . '">' . wp_get_attachment_image( $pictid, array( 60, 60 ), true ) . '</a>';
4206 $row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4207 $row .= '</td>
4208 <td class="aleft productname" data-label="' . esc_html__( 'Items', 'usces' ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />';
4209 if ( is_array( $options ) && count( $options ) > 0 ) {
4210 $optstr = '';
4211 foreach ( $options as $key => $value ) {
4212 if ( ! empty( $key ) ) {
4213 $key = urldecode( $key );
4214 if ( is_array( $value ) ) {
4215 $c = '';
4216 $optstr .= esc_html( $key ) . ' : ';
4217 foreach ( $value as $v ) {
4218 $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
4219 $c = ', ';
4220 }
4221 $optstr .= "<br />\n";
4222 } else {
4223 $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . "<br />\n";
4224 }
4225 }
4226 }
4227 $row .= apply_filters( 'usces_filter_option_cart', $optstr, $options, $args );
4228 }
4229 $row .= apply_filters( 'usces_filter_option_info_cart', '', $cart_row, $args );
4230 $row .= '</td>
4231 <td class="aright unitprice" data-label="' . esc_html__( 'Unit price', 'usces' ) . '">';
4232 if ( usces_is_gptekiyo( $post_id, $sku_code, $quantity ) ) {
4233 $usces_gp = 1;
4234 $gp_src = file_exists( get_template_directory() . '/images/gp.gif' ) ? get_template_directory_uri() . '/images/gp.gif' : USCES_PLUGIN_URL . '/images/gp.gif';
4235 $Business_pack_mark = '<img src="' . $gp_src . '" alt="' . __( 'Business package discount', 'usces' ) . '" /><br />';
4236 $row .= apply_filters( 'usces_filter_itemGpExp_cart_mark', $Business_pack_mark );
4237 }
4238 $row .= usces_crform( $skuPrice, true, false, 'return' ) . '
4239 </td>
4240 <td class="quantity" data-label="' . esc_html__( 'Quantity', 'usces' ) . '">';
4241 $row_quant = '<input name="quant[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" class="quantity" type="text" value="' . esc_attr( $cart_row['quantity'] ) . '" />';
4242 $row .= apply_filters( 'usces_filter_cart_rows_quant', $row_quant, $args );
4243 $row .= '</td>
4244 <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>';
4245 $stock_column = '<td ' . $red . ' data-label="' . esc_html__( 'stock status', 'usces' ) . '">' . esc_html( $stock ) . '</td>';
4246 $row .= apply_filters( 'usces_filter_cart_rows_stock', $stock_column, $args, $red, $stock );
4247 $row .= '<td class="action">';
4248 if ( is_array( $options ) && count( $options ) > 0 ) {
4249 foreach ( $options as $key => $value ) {
4250 if ( is_array( $value ) ) {
4251 foreach ( $value as $v ) {
4252 $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . '][' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" type="hidden" value="' . esc_attr( $v ) . '" />' . "\n";
4253 }
4254 } else {
4255 $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . '][' . esc_attr( $key ) . ']" type="hidden" value="' . esc_attr( $value ) . '" />' . "\n";
4256 }
4257 }
4258 }
4259 $row .= '<input name="itemRestriction[' . $i . ']" type="hidden" value="' . esc_attr( $itemRestriction ) . '" />
4260 <input name="itemOrderAcceptable[' . $i . ']" type="hidden" value="' . $itemOrderAcceptable . '" />
4261 <input name="stockid[' . $i . ']" type="hidden" value="' . esc_attr( $stockid ) . '" />
4262 <input name="itempostid[' . $i . ']" type="hidden" value="' . esc_attr( $post_id ) . '" />
4263 <input name="itemsku[' . $i . ']" type="hidden" value="' . esc_attr( $sku ) . '" />
4264 <input name="zaikonum[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $skuZaikonum ) . '" />
4265 <input name="skuPrice[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $skuPrice ) . '" />
4266 <input name="advance[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $advance ) . '" />
4267 <input name="delButton[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" class="delButton" type="submit" value="' . __( 'Delete', 'usces' ) . '" />
4268 </td>
4269 </tr>';
4270 $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance', 'itemCode', 'itemName', 'cartItemName', 'itemRestriction', 'skuPrice', 'skuZaikonum', 'stockid', 'stock', 'red', 'pictid' );
4271 $res .= apply_filters( 'usces_filter_cart_row', $row, $cart, $materials );
4272 }
4273
4274 $res = apply_filters( 'usces_filter_cart_rows', $res, $cart );
4275
4276 if ( 'return' === $out ) {
4277 return $res;
4278 } else {
4279 echo $res; // no escape due to filter.
4280 }
4281 }
4282
4283 /**
4284 * Confirm Cart Item Details
4285 *
4286 * @param string $out Return value or echo.
4287 * @return string|void
4288 */
4289 function usces_get_confirm_rows( $out = '' ) {
4290 global $usces, $usces_members, $usces_entries;
4291
4292 $memid = ( empty( $usces_members['ID'] ) ) ? 999999999 : $usces_members['ID'];
4293 $usces->set_cart_fees( $usces_members, $usces_entries );
4294 $usces_entries = $usces->cart->get_entry();
4295
4296 $cart = $usces->cart->get_cart();
4297 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
4298 $res = '';
4299
4300 for ( $i = 0; $i < $cart_count; $i++ ) {
4301 $cart_row = $cart[ $i ];
4302 $post_id = (int) $cart_row['post_id'];
4303 $sku = $cart_row['sku'];
4304 $sku_code = urldecode( $cart_row['sku'] );
4305 $quantity = $cart_row['quantity'];
4306 $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
4307 $advance = $cart_row['advance'];
4308 $itemCode = $usces->getItemCode( $post_id );
4309 $itemName = $usces->getItemName( $post_id );
4310 $cartItemName = $usces->getCartItemName( $post_id, $sku_code );
4311 $skuPrice = $cart_row['price'];
4312 $pictid = $usces->get_mainpictid( $itemCode );
4313 $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
4314
4315 $row = '';
4316 $row .= '<tr>
4317 <td class="num">' . ( $i + 1 ) . '</td>
4318 <td class="thumbnail">';
4319 $cart_thumbnail = wp_get_attachment_image( $pictid, array( 60, 60 ), true );
4320 $row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4321 $row .= '</td><td class="productname" data-label="' . esc_html__( 'Items', 'usces' ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />';
4322 if ( is_array( $options ) && count( $options ) > 0 ) {
4323 $optstr = '';
4324 foreach ( $options as $key => $value ) {
4325 if ( ! empty( $key ) ) {
4326 $key = urldecode( $key );
4327 if ( is_array( $value ) ) {
4328 $c = '';
4329 $optstr .= esc_html( $key ) . ' : ';
4330 foreach ( $value as $v ) {
4331 $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
4332 $c = ', ';
4333 }
4334 $optstr .= "<br />\n";
4335 } else {
4336 $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . "<br />\n";
4337 }
4338 }
4339 }
4340 $row .= apply_filters( 'usces_filter_option_confirm', $optstr, $options, $args );
4341 }
4342 $row .= apply_filters( 'usces_filter_option_info_confirm', '', $cart_row, $args );
4343 $row .= '</td>
4344 <td class="unitprice" data-label="' . esc_html__( 'Unit price', 'usces' ) . '">' . esc_html( usces_crform( $skuPrice, true, false, 'return' ) ) . '</td>
4345 <td class="quantity" data-label="' . esc_html__( 'Quantity', 'usces' ) . '">' . esc_html( $cart_row['quantity'] ) . '</td>
4346 <td class="subtotal" data-label="' . esc_html__( 'Amount', 'usces' ) . '">' . esc_html( usces_crform( ( $skuPrice * $cart_row['quantity'] ), true, false, 'return' ) ) . '</td>
4347 <td class="action">';
4348 $row .= apply_filters( 'usces_additional_confirm', '', array( $i, $post_id, $sku_code ) );
4349 $row .= '</td>
4350 </tr>';
4351
4352 $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance', 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'pictid' );
4353 $res .= apply_filters( 'usces_filter_confirm_row', $row, $cart, $materials );
4354 }
4355
4356 $res = apply_filters( 'usces_filter_confirm_rows', $res, $cart );
4357
4358 if ( 'return' === $out ) {
4359 return $res;
4360 } else {
4361 echo $res; // no escape due to filter.
4362 }
4363 }
4364
4365 /**
4366 * Address Information
4367 *
4368 * @param string $type Type.
4369 * @param array $data Entry data.
4370 * @param string $out Return value or echo.
4371 * @return string|void
4372 */
4373 function uesces_addressform( $type, $data, $out = 'return' ) {
4374 global $usces, $usces_settings;
4375
4376 $options = get_option( 'usces', array() );
4377 $form = $options['system']['addressform'];
4378 $nameform = $usces_settings['nameform'][ $form ];
4379 $applyform = usces_get_apply_addressform( $form );
4380 $formtag = '';
4381 switch ( $type ) {
4382 case 'confirm':
4383 case 'member':
4384 $values = $data;
4385 break;
4386 case 'customer':
4387 case 'delivery':
4388 $values = $data[ $type ];
4389 break;
4390 }
4391 $data['type'] = $type;
4392 $values['country'] = ! empty( $values['country'] ) ? $values['country'] : usces_get_local_addressform();
4393 $values = $usces->stripslashes_deep_post( $values );
4394 $target_market_count = ( isset( $options['system']['target_market'] ) && is_array( $options['system']['target_market'] ) ) ? count( $options['system']['target_market'] ) : 1;
4395
4396 if ( 'confirm' === $type ) {
4397
4398 switch ( $applyform ) {
4399
4400 case 'JP':
4401 $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4402 $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>';
4403 $furigana = ( '' === ( trim( $values['customer']['name3'] ) . trim( $values['customer']['name4'] ) ) ) ? '' : sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name3'] ) . ' ' . esc_html( $values['customer']['name4'] ) ) );
4404 $furigana_customer = '<tr class="furikana-row member-furikana-row"><th>' . __( 'furigana', 'usces' ) . '</th><td>' . $furigana . '</td></tr>';
4405 $formtag .= apply_filters( 'usces_filter_furigana_confirm_customer', $furigana_customer, $type, $values );
4406 $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4407 $formtag .= '<tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip/Postal Code', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>';
4408 if ( 1 < $target_market_count ) {
4409 $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4410 $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4411 }
4412 $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4413 $formtag .= '
4414 <tr class="states-row member-states-row"><th>' . __( 'Province', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>
4415 <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4416 <tr class="address2-row member-address2-row"><th>' . __( 'numbers', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4417 <tr class="address3-row member-address3-row"><th>' . __( 'building name', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4418 <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4419 <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4420 $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4421
4422 $shipping_address_info = '';
4423 if ( isset( $values['delivery'] ) ) {
4424 $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4425 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4426 $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>';
4427 $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'] ) ) );
4428 $furigana_delivery = '<tr class="furikana-row delivery-furikana-row"><th>' . __( 'furigana', 'usces' ) . '</th><td>' . $deli_furigana . '</td></tr>';
4429 $shipping_address_info .= apply_filters( 'usces_filter_furigana_confirm_delivery', $furigana_delivery, $type, $values );
4430 $shipping_address_info .= usces_custom_field_info( $values, 'delivery', 'name_after', 'return' );
4431 $shipping_address_info .= '<tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip/Postal Code', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>';
4432 if ( 1 < $target_market_count ) {
4433 $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4434 $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4435 }
4436 $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4437 $shipping_address_info .= '
4438 <tr class="states-row delivery-states-row"><th>' . __( 'Province', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>
4439 <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4440 <tr class="address2-row delivery-address2-row"><th>' . __( 'numbers', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4441 <tr class="address3-row delivery-address3-row"><th>' . __( 'building name', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4442 <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4443 <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4444 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4445 }
4446 $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4447 break;
4448
4449 case 'CN':
4450 $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4451 $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>';
4452 $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4453 if ( 1 < $target_market_count ) {
4454 $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4455 $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4456 }
4457 $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4458 $formtag .= '
4459 <tr class="states-row member-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>
4460 <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4461 <tr class="address2-row member-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4462 <tr class="address3-row member-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4463 <tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>
4464 <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4465 <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4466 $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4467
4468 $shipping_address_info = '';
4469 if ( isset( $values['delivery'] ) ) {
4470 $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4471 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4472 $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>';
4473 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_after', 'return' );
4474 if ( 1 < $target_market_count ) {
4475 $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4476 $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4477 }
4478 $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4479 $shipping_address_info .= '
4480 <tr class="states-row delivery-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>
4481 <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4482 <tr class="address2-row delivery-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4483 <tr class="address3-row delivery-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4484 <tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>
4485 <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4486 <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4487 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4488 }
4489 $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4490 break;
4491
4492 case 'US':
4493 default:
4494 $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4495 $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4496 $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>';
4497 $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4498 $formtag .= '
4499 <tr class="address2-row member-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4500 <tr class="address3-row member-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4501 <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4502 <tr class="states-row member-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>';
4503 if ( 1 < $target_market_count ) {
4504 $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4505 $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4506 }
4507 $formtag .= '
4508 <tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>
4509 <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4510 <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4511 $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4512
4513 $shipping_address_info = '';
4514 if ( isset( $values['delivery'] ) ) {
4515 $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4516 $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4517 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4518 $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>';
4519 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_after', 'return' );
4520 $shipping_address_info .= '
4521 <tr class="address2-row delivery-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4522 <tr class="address3-row delivery-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4523 <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4524 <tr class="states-row delivery-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>';
4525 if ( 1 < $target_market_count ) {
4526 $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4527 $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4528 }
4529 $shipping_address_info .= '
4530 <tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>
4531 <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4532 <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4533 $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4534 }
4535 $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4536 break;
4537 }
4538 $res = apply_filters( 'usces_filter_apply_addressform_confirm', $formtag, $type, $data );
4539
4540 } else {
4541
4542 switch ( $applyform ) {
4543
4544 case 'JP':
4545 $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4546 $formtag .= '<tr id="name_row" class="inp1">
4547 <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>';
4548 if ( $nameform ) {
4549 $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>';
4550 $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>';
4551 } else {
4552 $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>';
4553 $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>';
4554 }
4555 $formtag .= '</tr>';
4556 $furigana = '<tr id="furikana_row" class="inp1">
4557 <th scope="row">' . usces_get_essential_mark( 'name3', $data ) . __( 'furigana', 'usces' ) . '</th>';
4558 if ( $nameform ) {
4559 $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>';
4560 $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>';
4561 } else {
4562 $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>';
4563 $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>';
4564 }
4565 $furigana .= '</tr>';
4566 $formtag .= apply_filters( 'usces_filter_furigana_form', $furigana, $type, $values );
4567 $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4568 $formtag .= '<tr id="zipcode_row">
4569 <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip/Postal Code', 'usces' ) . '</th>
4570 <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>
4571 </tr>';
4572 if ( 1 < $target_market_count ) {
4573 $formtag .= '<tr id="country_row">
4574 <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4575 <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4576 </tr>';
4577 } else {
4578 $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . $options['system']['target_market'][0] . '">';
4579 }
4580 $formtag .= '<tr id="states_row">
4581 <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'Province', 'usces' ) . '</th>
4582 <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4583 </tr>
4584 <tr id="address1_row" class="inp2">
4585 <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4586 <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>
4587 </tr>
4588 <tr id="address2_row">
4589 <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'numbers', 'usces' ) . '</th>
4590 <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>
4591 </tr>
4592 <tr id="address3_row">
4593 <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'building name', 'usces' ) . '</th>
4594 <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>
4595 </tr>
4596 <tr id="tel_row">
4597 <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4598 <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>
4599 </tr>
4600 <tr id="fax_row">
4601 <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4602 <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>
4603 </tr>';
4604 $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4605 break;
4606
4607 case 'CN':
4608 $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4609 $formtag .= '<tr id="name_row" class="inp1">
4610 <th scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4611 if ( $nameform ) {
4612 $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>';
4613 $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>';
4614 } else {
4615 $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>';
4616 $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>';
4617 }
4618 $formtag .= '</tr>';
4619 $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4620 if ( 1 < $target_market_count ) {
4621 $formtag .= '<tr id="country_row">
4622 <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4623 <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4624 </tr>';
4625 } else {
4626 $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . $options['system']['target_market'][0] . '">';
4627 }
4628 $formtag .= '<tr id="states_row">
4629 <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'State', 'usces' ) . '</th>
4630 <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4631 </tr>
4632 <tr id="address1_row" class="inp2">
4633 <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4634 <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>
4635 </tr>
4636 <tr id="address2_row">
4637 <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'Address Line1', 'usces' ) . '</th>
4638 <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>
4639 </tr>
4640 <tr id="address3_row">
4641 <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'Address Line2', 'usces' ) . '</th>
4642 <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>
4643 </tr>
4644 <tr id="zipcode_row">
4645 <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip', 'usces' ) . '</th>
4646 <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>
4647 </tr>
4648 <tr id="tel_row">
4649 <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4650 <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>
4651 </tr>
4652 <tr id="fax_row">
4653 <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4654 <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>
4655 </tr>';
4656 $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4657 break;
4658
4659 case 'US':
4660 default:
4661 $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4662 $formtag .= '<tr id="name_row" class="inp1">
4663 <th scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4664 if ( $nameform ) {
4665 $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>';
4666 $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>';
4667 } else {
4668 $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>';
4669 $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>';
4670 }
4671 $formtag .= '</tr>';
4672 $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4673 $formtag .= '
4674 <tr id="address2_row">
4675 <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'Address Line1', 'usces' ) . '</th>
4676 <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>
4677 </tr>
4678 <tr id="address3_row">
4679 <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'Address Line2', 'usces' ) . '</th>
4680 <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>
4681 </tr>
4682 <tr id="address1_row" class="inp2">
4683 <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4684 <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>
4685 </tr>
4686 <tr id="states_row">
4687 <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'State', 'usces' ) . '</th>
4688 <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4689 </tr>';
4690 if ( 1 < $target_market_count ) {
4691 $formtag .= '<tr id="country_row">
4692 <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4693 <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4694 </tr>';
4695 } else {
4696 $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . esc_attr( $options['system']['target_market'][0] ) . '">';
4697 }
4698 $formtag .= '<tr id="zipcode_row">
4699 <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip', 'usces' ) . '</th>
4700 <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>
4701 </tr>
4702 <tr id="tel_row">
4703 <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4704 <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>
4705 </tr>
4706 <tr id="fax_row">
4707 <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4708 <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>
4709 </tr>';
4710 $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4711 break;
4712 }
4713 $res = apply_filters( 'usces_filter_apply_addressform', $formtag, $type, $data );
4714 }
4715
4716 if ( 'return' === $out ) {
4717 return $res;
4718 } else {
4719 echo $res; // no escape due to filter.
4720 }
4721 }
4722
4723 /**
4724 * Item option field
4725 *
4726 * @param int $post_id Post ID.
4727 * @param string $sku SKU code.
4728 * @param int $label Tabel.
4729 * @param string $out Return value or echo.
4730 * @return string|void
4731 */
4732 function usces_item_option_fileds( $post_id, $sku, $label = 1, $out = 'echo' ) {
4733 $options = wel_get_opts( $post_id, 'sort' );
4734 if ( ! $options || ! is_array( $options ) ) {
4735 return false;
4736 }
4737 if ( 0 === count( $options ) ) {
4738 return false;
4739 }
4740 $sku_enc = urlencode( $sku );
4741
4742 $html = '';
4743 foreach ( $options as $opt ) {
4744 $name = $opt['name'];
4745 $opt_code = urlencode( $name );
4746 $html .= '<div class="opt_field" id="opt_' . $post_id . '_' . $sku_enc . '_' . $opt_code . '">';
4747 if ( $label ) {
4748 $html .= '<label for="itemOption[' . $post_id . '][' . $sku_enc . '][' . $opt_code . ']">' . esc_html( $name ) . '</label>';
4749 }
4750 $html .= usces_get_itemopt_filed( $post_id, $sku, $opt );
4751 $html .= '</div>';
4752 }
4753 if ( 'return' === $out ) {
4754 return wel_esc_script( $html );
4755 } else {
4756 wel_esc_script_e( $html );
4757 }
4758 }
4759
4760 /**
4761 * Facebook
4762 */
4763 function usces_facebook_like() {
4764 global $post, $usces;
4765 $like = array(
4766 'url' => urlencode( get_permalink( $post->ID ) ),
4767 'send' => 'false',
4768 'layout' => 'button_count', /* standard, button_count, box_count */
4769 'width' => '450',
4770 'height' => '35',
4771 'show_faces' => 'false',
4772 'action' => 'like', /* like, recommend */
4773 );
4774 $like = apply_filters( 'usces_filter_facebook_like', $like, $post->ID );
4775 ?>
4776 <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>
4777 <?php
4778 }
4779
4780 /**
4781 * Checked
4782 *
4783 * @param string $chk Checked.
4784 * @param string $key Key.
4785 * @param string $out Return value or echo.
4786 * @return string|void
4787 */
4788 function usces_checked( $chk, $key, $out = '' ) {
4789 $checked = ( isset( $chk[ $key ] ) && 1 === (int) $chk[ $key ] );
4790 if ( 'return' === $out ) {
4791 return checked( $checked, true, false );
4792 } else {
4793 checked( $checked, true, true );
4794 }
4795 }
4796
4797 /**
4798 * Custom field value
4799 *
4800 * @param string $field Field.
4801 * @param string $key Key.
4802 * @param string $id ID.
4803 * @param string $out Return value or echo.
4804 * @return string|void
4805 */
4806 function usces_get_custom_field_value( $field, $key, $id, $out = '' ) {
4807 global $usces;
4808
4809 $value = '';
4810 switch ( $field ) {
4811 case 'order':
4812 $value = $usces->get_order_meta_value( 'csod_' . $key, $id );
4813 break;
4814 case 'customer':
4815 $value = $usces->get_order_meta_value( 'cscs_' . $key, $id );
4816 break;
4817 case 'delivery':
4818 $value = $usces->get_order_meta_value( 'csde_' . $key, $id );
4819 break;
4820 case 'member':
4821 $value = $usces->get_member_meta_value( 'csmb_' . $key, $id );
4822 break;
4823 }
4824
4825 if ( 'return' === $out ) {
4826 return wel_esc_script( $value );
4827 } else {
4828 wel_esc_script_e( $value );
4829 }
4830 }
4831
4832 /**
4833 * Address search button
4834 *
4835 * @param string $type Type.
4836 * @param string $out Return value or echo.
4837 * @return string|void
4838 */
4839 function usces_postal_code_address_search( $type, $out = 'return' ) {
4840 global $usces;
4841
4842 $html = '';
4843 if ( isset( $usces->options['address_search'] ) && 'activate' === $usces->options['address_search'] ) {
4844 $address_search_label = apply_filters( 'usces_filter_postal_code_address_search_label', '住所検索' );
4845 $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]' ) . '\' );" >';
4846 if ( 'delivery' === $type ) {
4847 $entry = $usces->cart->get_entry();
4848 $zipcode = ( isset( $entry['delivery']['zipcode'] ) ) ? $entry['delivery']['zipcode'] : '';
4849 $html .= '<input type="hidden" id="search_zipcode_change" value="' . esc_attr( $zipcode ) . '">';
4850 }
4851 }
4852 if ( 'return' === $out ) {
4853 return wel_esc_script( $html );
4854 } else {
4855 wel_esc_script_e( $html );
4856 }
4857 }
4858
4859 /**
4860 * Agreement Approval Field
4861 *
4862 * @param string $out Return value or echo.
4863 * @return string|void
4864 */
4865 function usces_agree_member_field( $out = '' ) {
4866 global $usces;
4867
4868 $html = '';
4869 if ( usces_is_membersystem_state() ) {
4870 $row = '';
4871 if ( isset( $usces->options['agree_member'] ) && 'activate' === $usces->options['agree_member'] ) {
4872 $row .= '<div class="agree_member_area">';
4873 if ( isset( $usces->options['member_page_data']['agree_member_exp'] ) ) {
4874 $row .= '<div class="at_exp_text">' . stripslashes( nl2br( $usces->options['member_page_data']['agree_member_exp'] ) ) . '</div>';
4875 }
4876 if ( isset( $usces->options['member_page_data']['agree_member_cont'] ) ) {
4877 $row .= '<textarea name="at_cont_text" class="at_cont_text" readonly="readonly">' . $usces->options['member_page_data']['agree_member_cont'] . '</textarea>
4878 <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>';
4879 }
4880 $row .= '</div>';
4881 }
4882 $html = apply_filters( 'usces_filter_agree_member_field', $row );
4883 }
4884
4885 if ( 'return' === $out ) {
4886 return wel_esc_script( $html );
4887 } else {
4888 wel_esc_script_e( $html );
4889 }
4890 }
4891
4892 /**
4893 * No image
4894 *
4895 * @param array $size Size.
4896 * @param string $alt Alt.
4897 * @return string
4898 */
4899 function usces_get_attachment_noimage( $size = array( 60, 60 ), $alt = '' ) {
4900 $size_class = join( 'x', $size );
4901 return '<img width="' . $size[0] . '" height="' . $size[1] . '" src="' . USCES_PLUGIN_URL . '/images/default.png" class="attachment-' . $size_class . ' size-' . $size_class . '" alt="' . $alt . '">';
4902 }
4903
4904 /**
4905 * Tax rate
4906 *
4907 * @param string $out Return value or echo.
4908 * @return string|void
4909 */
4910 function usces_the_taxrate( $out = '' ) {
4911 global $usces;
4912
4913 if ( isset( $usces->itemsku['taxrate'] ) ) {
4914 $taxrate = ( 'reduced' === $usces->itemsku['taxrate'] ) ? $usces->options['tax_rate_reduced'] : $usces->options['tax_rate'];
4915 } else {
4916 $taxrate = $usces->options['tax_rate'];
4917 }
4918 $the_taxrate = '<em class="tax">' . sprintf( __( "Tax Rate %s%%", 'usces' ), $taxrate ) . '</em>';
4919 $the_taxrate = apply_filters( 'usces_filter_the_taxrate', $the_taxrate, $usces->itemsku, $out );
4920
4921 if ( 'return' === $out ) {
4922 return wel_esc_script( $the_taxrate );
4923 } else {
4924 wel_esc_script_e( $the_taxrate );
4925 }
4926 }
4927
4928 /**
4929 * Tax amount
4930 *
4931 * @param string $out Return value or echo.
4932 * @return string|void
4933 */
4934 function usces_cart_tax( $out = '' ) {
4935 global $usces;
4936
4937 $total_items_price = $usces->get_total_price();
4938 $materials = array(
4939 'total_items_price' => $total_items_price,
4940 'discount' => 0,
4941 'shipping_charge' => 0,
4942 'cod_fee' => 0,
4943 'use_point' => 0,
4944 );
4945 $tax = $usces->getTax( $total_items_price, $materials );
4946
4947 if ( 'return' === $out ) {
4948 return wel_esc_script( $tax );
4949 } else {
4950 wel_esc_script_e( $tax );
4951 }
4952 }
4953
4954 /**
4955 * Total tax amount
4956 *
4957 * @param string $out Return value or echo.
4958 * @return string|void
4959 */
4960 function usces_confirm_tax( $out = '' ) {
4961 global $usces;
4962
4963 if ( $usces->is_reduced_taxrate() ) {
4964 if ( 'include' === $usces->options['tax_mode'] ) {
4965 $po = '( ';
4966 $pc = ' )';
4967 } else {
4968 $po = '';
4969 $pc = '';
4970 }
4971 $usces_tax = Welcart_Tax::get_instance();
4972 $entry = wel_get_entry();
4973 $shipping_charge = isset( $entry['order']['shipping_charge'] ) ? $entry['order']['shipping_charge'] : 0;
4974 $cod_fee = isset( $entry['order']['cod_fee'] ) ? $entry['order']['cod_fee'] : 0;
4975 $materials = compact( 'shipping_charge', 'cod_fee');
4976 $usces_tax->get_order_tax( $materials );
4977 $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;';
4978 $tax .= sprintf( __( "%s%% consumption tax", 'usces' ), $usces->options['tax_rate'] ) . '&nbsp;&nbsp;' . $po . usces_crform( $usces_tax->tax_standard, true, false, 'return' ) . $pc . '<br />';
4979 if ( 0 < $usces_tax->tax_rate_reduced ) {
4980 $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;';
4981 $tax .= sprintf( __( "%s%% consumption tax", 'usces' ), $usces->options['tax_rate_reduced'] ) . '&nbsp;&nbsp;' . $po . usces_crform( $usces_tax->tax_reduced, true, false, 'return' ) . $pc;
4982 }
4983 } else {
4984 $tax = '';
4985 }
4986
4987 $tax = apply_filters( 'usces_filter_confirm_tax', $tax, $out );
4988
4989 if ( 'return' === $out ) {
4990 return wel_esc_script( $tax );
4991 } else {
4992 wel_esc_script_e( $tax );
4993 }
4994 }
4995
4996 /**
4997 * Tax-included amount
4998 *
4999 * @param string $out Return value or echo.
5000 * @return string|void
5001 */
5002 function usces_the_itemPrice_taxincluded( $out = '' ) {
5003 global $post, $usces;
5004 $usces_tax = Welcart_Tax::get_instance();
5005
5006 if ( empty( $usces->itemsku['code'] ) ) {
5007 $skus = $usces->get_skus( $post->ID );
5008 $skucode = $skus[0]['code'];
5009 $skuprice = $skus[0]['price'];
5010 } else {
5011 $skucode = $usces->itemsku['code'];
5012 $skuprice = $usces->itemsku['price'];
5013 }
5014 $tax_rate = $usces_tax->get_sku_tax_rate( $post->ID, $skucode );
5015 $tax = (float) sprintf( '%.3f', (float) $skuprice * (float) $tax_rate / 100 );
5016 $tax = usces_tax_rounding_off( $tax );
5017 $price = $skuprice + $tax;
5018
5019 if ( 'return' === $out ) {
5020 return $price;
5021 } else {
5022 echo number_format( $price );
5023 }
5024 }
5025
5026 /**
5027 * Tax-included normal amount
5028 *
5029 * @param string $out Return value or echo.
5030 * @return string|void
5031 */
5032 function usces_the_itemCprice_taxincluded( $out = '' ) {
5033 global $post, $usces;
5034 $usces_tax = Welcart_Tax::get_instance();
5035
5036 if ( empty( $usces->itemsku['code'] ) ) {
5037 $skus = $usces->get_skus( $post->ID );
5038 $skucode = $skus[0]['code'];
5039 $skucprice = $skus[0]['cprice'];
5040 } else {
5041 $skucode = $usces->itemsku['code'];
5042 $skucprice = $usces->itemsku['cprice'];
5043 }
5044 $tax_rate = $usces_tax->get_sku_tax_rate( $post->ID, $skucode );
5045 $tax = (float) sprintf( '%.3f', (float) $skucprice * (float) $tax_rate / 100 );
5046 $tax = usces_tax_rounding_off( $tax );
5047 $price = $skucprice + $tax;
5048 if ( 'return' === $out ) {
5049 return $price;
5050 } else {
5051 echo number_format( $price );
5052 }
5053 }
5054
5055 /**
5056 * Formatted tax included amount
5057 *
5058 * @param string $out Return value or echo.
5059 * @return string|void
5060 */
5061 function usces_the_itemPriceCr_taxincluded( $out = '' ) {
5062 global $usces;
5063 $usces_tax = Welcart_Tax::get_instance();
5064
5065 $price_taxincluded = usces_the_itemPrice_taxincluded( 'return' );
5066 $price = $usces->get_currency( $price_taxincluded, true, false );
5067 $price = apply_filters( 'usces_filter_the_item_price_cr_taxincluded', $price, $price_taxincluded, $out );
5068 if ( 'return' === $out ) {
5069 return $price;
5070 } else {
5071 echo esc_html( $price );
5072 }
5073 }
5074
5075 /**
5076 * Formatted tax included normal amount
5077 *
5078 * @param string $out Return value or echo.
5079 * @return string|void
5080 */
5081 function usces_the_itemCpriceCr_taxincluded( $out = '' ) {
5082 global $usces;
5083 $usces_tax = Welcart_Tax::get_instance();
5084
5085 $price_taxincluded = usces_the_itemCprice_taxincluded( 'return' );
5086 $price = $usces->get_currency( $price_taxincluded, true, false );
5087 $price = apply_filters( 'usces_filter_the_item_cprice_cr_taxincluded', $price, $price_taxincluded, $out );
5088 if ( 'return' === $out ) {
5089 return $price;
5090 } else {
5091 echo esc_html( $price );
5092 }
5093 }
5094
5095 /**
5096 * Password policy
5097 *
5098 * @param string $out Return value or echo.
5099 * @return string|void
5100 */
5101 function usces_password_policy_message( $out = '' ) {
5102
5103 $usces_options = get_option( 'usces', array() );
5104 $rules = array();
5105 $sep = '';
5106
5107 if ( ! empty( $usces_options['system']['member_pass_rule_max'] ) ) {
5108 if ( $usces_options['system']['member_pass_rule_max'] === $usces_options['system']['member_pass_rule_min'] ) {
5109 $rules[] = sprintf( __( '%s characters long', 'usces' ), $usces_options['system']['member_pass_rule_min'] );
5110 } else {
5111 $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'] );
5112 $sep = __( 'use', 'usces' );
5113 }
5114 } else {
5115 $rules[] = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $usces_options['system']['member_pass_rule_min'], '30' );
5116 $sep = __( 'use', 'usces' );
5117 }
5118
5119 $and = __( 'and', 'usces' );
5120
5121 if ( ! empty( $usces_options['system']['member_pass_rule_digit'] ) ) {
5122 $rules[] = __( 'numeric character', 'usces' );
5123 }
5124
5125 if ( ! empty( $usces_options['system']['member_pass_rule_lowercase'] ) ) {
5126 $rules[] = __( 'lower-case alphabetics', 'usces' );
5127 }
5128
5129 if ( ! empty( $usces_options['system']['member_pass_rule_upercase'] ) ) {
5130 $rules[] = __( 'upper-case alphabetics', 'usces' );
5131 }
5132
5133 if ( ! empty( $usces_options['system']['member_pass_rule_symbol'] ) ) {
5134 $rules[] = __( 'symbolic character', 'usces' );
5135 }
5136
5137 $first = array_shift( $rules );
5138 $ret = '';
5139 if ( 0 === count( $rules ) ) {
5140 $ret = sprintf( __( 'Password must be at least %s.', 'usces' ), $first );
5141 } elseif ( 1 === count( $rules ) ) {
5142 $rule1 = sprintf( __( ' and include one or more %s', 'usces' ), $rules[0] );
5143 $ret = sprintf( __( 'Password must be at least %1$s%2$s.', 'usces' ), $first, $rule1 );
5144 } else {
5145 $rule2 = '';
5146 foreach ( $rules as $rule ) {
5147 if ( '' !== $rule2 ) {
5148 $rule2 .= __( ',', 'usces' );
5149 }
5150 $rule2 .= $rule;
5151 }
5152 $rule1 = sprintf( __( ' and include one or more %s', 'usces' ), $rule2 );
5153 $ret = sprintf( __( 'Password must be at least %1$s%2$s.', 'usces' ), $first, $rule1 );
5154 }
5155
5156 $ret = apply_filters( 'usces_filter_password_policy_message', $ret );
5157 if ( 'return' === $out ) {
5158 return $ret;
5159 }
5160
5161 echo '<p class="password_policy">' . esc_html( $ret ) . '</p>';
5162 }
5163
5164 /**
5165 * Formatted tax included amount
5166 *
5167 * @param bool $label_pre Forward label.
5168 * @param string $label Label.
5169 * @param string $start_tag Start tag.
5170 * @param string $end_tag End tag.
5171 * @param bool $symbol_pre Forward symbol.
5172 * @param bool $symbol_post Backward symbol.
5173 * @param bool $seperator_flag Seperator.
5174 * @param string $out Return value or echo.
5175 * @return string|void
5176 */
5177 function usces_crform_the_itemPriceCr_taxincluded( $label_pre = true, $label = '', $start_tag = '', $end_tag = '', $symbol_pre = true, $symbol_post = false, $seperator_flag = true, $out = '' ) {
5178 global $usces;
5179
5180 if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
5181 $res = '';
5182 } else {
5183 $price_taxincluded = usces_the_itemPrice_taxincluded( 'return' );
5184 $price = esc_html( $usces->get_currency( $price_taxincluded, $symbol_pre, $symbol_post, $seperator_flag ) );
5185 if ( empty( $label ) ) {
5186 $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
5187 } else {
5188 $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
5189 }
5190 if ( empty( $start_tag ) ) {
5191 $start_tag = '<p class="tax_inc_block">( ';
5192 }
5193 if ( $label_pre ) {
5194 $start_tag = $start_tag . $label_tag;
5195 }
5196 if ( empty( $end_tag ) ) {
5197 $end_tag = ' )</p>';
5198 }
5199 if ( true !== $label_pre ) {
5200 $end_tag = $label_tag . $end_tag;
5201 }
5202 $res = apply_filters( 'usces_filter_crform_the_itemPriceCr_taxincluded', $start_tag . $price . $end_tag, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
5203 }
5204 if ( 'return' === $out ) {
5205 return wel_esc_script( $res );
5206 } else {
5207 wel_esc_script_e( $res );
5208 }
5209 }
5210
5211 /**
5212 * Tax-included amount
5213 *
5214 * @param int $post_id Post ID.
5215 * @return float
5216 */
5217 function usces_itemPrice_taxincluded( $post_id = null ) {
5218 global $usces;
5219
5220 if ( null === $post_id ) {
5221 global $post;
5222 $post_id = $post->ID;
5223 }
5224 $usces_tax = Welcart_Tax::get_instance();
5225
5226 $skus = $usces->get_skus( $post_id );
5227 $skucode = $skus[0]['code'];
5228 $skuprice = $skus[0]['price'];
5229 $tax_rate = $usces_tax->get_sku_tax_rate( $post_id, $skucode );
5230 $tax = (float) sprintf( '%.3f', (float) $skuprice * (float) $tax_rate / 100 );
5231 $tax = usces_tax_rounding_off( $tax );
5232 $price = $skuprice + $tax;
5233 return $price;
5234 }
5235
5236 /**
5237 * Tax-included normal amount
5238 *
5239 * @param int $post_id Post ID.
5240 * @param bool $label_pre Forward label.
5241 * @param string $label Label.
5242 * @param string $start_tag Start tag.
5243 * @param string $end_tag End tag.
5244 * @param bool $symbol_pre Forward symbol.
5245 * @param bool $symbol_post Backward symbol.
5246 * @param bool $seperator_flag Seperator.
5247 * @return string
5248 */
5249 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 ) {
5250 global $usces;
5251
5252 if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
5253 $res = '';
5254 } else {
5255 $price_taxincluded = usces_itemPrice_taxincluded( $post_id );
5256 $price = esc_html( $usces->get_currency( $price_taxincluded, $symbol_pre, $symbol_post, $seperator_flag ) );
5257 if ( empty( $label ) ) {
5258 $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
5259 } else {
5260 $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
5261 }
5262 if ( empty( $start_tag ) ) {
5263 $start_tag = '<p class="tax_inc_block">( ';
5264 }
5265 if ( $label_pre ) {
5266 $start_tag = $start_tag . $label_tag;
5267 }
5268 if ( empty( $end_tag ) ) {
5269 $end_tag = ' )</p>';
5270 }
5271 if ( true !== $label_pre ) {
5272 $end_tag = $label_tag . $end_tag;
5273 }
5274 $res = apply_filters( 'usces_filter_crform_itemPriceCr_taxincluded', $start_tag . $price . $end_tag, $post_id, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
5275 }
5276 return $res;
5277 }
5278
5279 /**
5280 * Cart Totals
5281 *
5282 * @param string $out Return value or echo.
5283 * @return string|void
5284 */
5285 function usces_get_cart_total_rows( $out = '' ) {
5286 global $usces;
5287
5288 $res = '';
5289 if ( isset( $usces->options['tax_display'] ) && 'deactivate' !== $usces->options['tax_display'] ) {
5290 if ( isset( $usces->options['tax_mode'] ) && 'include' !== $usces->options['tax_mode'] ) {
5291 $total = usces_total_price( 'return' );
5292 $tax = usces_cart_tax( 'return' );
5293 $res .= ' <tr>
5294 <th class="num"></th>
5295 <th class="thumbnail"></th>
5296 <th colspan="3" scope="row" class="aright">' . __( 'Total', 'usces' ) . '</th>
5297 <th class="aright amount">' . usces_crform( $total, true, false, true ) . '</th>
5298 <th class="stock"></th>
5299 <th class="action"></th>
5300 </tr>' . "\n";
5301 $res .= ' <tr class="tax">
5302 <th class="num"></th>
5303 <th class="thumbnail"></th>
5304 <th colspan="3" scope="row" class="aright tax">' . __( 'Tax', 'usces' ) . '</th>
5305 <th class="aright amount tax">' . usces_crform( usces_cart_tax( 'return' ), true, false, true ) . '</th>
5306 <th class="stock"></th>
5307 <th class="action"></th>
5308 </tr>' . "\n";
5309 $res .= ' <tr>
5310 <th class="num"></th>
5311 <th class="thumbnail"></th>
5312 <th colspan="3" scope="row" class="aright">' . __( 'total items', 'usces' ) . '</th>
5313 <th class="aright amount">' . usces_crform( $total + $tax, true, false, true ) . '</th>
5314 <th class="stock"></th>
5315 <th class="action"></th>
5316 </tr>' . "\n";
5317 } else {
5318 $total = usces_total_price( 'return' );
5319 $tax = usces_internal_tax( array( 'total_items_price' => $total ), 'return' );
5320 $res .= ' <tr class="tax">
5321 <th class="num"></th>
5322 <th class="thumbnail"></th>
5323 <th colspan="3" scope="row" class="aright tax">' . __( 'Internal tax', 'usces' ) . '</th>
5324 <th class="aright amount tax">( ' . usces_crform( $tax, true, false, true ) . ' )</th>
5325 <th class="stock"></th>
5326 <th class="action"></th>
5327 </tr>' . "\n";
5328 $res .= ' <tr>
5329 <th class="num"></th>
5330 <th class="thumbnail"></th>
5331 <th colspan="3" scope="row" class="aright">' . __( 'total items', 'usces' ) . '</th>
5332 <th class="aright amount">' . usces_crform( $total, true, false, true ) . '</th>
5333 <th class="stock"></th>
5334 <th class="action"></th>
5335 </tr>' . "\n";
5336 }
5337 }
5338 if ( 'return' === $out ) {
5339 return wel_esc_script( $res );
5340 } else {
5341 wel_esc_script_e( $res );
5342 }
5343 }
5344
5345 if ( ! function_exists( 'welcart_assistance_excerpt_length' ) ) {
5346 /**
5347 * Assistance excerpt length
5348 *
5349 * @param int $length Length.
5350 * @return int
5351 */
5352 function welcart_assistance_excerpt_length( $length ) {
5353 return 10;
5354 }
5355 }
5356
5357 if ( ! function_exists( 'welcart_assistance_excerpt_mblength' ) ) {
5358 /**
5359 * Assistance excerpt mobile length
5360 *
5361 * @param int $length Length.
5362 * @return int
5363 */
5364 function welcart_assistance_excerpt_mblength( $length ) {
5365 return 40;
5366 }
5367 }
5368