PluginProbe
Welcart e-Commerce / 2.11.34
Welcart e-Commerce v2.11.34
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.34, at functions/template_func.php

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