PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
← All changes | functions/template_func.php +4295 -2294 1.4.12.12.4 View file →
@@ -1,249 +1,498 @@
1 1 <?php
2 -function usces_guid_tax( $out = '' ){
2 +/**
3 + * Template functions
4 + *
5 + * @package Welcart
6 + */
7 +
8 +/**
9 + * Tax guid
10 + *
11 + * @param string $out Return value or echo.
12 + * @param bool $tag HTML tag.
13 + * @return string|void
14 + */
15 +function usces_guid_tax( $out = '', $tag = true ) {
3 16 global $usces;
4 17
5 - if( $out == 'return' ){
6 - return $usces->getGuidTax();
7 - }else{
8 - echo $usces->getGuidTax();
18 + $guid_tax = '';
19 + if ( $tag ) {
20 + $guid_tax = $usces->getGuidTax();
21 + } else {
22 + if ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) {
23 + $guid_tax = '';
24 + } else {
25 + $tax_rate = (int) $usces->options['tax_rate'];
26 + if ( isset( $usces->options['tax_mode'] ) ) {
27 + if ( 'exclude' === $usces->options['tax_mode'] ) {
28 + $guid_tax = __( '(Excl. Tax)', 'usces' );
29 + } else {
30 + $guid_tax = __( '(Incl. Tax)', 'usces' );
31 + }
32 + } else {
33 + if ( 0 < $tax_rate ) {
34 + $guid_tax = __( '(Excl. Tax)', 'usces' );
35 + } else {
36 + $guid_tax = __( '(Incl. Tax)', 'usces' );
37 + }
38 + }
39 + }
9 40 }
41 +
42 + $guid_tax = apply_filters( 'usces_filter_guid_tax', $guid_tax );
43 +
44 + if ( 'return' === $out ) {
45 + return wel_esc_script( $guid_tax );
46 + } else {
47 + wel_esc_script_e( $guid_tax );
48 + }
10 49 }
11 50
12 -function usces_tax_label( $data = array(), $out = '' ){
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 = '' ) {
13 59 global $usces;
14 - if( empty($data) ){
15 - $tax_mode = $usces->options['tax_mode'];
16 - }else{
17 - $condition = maybe_unserialize($data['order_condition']);
18 - $tax_mode = isset($condition['tax_mode']) ? $condition['tax_mode'] : $usces->options['tax_mode'];
60 +
61 + if ( empty( $data ) || ! array_key_exists( 'order_condition', $data ) ) {
62 + $condition = $usces->get_condition();
63 + $tax_mode = $usces->options['tax_mode'];
64 + } else {
65 + $condition = wel_safe_maybe_unserialize( $data['order_condition'] );
66 + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : $usces->options['tax_mode'];
19 67 }
20 - if( 'exclude' == $tax_mode ){
21 - $label = __('consumption tax', 'usces');
22 - }else{
23 - if( isset($condition['tax_mode']) && !empty($data['ID']) ){
68 + if ( 'exclude' === $tax_mode ) {
69 + $label = __( 'consumption tax', 'usces' );
70 + } else {
71 + if ( isset( $condition['tax_mode'] ) && ! empty( $data['ID'] ) ) {
24 72 $materials = array(
25 73 'total_items_price' => $data['order_item_total_price'],
26 - 'discount' => $data['order_discount'],
27 - 'shipping_charge' => $data['order_shipping_charge'],
28 - 'cod_fee' => $data['order_cod_fee'],
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'],
29 81 );
30 - $label = __('Internal tax', 'usces') . '(' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return') . ')';
31 - }else{
32 - $label = __('Internal tax', 'usces');
82 + $label = __( 'Internal tax', 'usces' ) . '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
83 + } else {
84 + $label = __( 'Internal tax', 'usces' );
33 85 }
34 86 }
35 - $label = apply_filters( 'usces_filter_tax_label', $label);
36 -
37 - if( $out == 'return' ){
38 - return $label;
39 - }else{
40 - echo $label;
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 );
41 93 }
42 94 }
43 95
44 -function usces_tax( $usces_entries, $out = '' ){
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 = '' ) {
45 104 global $usces;
46 105
47 - if( 'exclude' == $usces->options['tax_mode'] ){
48 - $tax_str = usces_crform($usces_entries['order']['tax'], true, false,'return');
49 - }else{
50 - $materials = array(
51 - 'total_items_price' => $usces_entries['order']['total_items_price'],
52 - 'discount' => $usces_entries['order']['discount'],
53 - 'shipping_charge' => $usces_entries['order']['shipping_charge'],
54 - 'cod_fee' => $usces_entries['order']['cod_fee'],
55 - );
56 - $tax_str = '(' . usces_crform(usces_internal_tax( $materials, 'return' ), true, false,'return') . ')';
106 + if ( empty( $data ) || ! array_key_exists( 'order_condition', $data ) ) {
107 + $condition = $usces->get_condition();
108 + $tax_mode = $usces->options['tax_mode'];
109 + } else {
110 + $condition = wel_safe_maybe_unserialize( $data['order_condition'] );
111 + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : $usces->options['tax_mode'];
57 112 }
58 - $tax_str = apply_filters( 'usces_filter_tax', $tax_str);
59 -
60 - if( $out == 'return' ){
61 - return $tax_str;
62 - }else{
63 - echo $tax_str;
113 +
114 + if ( ! usces_is_tax_display() ) {
115 + $tax_str = '';
116 + } else {
117 + if ( 'exclude' === $tax_mode ) {
118 + if ( array_key_exists( 'order', $data ) && array_key_exists( 'tax', $data['order'] ) ) { /* from Entry */
119 + $tax = $data['order']['tax'];
120 + } elseif ( array_key_exists( 'order_tax', $data ) ) { /* from Order Data */
121 + $tax = $data['order_tax'];
122 + } elseif ( array_key_exists( 'tax', $data ) ) {
123 + $tax = $data['tax'];
124 + } else {
125 + $tax = 0;
126 + }
127 + $tax_str = usces_crform( $tax, true, false, 'return' );
128 + } else {
129 + if ( array_key_exists( 'order', $data ) ) { /* from Entry */
130 + $materials = array(
131 + 'total_items_price' => $data['order']['total_items_price'],
132 + 'discount' => ( isset( $data['order']['discount'] ) ) ? $data['order']['discount'] : 0,
133 + 'shipping_charge' => ( isset( $data['order']['shipping_charge'] ) ) ? $data['order']['shipping_charge'] : 0,
134 + 'cod_fee' => ( isset( $data['order']['cod_fee'] ) ) ? $data['order']['cod_fee'] : 0,
135 + 'use_point' => ( isset( $data['order']['use_point'] ) ) ? $data['order']['use_point'] : 0,
136 + );
137 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
138 + } elseif ( array_key_exists( 'order_tax', $data ) ) { /* from Order Data */
139 + $materials = array(
140 + 'total_items_price' => $data['order_item_total_price'],
141 + 'discount' => $data['order_discount'],
142 + 'shipping_charge' => $data['order_shipping_charge'],
143 + 'cod_fee' => $data['order_cod_fee'],
144 + 'use_point' => $data['order_usedpoint'],
145 + 'carts' => usces_get_ordercartdata( $data['ID'] ),
146 + 'condition' => wel_safe_unserialize( $data['order_condition'] ),
147 + );
148 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
149 + } elseif ( array_key_exists( 'tax', $data ) ) {
150 + $item_total_price = $usces->get_total_price( $data['cart'] );
151 + $materials = array(
152 + 'total_items_price' => $item_total_price,
153 + 'discount' => ( isset( $data['discount'] ) ) ? $data['discount'] : 0,
154 + 'shipping_charge' => ( isset( $data['shipping_charge'] ) ) ? $data['shipping_charge'] : 0,
155 + 'cod_fee' => ( isset( $data['cod_fee'] ) ) ? $data['cod_fee'] : 0,
156 + 'use_point' => ( isset( $data['usedpoint'] ) ) ? $data['usedpoint'] : 0,
157 + 'carts' => $data['cart'],
158 + );
159 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
160 + } else {
161 + $materials = array();
162 + $tax_str = '( ' . usces_crform( usces_internal_tax( $materials, 'return' ), true, false, 'return' ) . ' )';
163 + }
164 + }
165 + $tax_str = apply_filters( 'usces_filter_tax', $tax_str );
64 166 }
167 +
168 + if ( 'return' === $out ) {
169 + return wel_esc_script( $tax_str );
170 + } else {
171 + wel_esc_script_e( $tax_str );
172 + }
65 173 }
66 174
67 -function usces_internal_tax( $materials, $out = '' ){
68 - global $usces, $usces_settings;
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;
69 184
70 - if( 'products' == $usces->options['tax_target'] ){
71 - $total = $materials['total_items_price'] + $materials['discount'];
72 - }else{
73 - $total = $materials['total_items_price'] + $materials['discount'] + $materials['shipping_charge'] + $materials['cod_fee'];
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' ) . ' )';
74 198 }
75 - $total = apply_filters( 'usces_filter_internal_tax_total', $total, $materials);
199 + $tax_str = apply_filters( 'usces_filter_order_history_tax', $tax_str, $data, $tax_mode );
200 + return $tax_str;
201 +}
76 202
77 - $tax = $total * $usces->options['tax_rate'] / 100;
78 - $tax = $total - $total / (1 + ($usces->options['tax_rate'] / 100));
79 - $cr = $usces->options['system']['currency'];
80 - $decimal = $usces_settings['currency'][$cr][1];
81 - $decipad = (int)str_pad( '1', $decimal+1, '0', STR_PAD_RIGHT );
82 - switch( $usces->options['tax_method'] ){
83 - case 'cutting':
84 - $tax = floor($tax*$decipad)/$decipad;
85 - break;
86 - case 'bring':
87 - $tax = ceil($tax*$decipad)/$decipad;
88 - break;
89 - case 'rounding':
90 - if( 0 < $decimal ){
91 - $tax = round($tax, (int)$decimal);
92 - }else{
93 - $tax = round($tax);
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 + }
94 240 }
95 - break;
96 - }
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 + }
97 250
98 - $tax = apply_filters( 'usces_filter_internal_tax', $tax, $materials);
99 -
100 - if( $out == 'return' ){
101 - return $tax;
102 - }else{
103 - echo $tax;
251 + if ( 'return' === $out ) {
252 + return wel_esc_script( $tax );
253 + } else {
254 + wel_esc_script_e( $tax );
104 255 }
105 256 }
106 257
258 +/**
259 + * Currency Symbol
260 + *
261 + * @param string $out Return value or echo.
262 + * @return string|void
263 + */
107 264 function usces_currency_symbol( $out = '' ) {
108 265 global $usces;
109 266
110 - if( $out == 'return' ){
267 + if ( 'return' === $out ) {
111 268 return $usces->getCurrencySymbol();
112 - }else{
113 - echo esc_html($usces->getCurrencySymbol());
269 + } else {
270 + echo esc_html( $usces->getCurrencySymbol() );
114 271 }
115 272 }
116 273
274 +/**
275 + * Error Verification
276 + *
277 + * @return bool
278 + */
117 279 function usces_is_error_message() {
118 280 global $usces;
119 - if ( $usces->error_message != '' )
281 +
282 + if ( '' !== $usces->error_message ) {
120 283 return true;
121 - else
284 + } else {
122 285 return false;
286 + }
123 287 }
124 288
125 -function usces_is_item( $post_id = NULL ) {
126 - if( NULL == $post_id ){
289 +/**
290 + * Is item
291 + *
292 + * @param int $post_id Post ID.
293 + * @return bool
294 + */
295 +function usces_is_item( $post_id = null ) {
296 + if ( null === $post_id ) {
127 297 global $post;
128 - }else{
129 - $post = get_post($post_id);
298 + if ( empty( $post->ID ) ) {
299 + return false;
300 + }
301 + $post_id = $post->ID;
130 302 }
131 - if ( isset($post->post_mime_type) && $post->post_mime_type == 'item' )
303 + $product = wel_get_product( $post_id );
304 + if ( isset( $product['_pst'] ) && 'item' === $product['_pst']->post_mime_type ) {
132 305 return true;
133 - else
306 + } else {
134 307 return false;
308 + }
135 309 }
136 310
311 +/**
312 + * Item code
313 + *
314 + * @param string $out Return value or echo.
315 + * @return string|void
316 + */
137 317 function usces_the_itemCode( $out = '' ) {
138 318 global $post;
139 - $post_id = $post->ID;
140 319
141 - $str = get_post_meta($post_id, '_itemCode', true);
142 -
143 - if( $out == 'return' ){
320 + $product = wel_get_product( $post->ID );
321 + $str = $product['itemCode'];
322 +
323 + if ( 'return' === $out ) {
144 324 return $str;
145 - }else{
146 - echo esc_html($str);
325 + } else {
326 + echo esc_html( $str );
147 327 }
148 328 }
149 329
150 -function usces_the_itemName( $out = '', $post = NULL ) {
151 - if($post == NULL)
330 +/**
331 + * Item name
332 + *
333 + * @param string $out Return value or echo.
334 + * @param object $post Post data.
335 + * @return string|void
336 + */
337 +function usces_the_itemName( $out = '', $post = null ) {
338 + if ( null === $post ) {
152 339 global $post;
153 -
154 - $post_id = $post->ID;
340 + }
155 341
156 - $str = get_post_meta($post_id, '_itemName', true);
157 -
158 - if( $out == 'return' ){
342 + $product = wel_get_product( $post );
343 + $str = $product['itemName'];
344 +
345 + if ( 'return' === $out ) {
159 346 return $str;
160 - }else{
161 - echo esc_html($str);
347 + } else {
348 + echo esc_html( $str );
162 349 }
163 350 }
164 351
165 -function usces_the_point_rate( $out = '' ){
352 +/**
353 + * Point rate
354 + *
355 + * @param string $out Return value or echo.
356 + * @return string|void
357 + */
358 +function usces_the_point_rate( $out = '' ) {
166 359 global $post;
167 - $post_id = $post->ID;
168 360
169 - $str = get_post_meta($post_id, '_itemPointrate', true);
170 - $rate = (int)$str;
171 -
172 - if( $out == 'return' ){
361 + $product = wel_get_product( $post );
362 + $str = $product['itemPointrate'];
363 + $rate = (int) $str;
364 +
365 + if ( 'return' === $out ) {
173 366 return $rate;
174 - }else{
175 - echo esc_html($rate);
367 + } else {
368 + echo esc_html( $rate );
176 369 }
177 370 }
178 371
179 -function usces_the_shipment_aim( $out = '' ){
372 +/**
373 + * Shipment
374 + *
375 + * @param string $out Return value or echo.
376 + * @return string|void
377 + */
378 +function usces_the_shipment_aim( $out = '' ) {
180 379 global $post;
181 - $post_id = $post->ID;
182 380
183 - $str = get_post_meta($post_id, '_itemShipping', true);
184 - $no = (int)$str;
185 - if( 0 === $no ) return;
186 -
187 - $rules = get_option('usces_shipping_rule');
188 -
189 - if( $out == 'return' ){
190 - return $rules[$no];
191 - }else{
192 - echo esc_html($rules[$no]);
381 + $product = wel_get_product( $post );
382 + $str = $product['itemShipping'];
383 + $no = (int) $str;
384 + if ( 0 === $no ) {
385 + return '';
193 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 + }
194 394 }
195 395
196 -function usces_the_item(){
396 +/**
397 + * Current item
398 + */
399 +function usces_the_item() {
197 400 global $usces, $post;
198 -
199 - $usces->itemskus = $usces->get_skus($post->ID, 'sort');
200 - $usces->itemopts = usces_get_opts($post->ID, 'sort');
201 -
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 +
202 407 return;
203 408 }
204 409
205 -function usces_get_itemMeta($metakey, $post_id, $out = ''){
206 - $str = get_post_meta($post_id, $metakey, true);
207 - $value = $str;
208 -
209 - if( $out == 'return' ){
410 +/**
411 + * Get item meta
412 + *
413 + * @param string $metakey Meta key.
414 + * @param int $post_id Post ID.
415 + * @param string $out Return value or echo.
416 + * @return string|void
417 + */
418 +function usces_get_itemMeta( $metakey, $post_id, $out = '' ) {
419 + $product = wel_get_product( $post_id );
420 + $reserved_key = ltrim( $metakey, '_' );
421 +
422 + if ( array_key_exists( $reserved_key, $product ) ) {
423 + $meta = $product[ $reserved_key ];
424 + } else {
425 + $meta = $product[ $metakey ];
426 + }
427 + if ( is_array( $meta ) ) {
428 + $value = $meta[0];
429 + } else {
430 + $value = $meta;
431 + }
432 +
433 + if ( 'return' === $out ) {
210 434 return $value;
211 - }else{
212 - echo esc_html($value);
435 + } else {
436 + echo esc_html( $value );
213 437 }
214 438 }
215 439
440 +/**
441 + * Count SKU
442 + *
443 + * @return int
444 + */
216 445 function usces_sku_num() {
217 446 global $usces;
218 -
219 - return count($usces->itemskus);
447 +
448 + $sku_num = ( ! empty( $usces->itemskus ) && is_array( $usces->itemskus ) ) ? count( $usces->itemskus ) : 0;
449 + return $sku_num;
220 450 }
221 451
452 +/**
453 + * Is SKU
454 + *
455 + * @return bool
456 + */
222 457 function usces_is_skus() {
223 458 global $usces;
224 -
225 - if( 0 < count($usces->itemskus) ){
226 - reset($usces->itemskus);
459 +
460 + if ( ! empty( $usces->itemskus ) && is_array( $usces->itemskus ) && 0 < count( $usces->itemskus ) ) {
461 + $usces->current_itemsku = -1;
462 + reset( $usces->itemskus );
227 463 $usces->itemsku = array();
228 464 return true;
229 - }else{
465 + } else {
230 466 return false;
231 467 }
232 468 }
233 469
470 +/**
471 + * Reset SKU
472 + */
234 473 function usces_reset_skus() {
235 474 global $usces;
236 -
237 - reset($usces->itemskus);
475 +
476 + $usces->current_itemsku = -1;
477 + reset( $usces->itemskus );
238 478 }
239 479
480 +/**
481 + * Have SKU
482 + *
483 + * @return bool
484 + */
240 485 function usces_have_skus() {
241 486 global $usces;
242 -
243 - $res_each = each($usces->itemskus);
244 - $usces->itemsku = $res_each['value'];
245 - if($usces->itemsku) {
487 +
488 + if ( null === $usces->current_itemsku ) {
489 + $usces->current_itemsku = -1;
490 + }
491 +
492 + if ( $usces->current_itemsku + 1 < usces_sku_num() ) {
493 + $usces->current_itemsku++;
494 + $usces->itemsku = $usces->itemskus[ $usces->current_itemsku ];
246 495 return true;
247 496 } else {
248 497 return false;
249 498 }
@@ -248,695 +497,1251 @@
248 497 return false;
249 498 }
250 499 }
251 500
252 -function usces_the_itemSku($out = '') {
501 +/**
502 + * SKU data
503 + *
504 + * @param string $out Return value or echo.
505 + * @return string|void
506 + */
507 +function usces_the_itemSku( $out = '' ) {
253 508 global $usces;
254 509
255 - if($out == 'return'){
256 - return $usces->itemsku['code'];
257 - }else{
258 - echo esc_attr($usces->itemsku['code']);
510 + $skucode = isset( $usces->itemsku['code'] ) ? $usces->itemsku['code'] : '';
511 + if ( 'return' === $out ) {
512 + return $skucode;
513 + } else {
514 + echo esc_attr( $skucode );
259 515 }
260 516 }
261 517
262 -function usces_the_itemPrice($out = '') {
518 +/**
519 + * SKU price
520 + *
521 + * @param string $out Return value or echo.
522 + * @return int|void
523 + */
524 +function usces_the_itemPrice( $out = '' ) {
263 525 global $usces;
264 - if($out == 'return'){
526 +
527 + if ( 'return' === $out ) {
265 528 return $usces->itemsku['price'];
266 - }else{
267 - echo number_format($usces->itemsku['price']);
529 + } else {
530 + echo number_format( $usces->itemsku['price'] );
268 531 }
269 532 }
270 533
271 -function usces_the_itemCprice($out = '') {
534 +/**
535 + * SKU normal price
536 + *
537 + * @param string $out Return value or echo.
538 + * @return int|void
539 + */
540 +function usces_the_itemCprice( $out = '' ) {
272 541 global $usces;
273 - if($out == 'return'){
542 +
543 + if ( 'return' === $out ) {
274 544 return $usces->itemsku['cprice'];
275 - }else{
276 - echo number_format($usces->itemsku['cprice']);
545 + } else {
546 + echo number_format( $usces->itemsku['cprice'] );
277 547 }
278 548 }
279 549
280 -function usces_the_itemPriceCr($out = '') {
550 +/**
551 + * Formatted SKU price
552 + *
553 + * @param string $out Return value or echo.
554 + * @return string|void
555 + */
556 +function usces_the_itemPriceCr( $out = '' ) {
281 557 global $usces;
282 - $res = esc_html($usces->get_currency($usces->itemsku['price'], true, false ));
283 558
284 - if($out == 'return'){
559 + $res = $usces->get_currency( $usces->itemsku['price'], true, false );
560 + $res = apply_filters( 'usces_filter_the_item_price_cr', $res, $usces->itemsku['price'], $out );
561 +
562 + if ( 'return' === $out ) {
285 563 return $res;
286 - }else{
287 - echo $res;
564 + } else {
565 + echo esc_html( $res );
288 566 }
289 567 }
290 568
291 -function usces_the_itemCpriceCr($out = '') {
569 +/**
570 + * Formatted normal SKU price
571 + *
572 + * @param string $out Return value or echo.
573 + * @return string|void
574 + */
575 +function usces_the_itemCpriceCr( $out = '' ) {
292 576 global $usces;
293 - $res = esc_html($usces->get_currency($usces->itemsku['cprice'], true, false ));
294 577
295 - if($out == 'return'){
578 + $res = $usces->get_currency( $usces->itemsku['cprice'], true, false );
579 + $res = apply_filters( 'usces_filter_the_item_cprice_cr', $res, $usces->itemsku['cprice'], $out );
580 +
581 + if ( 'return' === $out ) {
296 582 return $res;
297 - }else{
298 - echo $res;
583 + } else {
584 + echo esc_html( $res );
299 585 }
300 586 }
301 587
588 +/**
589 + * Currency code
590 + *
591 + * @param string $out Return value or echo.
592 + * @return string|void
593 + */
302 594 function usces_crcode( $out = '' ) {
303 595 global $usces;
304 - $res = esc_html($usces->get_currency_code());
305 -
306 - if($out == 'return'){
596 +
597 + $res = esc_html( $usces->get_currency_code() );
598 +
599 + if ( 'return' === $out ) {
307 600 return $res;
308 - }else{
309 - echo __($res, 'usces');
601 + } else {
602 + echo __( $res, 'usces' );
310 603 }
311 604 }
312 605
313 -function usces_crsymbol( $out = '', $js = NULL ) {
606 +/**
607 + * Currency symbol code
608 + *
609 + * @param string $out Return value or echo.
610 + * @param string $js Use js.
611 + * @return string|void
612 + */
613 +function usces_crsymbol( $out = '', $js = '' ) {
314 614 global $usces;
615 +
315 616 $res = $usces->getCurrencySymbol();
316 - if( 'js' === $js && '&yen;' == $res ){
317 - $res = mb_convert_encoding($res, 'UTF-8', 'HTML-ENTITIES');
617 + if ( 'js' === $js && '&yen;' == $res ) {
618 + $res = mb_convert_encoding( $res, 'UTF-8', 'HTML-ENTITIES' );
318 619 }
319 -
320 - if($out == 'return'){
620 + if ( 'return' === $out ) {
321 621 return $res;
322 - }else{
323 - echo esc_html($res);
622 + } else {
623 + echo esc_html( $res );
324 624 }
325 625 }
326 626
627 +/**
628 + * Stock
629 + *
630 + * @param string $out Return value or echo.
631 + * @return string|void
632 + */
327 633 function usces_the_itemZaiko( $out = '' ) {
328 - global $usces;
329 - $num = (int)$usces->itemsku['stock'];
330 -
331 - if( 1 < $num || ( 0 === (int)$usces->itemsku['stocknum'] && !WCUtils::is_blank($usces->itemsku['stocknum']) ) ){
332 - $res = $usces->zaiko_status[$num];
333 - }elseif( 1 >= $num && ( 0 === (int)$usces->itemsku['stocknum'] && !WCUtils::is_blank($usces->itemsku['stocknum']) ) ){
334 - $res = $usces->zaiko_status[2];
335 - }else{
336 - $res = $usces->zaiko_status[$num];
634 + global $usces, $post;
635 +
636 + $item_order_acceptable = $usces->getItemOrderAcceptable( $post->ID );
637 + $num = (int) $usces->itemsku['stock'];
638 + $stocknum = $usces->itemsku['stocknum'];
639 +
640 + if ( 1 !== $item_order_acceptable || WCUtils::is_blank( $stocknum ) ) {
641 + if ( 1 < $num || ( 0 === (int) $usces->itemsku['stocknum'] && ! WCUtils::is_blank( $usces->itemsku['stocknum'] ) ) ) {
642 + $res = $usces->zaiko_status[ $num ];
643 + } elseif ( 1 >= $num && ( 0 === (int) $usces->itemsku['stocknum'] && ! WCUtils::is_blank( $usces->itemsku['stocknum'] ) ) ) {
644 + $res = $usces->zaiko_status[2];
645 + } else {
646 + $res = $usces->zaiko_status[ $num ];
647 + }
648 + } else {
649 + if ( 1 < $num ) {
650 + $res = $usces->zaiko_status[ $num ];
651 + } elseif ( 1 >= $num && 0 >= (int) $stocknum ) {
652 + $res = ( ! empty( $usces->options['order_acceptable_label'] ) ) ? $usces->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
653 + } else {
654 + $res = $usces->zaiko_status[ $num ];
655 + }
337 656 }
338 -
339 - if( $out == 'return' ){
657 +
658 + if ( 'return' === $out ) {
340 659 return $res;
341 - }else{
342 - echo esc_html($res);
660 + } else {
661 + echo esc_html( $res );
343 662 }
344 663 }
345 664
665 +/**
666 + * Stock status
667 + *
668 + * @param string $out Return value or echo.
669 + * @return string|void
670 + */
346 671 function usces_the_itemZaikoStatus( $out = '' ) {
347 672 global $usces;
348 -
349 - if( $out == 'return' ){
673 +
674 + if ( 'return' === $out ) {
350 675 return usces_get_itemZaiko( 'name' );
351 - }else{
352 - echo esc_html(usces_get_itemZaiko( 'name' ));
676 + } else {
677 + echo esc_html( usces_get_itemZaiko( 'name' ) );
353 678 }
354 679 }
355 680
356 -function usces_get_itemZaiko( $field = 'name', $post_id=NULL, $sku=NULL ) {
681 +/**
682 + * SKU stock
683 + *
684 + * @param string $field Key.
685 + * @param int $post_id Post ID.
686 + * @param string $sku SKU code.
687 + * @return string
688 + */
689 +function usces_get_itemZaiko( $field = 'name', $post_id = null, $sku = null ) {
357 690 global $usces;
358 - if( empty($sku) ){
359 - $num = (int)$usces->itemsku['stock'];
360 - }else{
361 - $skus = $usces->get_skus( $post_id, 'code' );
362 - $num = (int)$skus[$sku]['stock'];
691 +
692 + if ( null === $post_id ) {
693 + global $post;
694 + $post_id = $post->ID;
363 695 }
364 -
365 - if( 'id' == $field ){
696 +
697 + if ( empty( $sku ) && ! empty( $usces->itemsku ) ) {
698 + $num = (int) $usces->itemsku['stock'];
699 + $stocknum = $usces->itemsku['stocknum'];
700 + } else {
701 + $skus = wel_get_skus( $post_id, 'code' );
702 + if ( null === $skus || ! isset( $skus[ $sku ] ) ) {
703 + return false;
704 + }
705 + $num = (int) $skus[ $sku ]['stock'];
706 + $stocknum = $skus[ $sku ]['stocknum'];
707 + }
708 +
709 + if ( 'id' === $field ) {
366 710 $res = $num;
367 - }else{
368 - $res = $usces->zaiko_status[$num];
711 + } else {
712 + $item_order_acceptable = $usces->getItemOrderAcceptable( $post_id );
713 + if ( 1 !== (int) $item_order_acceptable || WCUtils::is_blank( $stocknum ) ) {
714 + $res = $usces->zaiko_status[ $num ];
715 + } else {
716 + if ( 2 > $num && 0 >= (int) $stocknum ) {
717 + $res = ( ! empty( $usces->options['order_acceptable_label'] ) ) ? $usces->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
718 + } else {
719 + $res = $usces->zaiko_status[ $num ];
720 + }
721 + }
369 722 }
370 723 return $res;
371 724 }
372 725
726 +/**
727 + * SKU stock
728 + *
729 + * @param string $out Return value or echo.
730 + * @return int|void
731 + */
373 732 function usces_the_itemZaikoNum( $out = '' ) {
374 733 global $usces;
734 +
735 + if ( ! isset( $usces->itemsku['stocknum'] ) ) {
736 + return false;
737 + }
738 +
375 739 $num = $usces->itemsku['stocknum'];
376 -
377 - if( $out == 'return' ){
740 + if ( '' !== $num ) {
741 + $num = (int) $num;
742 + }
743 +
744 + if ( 'return' === $out ) {
378 745 return $num;
379 - }else{
380 - echo number_format($num);
746 + } else {
747 + echo number_format( $num );
381 748 }
382 749 }
383 750
751 +/**
752 + * SKU title
753 + *
754 + * @param string $out Return value or echo.
755 + * @return string|void
756 + */
384 757 function usces_the_itemSkuDisp( $out = '' ) {
385 758 global $usces;
386 -
387 - if( $out == 'return' ){
759 +
760 + if ( ! isset( $usces->itemsku['name'] ) ) {
761 + return false;
762 + }
763 +
764 + if ( 'return' === $out ) {
388 765 return $usces->itemsku['name'];
389 - }else{
390 - echo esc_html($usces->itemsku['name']);
766 + } else {
767 + echo esc_html( $usces->itemsku['name'] );
391 768 }
392 769 }
393 770
771 +/**
772 + * SKU unit
773 + *
774 + * @param string $out Return value or echo.
775 + * @return string|void
776 + */
394 777 function usces_the_itemSkuUnit( $out = '' ) {
395 778 global $usces;
396 -
397 - if( $out == 'return' ){
779 +
780 + if ( ! isset( $usces->itemsku['unit'] ) ) {
781 + return false;
782 + }
783 +
784 + if ( 'return' === $out ) {
398 785 return $usces->itemsku['unit'];
399 - }else{
400 - echo esc_html($usces->itemsku['unit']);
786 + } else {
787 + echo esc_html( $usces->itemsku['unit'] );
401 788 }
402 789 }
403 790
791 +/**
792 + * Top SKU code
793 + *
794 + * @param string $out Return value or echo.
795 + * @return string|void
796 + */
404 797 function usces_the_firstSku( $out = '' ) {
405 798 global $post, $usces;
799 +
406 800 $post_id = $post->ID;
407 -
408 -
409 - $skus = $usces->get_skus( $post_id );
410 -
801 + $skus = wel_get_skus( $post_id );
411 802
412 - if($out == 'return'){
803 + if ( null === $skus || ! isset( $skus[0]['code'] ) ) {
804 + return false;
805 + }
806 +
807 + if ( 'return' === $out ) {
413 808 return $skus[0]['code'];
414 - }else{
415 - echo esc_html($skus[0]['code']);
809 + } else {
810 + echo esc_html( $skus[0]['code'] );
416 811 }
417 812 }
418 813
419 -function usces_the_firstPrice( $out = '', $post = NULL ) {
814 +/**
815 + * Top SKU price
816 + *
817 + * @param string $out Return value or echo.
818 + * @param object $post Post data.
819 + * @return string|void
820 + */
821 +function usces_the_firstPrice( $out = '', $post = null ) {
420 822 global $usces;
421 - if($post == NULL)
823 +
824 + if ( null === $post ) {
422 825 global $post;
826 + }
423 827 $post_id = $post->ID;
424 -
425 - $skus = $usces->get_skus( $post_id );
426 -
427 - if($out == 'return'){
428 - return $skus[0]['price'];
429 - }else{
430 - echo number_format($skus[0]['price']);
828 + $skus = wel_get_skus( $post_id );
829 +
830 + if ( empty( $skus ) ) {
831 + $price = null;
832 + } else {
833 + $price = $skus[0]['price'];
431 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 + }
432 843 }
433 844
434 -function usces_the_firstCprice( $out = '', $post = NULL ) {
845 +/**
846 + * Top SKU normal price
847 + *
848 + * @param string $out Return value or echo.
849 + * @param object $post Post data.
850 + * @return string|void
851 + */
852 +function usces_the_firstCprice( $out = '', $post = null ) {
435 853 global $usces;
436 - if($post == NULL)
854 +
855 + if ( null === $post ) {
437 856 global $post;
857 + }
438 858 $post_id = $post->ID;
439 -
440 - $skus = $usces->get_skus( $post_id );
441 -
442 - if($out == 'return'){
859 + $skus = wel_get_skus( $post_id );
860 +
861 + if ( null === $skus || ! isset( $skus[0]['cprice'] ) ) {
862 + return false;
863 + }
864 +
865 + if ( 'return' === $out ) {
443 866 return $skus[0]['cprice'];
444 - }else{
445 - echo number_format($skus[0]['cprice']);
867 + } else {
868 + echo number_format( $skus[0]['cprice'] );
446 869 }
447 870 }
448 871
449 -function usces_the_firstPriceCr( $out = '', $post = NULL ) {
872 +/**
873 + * Formatted top SKU price
874 + *
875 + * @param string $out Return value or echo.
876 + * @param object $post Post data.
877 + * @return string|void
878 + */
879 +function usces_the_firstPriceCr( $out = '', $post = null ) {
450 880 global $usces;
451 - if($post == NULL)
881 +
882 + if ( null === $post ) {
452 883 global $post;
884 + }
453 885 $post_id = $post->ID;
454 -
455 - $skus = $usces->get_skus( $post_id );
456 - $res = esc_html($usces->get_currency($skus[0]['price'], true, false ));
886 + $skus = wel_get_skus( $post_id );
887 + if ( isset( $skus[0]['price'] ) ) {
888 + $res = $usces->get_currency( $skus[0]['price'], true, false );
889 + $price = apply_filters( 'usces_filter_the_first_price_cr', $res, $skus[0]['price'], $post_id, $skus, $out );
890 + } else {
891 + $price = apply_filters( 'usces_filter_the_first_price_cr', '', null, $post_id, $skus, $out );
892 + }
457 893
458 - if($out == 'return'){
459 - return $res;
460 - }else{
461 - echo $res;
894 + if ( 'return' === $out ) {
895 + return $price;
896 + } else {
897 + echo esc_html( $price );
462 898 }
463 899 }
464 900
465 -function usces_the_firstCpriceCr( $out = '', $post = NULL ) {
901 +/**
902 + * Formatted top SKU normal price
903 + *
904 + * @param string $out Return value or echo.
905 + * @param object $post Post data.
906 + * @return string|void
907 + */
908 +function usces_the_firstCpriceCr( $out = '', $post = null ) {
466 909 global $usces;
467 - if($post == NULL)
910 +
911 + if ( null === $post ) {
468 912 global $post;
913 + }
469 914 $post_id = $post->ID;
470 -
471 - $skus = $usces->get_skus( $post_id );
472 - $res = esc_html($usces->get_currency($skus[0]['cprice'], true, false ));
915 + $skus = wel_get_skus( $post_id );
916 + if ( isset( $skus[0]['cprice'] ) ) {
917 + $res = $usces->get_currency( $skus[0]['cprice'], true, false );
918 + $cprice = apply_filters( 'usces_filter_the_first_cprice_cr', $res, $skus[0]['cprice'], $post_id, $skus, $out );
919 + } else {
920 + $cprice = apply_filters( 'usces_filter_the_first_cprice_cr', '', null, $post_id, $skus, $out );
921 + }
473 922
474 - if($out == 'return'){
475 - return $res;
476 - }else{
477 - echo $res;
923 + if ( 'return' === $out ) {
924 + return $cprice;
925 + } else {
926 + echo esc_html( $cprice );
478 927 }
479 928 }
480 929
481 -function usces_the_firstZaiko( $out = '' ) {
482 - global $post, $usces;
930 +/**
931 + * Top SKU stock
932 + *
933 + * @param string $out Return value or echo.
934 + * @param object $post Post data.
935 + * @return string|void
936 + */
937 +function usces_the_firstZaiko( $out = '', $post = null ) {
938 + global $usces;
939 +
940 + if ( null === $post ) {
941 + global $post;
942 + }
483 943 $post_id = $post->ID;
484 -
485 -
486 - $skus = $usces->get_skus( $post_id );
487 -
488 - if($out == 'return'){
944 + $skus = wel_get_skus( $post_id );
945 +
946 + if ( 'return' === $out ) {
489 947 return $skus[0]['stock'];
490 - }else{
491 - echo esc_html($skus[0]['stock']);
948 + } else {
949 + echo esc_html( $skus[0]['stock'] );
492 950 }
493 951 }
494 952
495 -function usces_the_lastSku( $out = '' ) {
496 - global $post, $usces;
953 +/**
954 + * Last SKU
955 + *
956 + * @param string $out Return value or echo.
957 + * @param object $post Post data.
958 + * @return string|void
959 + */
960 +function usces_the_lastSku( $out = '', $post = null ) {
961 + global $usces;
962 +
963 + if ( null === $post ) {
964 + global $post;
965 + }
497 966 $post_id = $post->ID;
498 -
499 -
500 - $skus = $usces->get_skus( $post_id );
501 - $sku = end($skus);
967 + $skus = wel_get_skus( $post_id );
968 + $sku = end( $skus );
502 969
503 - if($out == 'return'){
970 + if ( 'return' === $out ) {
504 971 return $sku['code'];
505 - }else{
506 - echo esc_html($sku['code']);
972 + } else {
973 + echo esc_html( $sku['code'] );
507 974 }
508 975 }
509 976
510 -function usces_the_lastPrice( $out = '' ) {
511 - global $post, $usces;
977 +/**
978 + * Last SKU price
979 + *
980 + * @param string $out Return value or echo.
981 + * @param object $post Post data.
982 + * @return string|void
983 + */
984 +function usces_the_lastPrice( $out = '', $post = null ) {
985 + global $usces;
986 +
987 + if ( null === $post ) {
988 + global $post;
989 + }
512 990 $post_id = $post->ID;
513 -
514 -
515 - $skus = $usces->get_skus( $post_id );
516 - $sku = end($skus);
517 -
518 - if($out == 'return'){
991 + $skus = wel_get_skus( $post_id );
992 + $sku = end( $skus );
993 +
994 + if ( 'return' === $out ) {
519 995 return $sku['price'];
520 - }else{
521 - echo number_format($sku['price']);
996 + } else {
997 + echo number_format( $sku['price'] );
522 998 }
523 999 }
524 1000
525 -function usces_the_lastZaiko( $out = '' ) {
526 - global $post, $usces;
1001 +/**
1002 + * Last SKU stock
1003 + *
1004 + * @param string $out Return value or echo.
1005 + * @param object $post Post data.
1006 + * @return string|void
1007 + */
1008 +function usces_the_lastZaiko( $out = '', $post = null ) {
1009 + global $usces;
1010 +
1011 + if ( null === $post ) {
1012 + global $post;
1013 + }
527 1014 $post_id = $post->ID;
528 -
529 -
530 - $skus = $usces->get_skus( $post_id );
531 - $sku = end($skus);
532 -
533 - if($out == 'return'){
1015 + $skus = wel_get_skus( $post_id );
1016 + $sku = end( $skus );
1017 +
1018 + if ( 'return' === $out ) {
534 1019 return $sku['stock'];
535 - }else{
536 - echo esc_html($sku['stock']);
1020 + } else {
1021 + echo esc_html( $sku['stock'] );
537 1022 }
538 1023 }
539 1024
540 -function usces_have_zaiko(){
1025 +/**
1026 + * In stock
1027 + *
1028 + * @return bool
1029 + */
1030 +function usces_have_zaiko() {
541 1031 global $post, $usces;
542 - return $usces->is_item_zaiko( $post->ID, $usces->itemsku['code'] );
1032 +
1033 + $post_id = isset( $post->ID ) ? $post->ID : 0;
1034 + $sku_code = isset( $usces->itemsku['code'] ) ? $usces->itemsku['code'] : '';
1035 +
1036 + return $usces->is_item_zaiko( $post_id, $sku_code );
543 1037 }
544 1038
545 -function usces_have_zaiko_anyone( $post_id = NULL ){
546 - global $post, $usces;
547 - if( NULL == $post_id ) $post_id = $post->ID;
548 -
549 - $skus = $usces->get_skus($post_id);
1039 +/**
1040 + * In stock
1041 + *
1042 + * @param int $post_id Post ID.
1043 + * @return bool
1044 + */
1045 +function usces_have_zaiko_anyone( $post_id = null ) {
1046 + global $post, $usces;
1047 +
1048 + if ( null === $post_id ) {
1049 + $post_id = $post->ID;
1050 + }
1051 +
1052 + $skus = wel_get_skus( $post_id );
550 1053 $status = false;
551 - foreach($skus as $sku){
552 - if( (WCUtils::is_blank($sku['stocknum']) || 0 < (int)$sku['stocknum']) && 2 > (int)$sku['stock']) {
1054 +
1055 + foreach ( $skus as $sku ) {
1056 + if ( $usces->is_item_zaiko( $post_id, $sku['code'] ) ) {
553 1057 $status = true;
554 1058 break;
555 1059 }
556 1060 }
557 - return $status;
1061 + return apply_filters( 'usces_have_zaiko_anyone', $status, $post_id, $skus );
558 1062 }
559 1063
560 -function usces_is_gptekiyo( $post_id, $sku, $quant ){
1064 +/**
1065 + * Low or not stock
1066 + *
1067 + * @param int $post_id Post ID.
1068 + * @return bool
1069 + */
1070 +function usces_have_fewstock( $post_id = null ) {
1071 + global $post, $usces;
1072 +
1073 + if ( null === $post_id ) {
1074 + $post_id = $post->ID;
1075 + }
1076 +
1077 + $skus = wel_get_skus( $post_id );
1078 + $res = false;
1079 + foreach ( $skus as $sku ) {
1080 + if ( 1 === (int) $sku['stock'] ) {
1081 + $res = true;
1082 + break;
1083 + }
1084 + }
1085 + return $res;
1086 +}
1087 +
1088 +/**
1089 + * Is applied large-lot discount
1090 + *
1091 + * @param int $post_id Post ID.
1092 + * @param string $sku SKU code.
1093 + * @param int $quant Quantity.
1094 + * @return bool
1095 + */
1096 +function usces_is_gptekiyo( $post_id, $sku, $quant ) {
561 1097 global $usces;
562 1098 return $usces->is_gptekiyo( $post_id, $sku, $quant );
563 1099 }
1100 +
1101 +/**
1102 + * Large-lot discount
1103 + *
1104 + * @param string $out Return value or echo.
1105 + * @return string|void
1106 + */
564 1107 function usces_the_itemGpExp( $out = '' ) {
565 1108 global $post, $usces;
1109 +
566 1110 $post_id = $post->ID;
567 - $sku = $usces->itemsku['code'];
568 - $GpN1 = $usces->getItemGpNum1($post_id);
569 - $GpN2 = $usces->getItemGpNum2($post_id);
570 - $GpN3 = $usces->getItemGpNum3($post_id);
571 - $GpD1 = $usces->getItemGpDis1($post_id);
572 - $GpD2 = $usces->getItemGpDis2($post_id);
573 - $GpD3 = $usces->getItemGpDis3($post_id);
574 - $unit = $usces->getItemSkuUnit($post_id, $sku);
575 - $price = $usces->getItemPrice($post_id, $sku);
1111 + $sku = $usces->itemsku['code'];
1112 + $gpn1 = $usces->getItemGpNum1( $post_id );
1113 + $gpn2 = $usces->getItemGpNum2( $post_id );
1114 + $gpn3 = $usces->getItemGpNum3( $post_id );
1115 + $gpd1 = $usces->getItemGpDis1( $post_id );
1116 + $gpd2 = $usces->getItemGpDis2( $post_id );
1117 + $gpd3 = $usces->getItemGpDis3( $post_id );
1118 + $unit = $usces->getItemSkuUnit( $post_id, $sku );
1119 + $price = $usces->getItemPrice( $post_id, $sku );
576 1120
577 - if( ($usces->itemsku['gp'] == 0) || empty($GpN1) || empty($GpD1) ){
1121 + if ( ( 0 === (int) $usces->itemsku['gp'] ) || empty( $gpn1 ) || empty( $gpd1 ) ) {
578 1122 return;
579 1123 }
580 - $html = "<dl class='itemGpExp'>\n<dt>" . apply_filters( 'usces_filter_itemGpExp_title', __('Business package discount','usces')) . "</dt>\n<dd>\n<ul>\n";
581 - if(!empty($GpN1) && !empty($GpD1)) {
582 - if(empty($GpN2) || empty($GpD2)) {
583 - $html .= "<li>";
584 - $html .= sprintf( __('<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces'),
585 - $usces->get_currency(round($price * (100 - $GpD1) / 100), true, false ),
586 - $usces->getGuidTax(),
587 - esc_html($unit),
588 - $GpN1,
589 - "'price'"
590 - );
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 + }
591 1147 $html .= "</li>\n";
592 1148 } else {
593 -
594 - $html .= "<li>";
595 - $html .= sprintf( __('<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces'),
596 - $usces->get_currency(round($price * (100 - $GpD1) / 100), true, false ),
597 - $usces->getGuidTax(),
598 - esc_html($unit),
599 - $GpN1,
600 - $GpN2-1,
601 - "'price'"
602 - );
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 + }
603 1162 $html .= "</li>\n";
604 - if(empty($GpN3) || empty($GpD3)) {
605 - //$html .= "<li>" . $GpN2 . $unit . __('for more than ','usces') . "1" . $unit . __('par','usces') . "<span class='price'>" . __('$', 'usces') . number_format(round($price * (100 - $GpD2) / 100)) . $usces->getGuidTax() . "</span></li>\n";
606 - $html .= "<li>";
607 - $html .= sprintf( __('<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces'),
608 - $usces->get_currency(round($price * (100 - $GpD2) / 100), true, false ),
609 - $usces->getGuidTax(),
610 - esc_html($unit),
611 - $GpN2,
612 - "'price'"
613 - );
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 + }
614 1176 $html .= "</li>\n";
615 1177 } else {
616 - $html .= "<li>";
617 - $html .= sprintf( __('<span class=%6$s>%1$s</span>%2$s par 1%3$s for %4$s-%5$s%3$s', 'usces'),
618 - $usces->get_currency(round($price * (100 - $GpD2) / 100), true, false ),
619 - $usces->getGuidTax(),
620 - esc_html($unit),
621 - $GpN2,
622 - $GpN3-1,
623 - "'price'"
624 - );
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 + }
625 1204 $html .= "</li>\n";
626 - $html .= "<li>";
627 - $html .= sprintf( __('<span class=%5$s>%1$s</span>%2$s par 1%3$s for more than %4$s%3$s', 'usces'),
628 - $usces->get_currency(round($price * (100 - $GpD3) / 100), true, false ),
629 - $usces->getGuidTax(),
630 - esc_html($unit),
631 - $GpN3,
632 - "'price'"
633 - );
634 - $html .= "</li>\n";
635 1205 }
636 1206 }
637 1207 }
638 - $html .= "</ul></dd></dl>";
639 -
640 - $html = apply_filters('usces_filter_itemGpExp', $html);
641 -
642 - if( $out == 'return' ){
1208 + $html .= '</ul></dd></dl>';
1209 +
1210 + $html = apply_filters( 'usces_filter_itemGpExp', $html );
1211 +
1212 + if ( 'return' === $out ) {
643 1213 return $html;
644 - }else{
645 - echo $html;
1214 + } else {
1215 + echo $html; // no escape due to filter.
646 1216 }
647 1217 }
648 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 + */
649 1289 function usces_the_itemQuant( $out = '' ) {
650 1290 global $usces, $post;
1291 +
651 1292 $post_id = $post->ID;
652 - $sku = esc_attr(urlencode($usces->itemsku['code']));
653 - $value = isset( $_SESSION['usces_singleitem']['quant'][$post_id][$sku] ) ? $_SESSION['usces_singleitem']['quant'][$post_id][$sku] : 1;
654 - $quant = "<input name=\"quant[{$post_id}][" . $sku . "]\" type=\"text\" id=\"quant[{$post_id}][" . $sku . "]\" class=\"skuquantity\" value=\"" . $value . "\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" />";
655 - $html = apply_filters('usces_filter_the_itemQuant', $quant, $post);
656 -
657 - if( $out == 'return' ){
1293 + $sku = urlencode( $usces->itemsku['code'] );
1294 + $value = isset( $_SESSION['usces_singleitem']['quant'][ $post_id ][ $sku ] ) ? $_SESSION['usces_singleitem']['quant'][ $post_id ][ $sku ] : 1;
1295 + $quant = "<input name=\"quant[{$post_id}][" . $sku . "]\" type=\"text\" id=\"quant[{$post_id}][" . $sku . "]\" class=\"skuquantity\" value=\"" . esc_attr( $value ) . "\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" />";
1296 + $html = apply_filters( 'usces_filter_the_itemQuant', $quant, $post );
1297 +
1298 + if ( 'return' === $out ) {
658 1299 return $html;
659 - }else{
660 - echo $html;
1300 + } else {
1301 + echo $html; // no escape due to filter.
661 1302 }
662 1303 }
663 1304
664 -function usces_the_itemSkuButton($value, $type=0, $out = '') {
1305 +/**
1306 + * Add to Cart
1307 + *
1308 + * @param mixed $value Value.
1309 + * @param int $type Submit or button.
1310 + * @param string $out Return value or echo.
1311 + * @return string|void
1312 + */
1313 +function usces_the_itemSkuButton( $value, $type = 0, $out = '' ) {
665 1314 global $usces, $post;
666 - $post_id = $post->ID;
667 - $zaikonum = $usces->itemsku['stocknum'];
668 - $zaiko_status = $usces->itemsku['stock'];
669 - $gptekiyo = $usces->itemsku['gp'];
670 - $skuPrice = $usces->getItemPrice($post_id, $usces->itemsku['code']);
671 - $value = esc_attr(apply_filters( 'usces_filter_incart_button_label', $value));
672 - $sku = esc_attr(urlencode($usces->itemsku['code']));
673 -
674 - if($type == 1)
1315 +
1316 + $post_id = (int) $post->ID;
1317 + $zaikonum = esc_attr( $usces->itemsku['stocknum'] );
1318 + $zaiko_status = esc_attr( $usces->itemsku['stock'] );
1319 + $gptekiyo = esc_attr( $usces->itemsku['gp'] );
1320 + $skuprice = esc_attr( $usces->getItemPrice( $post_id, $usces->itemsku['code'] ) );
1321 + $value = esc_attr( apply_filters( 'usces_filter_incart_button_label', $value ) );
1322 + $sku = esc_attr( urlencode( $usces->itemsku['code'] ) );
1323 +
1324 + if ( 1 === (int) $type ) {
675 1325 $type = 'button';
676 - else
1326 + } else {
677 1327 $type = 'submit';
678 -
679 - $html = "<input name=\"zaikonum[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku}]\" value=\"{$zaikonum}\" />\n";
1328 + }
1329 + $html = "<input name=\"zaikonum[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku}]\" value=\"{$zaikonum}\" />\n";
680 1330 $html .= "<input name=\"zaiko[{$post_id}][{$sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku}]\" value=\"{$zaiko_status}\" />\n";
681 1331 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku}]\" value=\"{$gptekiyo}\" />\n";
682 - $html .= "<input name=\"skuPrice[{$post_id}][{$sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku}]\" value=\"{$skuPrice}\" />\n";
683 - if( $usces->use_js ){
684 - $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}')\" />";
685 - }else{
1332 + $html .= "<input name=\"skuPrice[{$post_id}][{$sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku}]\" value=\"{$skuprice}\" />\n";
1333 + if ( $usces->use_js ) {
1334 + $html .= "<input name=\"inCart[{$post_id}][{$sku}]\" type=\"{$type}\" id=\"inCart[{$post_id}][{$sku}]\" class=\"skubutton\" value=\"{$value}\" onclick=\"return uscesCart.intoCart( '{$post_id}','{$sku}' )\" />";
1335 + } else {
686 1336 $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$sku}]\" type=\"{$type}\" id=\"inCart[{$post_id}][{$sku}]\" class=\"skubutton\" value=\"{$value}\" />";
687 1337 }
688 - $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . $_SERVER['REQUEST_URI'] . "\" />\n";
1338 + $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
1339 + $html = apply_filters( 'usces_filter_item_sku_button', $html, $value, $type );
689 1340
690 - if( $out == 'return' ){
1341 + if ( 'return' === $out ) {
691 1342 return $html;
692 - }else{
693 - echo $html;
1343 + } else {
1344 + echo $html; // no escape due to filter.
694 1345 }
695 1346 }
696 -
697 -function usces_direct_intoCart($post_id, $sku, $force=false, $value=NULL, $options=NULL, $out = '') {
1347 +
1348 +/**
1349 + * Add to Cart ( direct mode )
1350 + *
1351 + * @param int $post_id Post ID.
1352 + * @param string $sku SKU code.
1353 + * @param bool $force Force.
1354 + * @param mixed $value Value.
1355 + * @param bool $options Have options.
1356 + * @param string $out Return value or echo.
1357 + * @return string|void
1358 + */
1359 +function usces_direct_intoCart( $post_id, $sku, $force = false, $value = null, $options = null, $out = '' ) {
698 1360 global $usces;
699 - if( empty($value) )
700 - $value = __('Add To Cart', 'usces');
701 - $skus = $usces->get_skus( $post_id, 'code' );
702 - $zaikonum = $skus[$sku]['stocknum'];
703 - $zaiko = $skus[$sku]['stock'];
704 - $gptekiyo = $skus[$sku]['gp'];
705 - $skuPrice = $skus[$sku]['price'];
706 - $enc_sku = urlencode($sku);
707 1361
708 - $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\" name=\"" . $post_id."-". $enc_sku . "\">\n";
709 - $html .= "<input name=\"zaikonum[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$enc_sku}]\" value=\"{$zaikonum}\" />\n";
710 - $html .= "<input name=\"zaiko[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$enc_sku}]\" value=\"{$zaiko}\" />\n";
711 - $html .= "<input name=\"gptekiyo[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$enc_sku}]\" value=\"{$gptekiyo}\" />\n";
712 - $html .= "<input name=\"skuPrice[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$enc_sku}]\" value=\"{$skuPrice}\" />\n";
713 - $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$enc_sku}]\" type=\"submit\" id=\"inCart[{$post_id}][{$enc_sku}]\" class=\"skubutton\" value=\"{$value}\" " . apply_filters('usces_filter_direct_intocart_button', NULL, $post_id, $sku, $force, $options) . " />";
714 - $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . $_SERVER['REQUEST_URI'] . "\" />\n";
715 - if( $force )
1362 + if ( empty( $value ) ) {
1363 + $value = __( 'Add To Cart', 'usces' );
1364 + }
1365 + $skus = wel_get_skus( $post_id, 'code' );
1366 +
1367 + $zaikonum = $skus[ $sku ]['stocknum'];
1368 + $zaiko = $skus[ $sku ]['stock'];
1369 + $gptekiyo = $skus[ $sku ]['gp'];
1370 + $skuprice = $skus[ $sku ]['price'];
1371 + $enc_sku = urlencode( $sku );
1372 +
1373 + $usces->itemopts = wel_get_opts( $post_id, 'sort' );
1374 + $usces->current_itemopt = -1;
1375 +
1376 + $usces->itemsku = $skus[ $sku ];
1377 +
1378 + $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\" name=\"" . $post_id . '-' . $enc_sku . "\">\n";
1379 + $html .= "<input name=\"zaikonum[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $zaikonum ) . "\" />\n";
1380 + $html .= "<input name=\"zaiko[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $zaiko ) . "\" />\n";
1381 + $html .= "<input name=\"gptekiyo[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $gptekiyo ) . "\" />\n";
1382 + $html .= "<input name=\"skuPrice[{$post_id}][{$enc_sku}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$enc_sku}]\" value=\"" . esc_attr( $skuprice ) . "\" />\n";
1383 +
1384 + if ( $options && usces_is_options() ) {
1385 + while ( usces_have_options() ) {
1386 + $html .= '<div class="itemopt_row">' . usces_get_itemopt_filed( $post_id, $sku, $usces->itemopt ) . "</div>\n";
1387 + }
1388 + }
1389 +
1390 + $html .= "<a name=\"cart_button\"></a><input name=\"inCart[{$post_id}][{$enc_sku}]\" type=\"submit\" id=\"inCart[{$post_id}][{$enc_sku}]\" class=\"skubutton\" value=\"" . esc_attr( $value ) . "\" " . apply_filters( 'usces_filter_direct_intocart_button', null, $post_id, $sku, $force, $options ) . ' />';
1391 + $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
1392 + if ( $force ) {
716 1393 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
717 - $html = apply_filters('usces_filter_single_item_inform', $html);
718 - $html .= "</form>";
719 - $html .= '<div class="direct_error_message">' . usces_singleitem_error_message($post_id, $sku, 'return') . '</div>'."\n";
1394 + }
1395 + $html = apply_filters( 'usces_filter_single_item_inform', $html );
720 1396
721 - if( $out == 'return' ){
1397 + $html .= '</form>';
1398 + $html .= '<div class="direct_error_message">' . usces_singleitem_error_message( $post_id, $sku, 'return' ) . '</div>' . "\n";
1399 +
1400 + if ( 'return' === $out ) {
722 1401 return $html;
723 - }else{
724 - echo $html;
1402 + } else {
1403 + echo $html; // no escape due to filter.
725 1404 }
726 1405 }
727 1406
728 -
729 -function usces_the_itemImage($number = 0, $width = 60, $height = 60, $post = '', $out = '', $media = 'item' ) {
1407 +/**
1408 + * Product Image
1409 + *
1410 + * @param int $number Image number.
1411 + * @param int $width Width.
1412 + * @param int $height Height.
1413 + * @param object $post Post data.
1414 + * @param string $out Return value or echo.
1415 + * @param string $media Media.
1416 + * @return string|void
1417 + */
1418 +function usces_the_itemImage( $number = 0, $width = 60, $height = 60, $post = '', $out = '', $media = 'item' ) {
730 1419 global $usces;
731 - $ptitle = $number;
732 - if($post == '') global $post;
733 1420
1421 + if ( '' === $post ) {
1422 + global $post;
1423 + }
734 1424 $post_id = $post->ID;
735 -
736 - if( $ptitle && 0 == (int)$number ){
737 1425
738 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
739 - $pictid = empty($picposts) ? 0 : $picposts[0]->ID;
740 - $html = wp_get_attachment_image( $pictid, array($width, $height), false );
741 - if( 'item' == $media ){
742 - $alt = 'alt="'.esc_attr($code[0]).'"';
743 - $alt = apply_filters('usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height);
744 - $html = preg_replace('/alt=\"[^\"]*\"/', $alt, $html);
745 - $title = 'title="'.esc_attr($name[0]).'"';
746 - $title = apply_filters('usces_filter_img_title', $title, $post_id, $pictid, $width, $height);
747 - $html = preg_replace('/title=\"[^\"]+\"/', $title, $html);
748 - $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height);
1426 + $ptitle = '';
1427 + if ( is_string( $number ) ) {
1428 + $ptitle = $number;
1429 + }
1430 + if ( $ptitle ) {
1431 +
1432 + $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1433 + $pictid = ( $picposts->have_posts() ) ? $picposts[0]->ID : 0;
1434 + $html = wp_get_attachment_image( $pictid, array( $width, $height ), false );
1435 + if ( 'item' === $media ) {
1436 + $product = wel_get_product( $post_id );
1437 + $code = $product['itemCode'];
1438 + if ( ! $code ) {
1439 + return false;
1440 + }
1441 + $name = $product['itemName'];
1442 +
1443 + $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1444 + if ( empty( $alt ) ) {
1445 + $alt = $code;
1446 + }
1447 + $alt = 'alt="' . esc_attr( $alt ) . '"';
1448 + $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1449 +
1450 + $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1451 +
1452 + $title = 'title="' . esc_attr( $name ) . '"';
1453 + $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1454 +
1455 + $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1456 + $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height );
749 1457 }
750 1458
751 - }else{
1459 + } else {
752 1460
753 -
754 - $code = get_post_meta($post_id, '_itemCode', true);
755 - if(!$code) return false;
756 -
757 - $name = get_post_meta($post_id, '_itemName', true);
758 -
759 - if( 0 == $number ){
760 - $pictid = (int)$usces->get_mainpictid($code);
761 - $html = wp_get_attachment_image( $pictid, array($width, $height), true );//'<img src="#" height="60" width="60" alt="" />';
762 - if( 'item' == $media ){
763 - $alt = 'alt="'.esc_attr($code).'"';
764 - $alt = apply_filters('usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height);
765 - $html = preg_replace('/alt=\"[^\"]*\"/', $alt, $html);
766 - $title = 'title="'.esc_attr($name).'"';
767 - $title = apply_filters('usces_filter_img_title', $title, $post_id, $pictid, $width, $height);
768 - $html = preg_replace('/title=\"[^\"]+\"/', $title, $html);
769 - $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height);
1461 + $product = wel_get_product( $post_id );
1462 + $code = $product['itemCode'];
1463 + if ( ! $code ) {
1464 + return false;
1465 + }
1466 + $name = $product['itemName'];
1467 +
1468 + if ( 0 === (int) $number ) {
1469 +
1470 + $pictid = (int) $usces->get_mainpictid( $code );
1471 + $html = wp_get_attachment_image( $pictid, array( $width, $height ), true );/* '<img src="#" height="60" width="60" alt="" />'; */
1472 + if ( 'item' === $media ) {
1473 + $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1474 + if ( empty( $alt ) ) {
1475 + $alt = $code;
1476 + }
1477 + $alt = 'alt="' . esc_attr( $alt ) . '"';
1478 + $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1479 +
1480 + $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1481 +
1482 + $title = 'title="' . esc_attr( $name ) . '"';
1483 + $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1484 +
1485 + $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1486 + $html = apply_filters( 'usces_filter_main_img', $html, $post_id, $pictid, $width, $height );
770 1487 }
771 - }else{
772 - $pictids = $usces->get_pictids($code);
773 - $ind = $number - 1;
774 - $pictid = ( isset($pictids[$ind]) && (int)$pictids[$ind] ) ? $pictids[$ind] : 0;
775 - $html = wp_get_attachment_image( $pictid, array($width, $height), false );//'<img src="#" height="60" width="60" alt="" />';
776 - if( 'item' == $media ){
777 - $alt = 'alt="'.esc_attr($code).'"';
778 - $alt = apply_filters('usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height);
779 - $html = preg_replace('/alt=\"[^\"]*\"/', $alt, $html);
780 - $title = 'title="'.esc_attr($name).'"';
781 - $title = apply_filters('usces_filter_img_title', $title, $post_id, $pictid, $width, $height);
782 - $html = preg_replace('/title=\"[^\"]+\"/', $title, $html);
783 - $html = apply_filters( 'usces_filter_sub_img', $html, $post_id, $pictid, $width, $height);
1488 +
1489 + } else {
1490 +
1491 + $pictids = $usces->get_pictids( $code );
1492 + $ind = $number - 1;
1493 + $pictid = ( isset( $pictids[ $ind ] ) && (int) $pictids[ $ind ] ) ? $pictids[ $ind ] : 0;
1494 + $html = wp_get_attachment_image( $pictid, array( $width, $height ), false );/* '<img src="#" height="60" width="60" alt="" />'; */
1495 + if ( 'item' === $media ) {
1496 + $alt = trim( strip_tags( get_post_meta( $pictid, '_wp_attachment_image_alt', true ) ) );
1497 + if ( empty( $alt ) ) {
1498 + $alt = $code;
1499 + }
1500 + $alt = 'alt="' . esc_attr( $alt ) . '"';
1501 + $alt = apply_filters( 'usces_filter_img_alt', $alt, $post_id, $pictid, $width, $height );
1502 +
1503 + $html = preg_replace( '/alt=\"[^\"]*\"/', $alt, $html );
1504 +
1505 + $title = 'title="' . esc_attr( $name ) . '"';
1506 + $title = apply_filters( 'usces_filter_img_title', $title, $post_id, $pictid, $width, $height );
1507 +
1508 + $html = preg_replace( '/title=\"[^\"]+\"/', $title, $html );
1509 + $html = apply_filters( 'usces_filter_sub_img', $html, $post_id, $pictid, $width, $height );
784 1510 }
785 1511 }
786 1512 }
787 -
788 - if($out == 'return'){
789 - return $html;
790 - }else{
791 - echo $html;
1513 +
1514 + if ( 'return' === $out ) {
1515 + return wel_esc_script( $html );
1516 + } else {
1517 + wel_esc_script_e( $html );
792 1518 }
793 1519 }
794 1520
795 -function usces_the_itemImageURL($number = 0, $out = '', $post = '' ) {
1521 +/**
1522 + * Product Image URL
1523 + *
1524 + * @param int $number Image number.
1525 + * @param string $out Return value or echo.
1526 + * @param object $post Post data.
1527 + * @return string|void
1528 + */
1529 +function usces_the_itemImageURL( $number = 0, $out = '', $post = '' ) {
796 1530 global $usces;
1531 +
797 1532 $ptitle = $number;
798 -
799 - if( $ptitle && is_string($number) ){
800 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
801 - $pictid = empty($picposts) ? 0 : $picposts[0]->ID;
802 - $pictid = $picposts[0]->ID;
803 - $html = wp_get_attachment_url( $pictid );
804 - }else{
805 -
806 - if($post == '') global $post;
1533 + if ( $ptitle && is_string( $number ) ) {
1534 +
1535 + $picposts = new WP_Query( array( 'post_type' => 'attachment', 'name' => $ptitle ) );
1536 + $pictid = ( $picposts->have_posts() ) ? $picposts[0]->ID : 0;
1537 + $html = wp_get_attachment_url( $pictid );
1538 +
1539 + } else {
1540 +
1541 + if ( '' === $post ) {
1542 + global $post;
1543 + }
807 1544 $post_id = $post->ID;
808 -
809 - $code = get_post_meta($post_id, '_itemCode', true);
810 - if(!$code) return false;
811 - $name = get_post_meta($post_id, '_itemName', true);
812 - if( 0 == $number ){
813 - $pictid = (int)$usces->get_mainpictid($code);
814 - $html = wp_get_attachment_url( $pictid );
815 - }else{
816 - $pictids = $usces->get_pictids($code);
817 - $ind = $number - 1;
818 - $pictid = ( isset($pictids[$ind]) && (int)$pictids[$ind] ) ? $pictids[$ind] : 0;
819 - $html = wp_get_attachment_url( $pictid );
1545 + $product = wel_get_product( $post_id );
1546 + $code = $product['itemCode'];
1547 + if ( ! $code ) {
1548 + return false;
820 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 + }
821 1560 }
822 -
823 - if($out == 'return'){
824 - return $html;
825 - }else{
826 - echo $html;
1561 +
1562 + if ( 'return' === $out ) {
1563 + return wel_esc_script( $html );
1564 + } else {
1565 + wel_esc_script_e( $html );
827 1566 }
828 1567 }
829 1568
830 -function usces_the_itemImageCaption($number = 0, $post = '', $out = '' ) {
1569 +/**
1570 + * Product Image caption
1571 + *
1572 + * @param int $number Image number.
1573 + * @param object $post Post data.
1574 + * @param string $out Return value or echo.
1575 + * @return string|void
1576 + */
1577 +function usces_the_itemImageCaption( $number = 0, $post = '', $out = '' ) {
831 1578 global $usces;
1579 +
832 1580 $ptitle = $number;
833 -
834 - if( $ptitle && 0 == (int)$number ){
835 -
836 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
837 - $excerpt = empty($picposts) ? '' : $picposts[0]->post_excerpt;
838 -
839 - }else{
840 -
841 - if($post == '') global $post;
842 -
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 + }
843 1591 $post_id = $post->ID;
844 -
845 - $code = get_post_meta($post_id, '_itemCode', true);
846 - if(!$code) return false;
847 -
848 - $name = get_post_meta($post_id, '_itemName', true);
849 -
850 - if( 0 == $number ){
851 - $pictid = $usces->get_mainpictid($code);
852 - $attach_ob = get_post($pictid);
853 - }else{
854 - $pictids = $usces->get_pictids($code);
855 - $ind = $number - 1;
856 - $attach_ob = get_post($pictids[$ind]);
1592 + $product = wel_get_product( $post_id );
1593 +
1594 + $code = $product['itemCode'];
1595 + if ( ! $code ) {
1596 + return false;
857 1597 }
858 - $excerpt = $attach_ob->post_excerpt;
1598 + $name = $product['itemName'];
1599 +
1600 + if ( 0 === (int) $number ) {
1601 + $pictid = $usces->get_mainpictid( $code );
1602 + if ( $pictid ) {
1603 + $attach_ob = get_post( $pictid );
1604 + $excerpt = ( isset( $attach_ob->post_excerpt ) ) ? $attach_ob->post_excerpt : '';
1605 + } else {
1606 + $excerpt = '';
1607 + }
1608 + } else {
1609 + $pictids = $usces->get_pictids( $code );
1610 + $ind = $number - 1;
1611 + if ( isset( $pictids[ $ind ] ) ) {
1612 + $attach_ob = get_post( $pictids[ $ind ] );
1613 + $excerpt = ( isset( $attach_ob->post_excerpt ) ) ? $attach_ob->post_excerpt : '';
1614 + } else {
1615 + $excerpt = '';
1616 + }
1617 + }
859 1618 }
860 1619
861 - if($out == 'return'){
1620 + if ( 'return' === $out ) {
862 1621 return $excerpt;
863 - }else{
864 - echo esc_html($excerpt);
1622 + } else {
1623 + echo esc_html( $excerpt );
865 1624 }
866 1625 }
867 1626
868 -function usces_the_itemImageDescription($number = 0, $post = '', $out = '' ) {
1627 +/**
1628 + * Product Image description
1629 + *
1630 + * @param int $number Image number.
1631 + * @param object $post Post data.
1632 + * @param string $out Return value or echo.
1633 + * @return string|void
1634 + */
1635 +function usces_the_itemImageDescription( $number = 0, $post = '', $out = '' ) {
869 1636 global $usces;
1637 +
870 1638 $ptitle = $number;
871 -
872 - if( $ptitle && 0 == (int)$number ){
873 -
874 - $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
875 - $excerpt = empty($picposts) ? '' : $picposts[0]->post_content;
876 -
877 - }else{
1639 + if ( $ptitle && 0 === (int) $number ) {
878 1640
879 - if($post == '') global $post;
880 -
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 + }
881 1649 $post_id = $post->ID;
882 -
883 - $code = get_post_meta($post_id, '_itemCode', true);
884 - if(!$code) return false;
885 -
886 - $name = get_post_meta($post_id, '_itemName', true);
887 -
888 - if( 0 == $number ){
889 - $pictid = $usces->get_mainpictid($code);
890 - $attach_ob = get_post($pictid);
891 - }else{
892 - $pictids = $usces->get_pictids($code);
893 - $ind = $number - 1;
894 - $attach_ob = get_post($pictids[$ind]);
1650 + $product = wel_get_product( $post_id );
1651 +
1652 + $code = $product['itemCode'];
1653 + if ( ! $code ) {
1654 + return false;
895 1655 }
896 - $excerpt = $attach_ob->post_content;
1656 + $name = $product['itemName'];
1657 +
1658 + if ( 0 === (int) $number ) {
1659 + $pictid = $usces->get_mainpictid( $code );
1660 + if ( $pictid ) {
1661 + $attach_ob = get_post( $pictid );
1662 + $description = ( isset( $attach_ob->post_content ) ) ? $attach_ob->post_content : '';
1663 + } else {
1664 + $description = '';
1665 + }
1666 + } else {
1667 + $pictids = $usces->get_pictids( $code );
1668 + $ind = $number - 1;
1669 + if ( isset( $pictids[ $ind ] ) ) {
1670 + $attach_ob = get_post( $pictids[ $ind ] );
1671 + $description = ( isset( $attach_ob->post_content ) ) ? $attach_ob->post_content : '';
1672 + } else {
1673 + $description = '';
1674 + }
1675 + }
897 1676 }
898 1677
899 - if($out == 'return'){
900 - return $excerpt;
901 - }else{
902 - echo esc_html($excerpt);
1678 + if ( 'return' === $out ) {
1679 + return $description;
1680 + } else {
1681 + echo esc_html( $description );
903 1682 }
904 1683 }
905 1684
1685 +/**
1686 + * Product sub image
1687 + *
1688 + * @return array
1689 + */
906 1690 function usces_get_itemSubImageNums() {
907 1691 global $post, $usces;
1692 +
908 1693 $post_id = $post->ID;
909 - $res = array();
910 -
911 - $code = get_post_meta($post_id, '_itemCode', true);
912 - if(!$code) return false;
913 - $name = get_post_meta($post_id, '_itemName', true);
914 - $pictids = $usces->get_pictids($code);
915 - for($i=1; $i<=count($pictids); $i++){
1694 + $res = array();
1695 +
1696 + $product = wel_get_product( $post_id );
1697 + $code = $product['itemCode'];
1698 + if ( ! $code ) {
1699 + return false;
1700 + }
1701 + $name = $product['itemName'];
1702 +
1703 + $pictids = $usces->get_pictids( $code );
1704 + $pictids_count = ( $pictids && is_array( $pictids ) ) ? count( $pictids ) : 0;
1705 + for ( $i = 1; $i <= $pictids_count; $i++ ) {
916 1706 $res[] = $i;
917 1707 }
918 - return $res;
1708 + return $res;
919 1709 }
920 1710
1711 +/**
1712 + * Is item option
1713 + *
1714 + * @return bool
1715 + */
921 1716 function usces_is_options() {
922 1717 global $usces;
923 -
924 - if( 0 < count($usces->itemopts) ){
925 - reset($usces->itemopts);
926 - $usces->itemopt = array();
1718 +
1719 + if ( ! empty( $usces->itemopts ) && is_array( $usces->itemopts ) && 0 < count( $usces->itemopts ) ) {
1720 + reset( $usces->itemopts );
1721 + $usces->itemopt = array();
1722 + $usces->current_itemopt = -1;
927 1723 return true;
928 - }else{
1724 + } else {
929 1725 return false;
930 1726 }
931 1727 }
932 1728
1729 +/**
1730 + * Have item option
1731 + *
1732 + * @return bool
1733 + */
933 1734 function usces_have_options() {
934 1735 global $usces;
935 -
936 - $res_each = each($usces->itemopts);
937 - $usces->itemopt = $res_each['value'];
938 - if($usces->itemopt) {
1736 +
1737 + if ( null === $usces->current_itemopt ) {
1738 + $usces->current_itemopt = -1;
1739 + }
1740 +
1741 + if ( ! empty( $usces->itemopts ) && is_array( $usces->itemopts ) && ( $usces->current_itemopt + 1 < count( $usces->itemopts ) ) ) {
1742 + $usces->current_itemopt++;
1743 + $usces->itemopt = ( isset( $usces->itemopts[ $usces->current_itemopt ] ) ) ? $usces->itemopts[ $usces->current_itemopt ] : array();
939 1744 return true;
940 1745 } else {
941 1746 return false;
942 1747 }
@@ -941,786 +1746,1133 @@
941 1746 return false;
942 1747 }
943 1748 }
944 1749
1750 +/**
1751 + * Item option name
1752 + *
1753 + * @return string
1754 + */
945 1755 function usces_getItemOptName() {
946 1756 global $usces;
947 1757 return $usces->itemopt['name'];
948 1758 }
949 1759
950 -function usces_the_itemOptName($out = '') {
1760 +/**
1761 + * Item option name
1762 + *
1763 + * @param string $out Return value or echo.
1764 + * @return string|void
1765 + */
1766 +function usces_the_itemOptName( $out = '' ) {
951 1767 global $usces;
952 1768
953 - if($out == 'return'){
1769 + if ( 'return' === $out ) {
954 1770 return $usces->itemopt['name'];
955 - }else{
956 - echo esc_html($usces->itemopt['name']);
1771 + } else {
1772 + echo esc_html( $usces->itemopt['name'] );
957 1773 }
958 1774 }
959 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 + */
960 1784 function usces_the_itemOption( $name, $label = '#default#', $out = '' ) {
961 1785 global $post, $usces;
962 1786 $post_id = $post->ID;
963 -
964 - if($label == '#default#')
1787 +
1788 + if ( '#default#' === $label ) {
965 1789 $label = $name;
1790 + }
966 1791
967 - $opts = usces_get_opts($post_id, 'name');
968 - if(!$opts)
1792 + $opts = wel_get_opts( $post_id, 'name' );
1793 + if ( ! $opts || ! isset( $opts[ $name ] ) ) {
969 1794 return false;
970 -
971 - $opt = $opts[$name];
972 - $means = (int)$opt['means'];
973 - $essential = (int)$opt['essential'];
1795 + }
974 1796
975 - $html = '';
976 - $sku = esc_attr(urlencode($usces->itemsku['code']));
977 - $optcode = esc_attr(urlencode($name));
978 - $name = esc_attr($name);
979 - $label = esc_attr($label);
980 - $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] ) ? $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] : NULL;
981 -//20110715ysk start 0000208
1797 + $opt = $opts[ $name ];
1798 + $opt['value'] = usces_change_line_break( $opt['value'] );
1799 + $means = (int) $opt['means'];
1800 + $essential = (int) $opt['essential'];
1801 +
1802 + $sku = esc_attr( urlencode( $usces->itemsku['code'] ) );
1803 + $optcode = esc_attr( urlencode( $name ) );
1804 + $name = esc_attr( $name );
1805 + $label = esc_attr( $label );
1806 +
1807 + $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] ) ? $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] : null;
1808 +
1809 + $html = '';
982 1810 $html .= "\n<label for='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_label'>{$label}</label>\n";
983 -//20110715ysk end
984 -//20100914ysk start
985 - //if($means < 2){
986 - switch($means) {
987 - case 0://Single-select
988 - case 1://Multi-select
989 -//20100914ysk end
990 - $selects = explode("\n", $opt['value']);
991 - $multiple = ($means === 0) ? '' : ' multiple';
992 - $multiple_array = ($means == 0) ? '' : '[]';//20110629ysk 0000190
993 - //$html .= "\n<label for='itemOption[{$post_id}][{$sku}][{$name}]' class='iopt_label'>{$label}</label>\n";
994 -//20110629ysk start 0000190
995 - //$html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$name}]' id='itemOption[{$post_id}][{$sku}][{$name}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
996 - $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";
997 -//20110629ysk end
998 - if($essential == 1){
999 - if( '#NONE#' == $session_value || NULL == $session_value )
1000 - $selected = ' selected="selected"';
1001 - else
1002 - $selected = '';
1003 - $html .= "\t<option value='#NONE#'{$selected}>" . __('Choose','usces') . "</option>\n";
1004 - }
1005 - $i=0;
1006 - foreach($selects as $v) {
1007 - $v = trim($v);
1008 - if( ($i == 0 && $essential == 0 && NULL == $session_value) || esc_attr($v) == $session_value )
1009 - $selected = ' selected="selected"';
1010 - else
1011 - $selected = '';
1012 - $html .= "\t<option value='" . esc_attr($v) . "'{$selected}>" . esc_attr($v) . "</option>\n";
1013 - $i++;
1014 - }
1015 - $html .= "</select>\n";
1016 -//20100914ysk start
1017 - //}else{
1018 - break;
1019 - case 2://Text
1020 -//20100914ysk end
1021 - $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";
1022 -//20100914ysk start
1023 - break;
1024 - case 5://Text-area
1025 - $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr($session_value) . "</textarea>\n";
1026 - break;
1027 -//20100914ysk end
1811 +
1812 + switch ( $means ) {
1813 + case 0: // Single-select.
1814 + case 1: // Multi-select.
1815 + $selects = explode( "\n", $opt['value'] );
1816 + $multiple = ( 0 === $means ) ? '' : ' multiple';
1817 + $multiple_array = ( 0 === $means ) ? '' : '[]';
1818 +
1819 + $html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$optcode}]{$multiple_array}' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
1820 + if ( 1 === $essential ) {
1821 + if ( 0 === $means && ( '#NONE#' === $session_value || null === $session_value ) ) {
1822 + $selected = ' selected="selected"';
1823 + } else {
1824 + $selected = '';
1825 + }
1826 + $html .= "\t<option value='#NONE#'{$selected}>" . __( 'Choose', 'usces' ) . "</option>\n";
1827 + }
1828 + $i = 0;
1829 + foreach ( (array) $selects as $v ) {
1830 + $v = trim( $v );
1831 + if ( ( 0 === $i && 0 === $essential && null === $session_value ) || esc_attr( $v ) === $session_value ) {
1832 + $selected = ' selected="selected"';
1833 + } else {
1834 + $selected = '';
1835 + }
1836 + $html .= "\t<option value='" . esc_attr( $v ) . "'{$selected}>" . esc_attr( $v ) . "</option>\n";
1837 + $i++;
1838 + }
1839 + $html .= "</select>\n";
1840 + break;
1841 + case 2: // Text.
1842 + $html .= "\n<input name='itemOption[{$post_id}][{$sku}][{$optcode}]' type='text' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"" . esc_attr( $session_value ) . "\" />\n";
1843 + break;
1844 + case 3: // Radio-button.
1845 + $selects = explode( "\n", $opt['value'] );
1846 + $i = 0;
1847 + foreach ( (array) $selects as $v ) {
1848 + $v = trim( $v );
1849 + if ( $v === $session_value ) {
1850 + $checked = ' checked="checked"';
1851 + } else {
1852 + $checked = '';
1853 + }
1854 + $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio' type='radio' value='" . urlencode( $v ) . "'{$checked}>" . esc_html( $v ) . "</label>\n";
1855 + $i++;
1856 + }
1857 + break;
1858 + case 4: // Check-box.
1859 + $selects = explode( "\n", $opt['value'] );
1860 + $i = 0;
1861 + foreach ( (array) $selects as $v ) {
1862 + $v = trim( $v );
1863 + if ( $v === $session_value ) {
1864 + $checked = ' checked="checked"';
1865 + } else {
1866 + $checked = '';
1867 + }
1868 + $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}][]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox' type='checkbox' value='" . urlencode( $v ) . "'{$checked}>" . esc_html( $v ) . "</label><br />\n";
1869 + $i++;
1870 + }
1871 + break;
1872 + case 5: // Text-area.
1873 + $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr( $session_value ) . "</textarea>\n";
1874 + break;
1028 1875 }
1029 -
1030 - $html = apply_filters('usces_filter_the_itemOption', $html, $opts, $name, $label, $post_id, $usces->itemsku['code']);
1031 -
1032 - if( $out == 'return' ){
1876 +
1877 + $html = apply_filters( 'usces_filter_the_itemOption', $html, $opts, $name, $label, $post_id, $usces->itemsku['code'] );
1878 +
1879 + if ( 'return' === $out ) {
1033 1880 return $html;
1034 - }else{
1035 - echo $html;
1881 + } else {
1882 + echo $html; // no escape due to filter.
1036 1883 }
1037 1884 }
1038 1885
1886 +/**
1887 + * Display cart
1888 + */
1039 1889 function usces_the_cart() {
1040 1890 global $usces;
1041 -
1042 1891 $usces->display_cart();
1043 -
1044 1892 }
1045 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 + */
1046 1918 function usces_is_cart() {
1047 1919 global $usces;
1048 -
1049 - if($usces->cart->num_row() > 0)
1050 - if( apply_filters('usces_is_cart_check', true) ) {
1920 +
1921 + if ( 0 < $usces->cart->num_row() ) {
1922 + if ( apply_filters( 'usces_is_cart_check', true ) ) {
1051 1923 return true;
1052 - }else{
1924 + } else {
1053 1925 return false;
1054 1926 }
1055 - else
1927 + } else {
1056 1928 return false;
1057 -
1929 + }
1058 1930 }
1059 1931
1932 +/**
1933 + * Is category
1934 + *
1935 + * @param string $str categpry slug.
1936 + * @return bool
1937 + */
1060 1938 function usces_is_category( $str ) {
1061 - global $post;
1062 1939
1063 - //if( $post->post_type != 'post' ) return false;
1064 -
1065 - $cat = get_the_category();
1940 + $cat = get_the_category();
1066 1941 $slugs = array();
1067 - foreach($cat as $value){
1942 + foreach ( $cat as $value ) {
1068 1943 $slugs[] = $value->slug;
1069 1944 }
1070 -
1071 - $str = utf8_uri_encode($str);
1072 -
1073 - if( in_array( $str, $slugs) )
1945 +
1946 + $str = utf8_uri_encode( $str );
1947 +
1948 + if ( in_array( $str, $slugs, true ) ) {
1074 1949 return true;
1075 - else
1950 + } else {
1076 1951 return false;
1952 + }
1077 1953 }
1078 1954
1079 -function usces_the_pref( $flag, $out = '' ){
1955 +/**
1956 + * Pref field
1957 + *
1958 + * @param string $flag Member or not.
1959 + * @param string $out Return value or echo.
1960 + * @return string|void
1961 + */
1962 +function usces_the_pref( $flag, $out = '' ) {
1080 1963 global $usces;
1081 -
1082 - $usces_members = $usces->get_member();
1964 +
1083 1965 $usces_entries = $usces->cart->get_entry();
1084 - $name = esc_attr($flag) . '[pref]';
1085 - $pref = $usces_entries[$flag]['pref'];
1086 - if( 'member' == $flag)
1087 - $pref = $usces_members['pref'];
1088 -
1089 - $html = "<select name='" . esc_attr($name) . "' id='pref' class='pref'>\n";
1090 -// $prefs = get_option('usces_pref');
1091 -//20110331ysk start
1092 - //$prefs = $usces->options['province'];
1093 - $prefs = get_usces_states(usces_get_local_addressform());
1094 -//20110331ysk end
1095 - foreach($prefs as $value) {
1096 - $selected = ($pref == $value) ? ' selected="selected"' : '';
1097 - $html .= "\t<option value='" . esc_attr($value) . "'{$selected}>" . esc_html($value) . "</option>\n";
1966 + $name = esc_attr( $flag ) . '[pref]';
1967 + $pref = $usces_entries[ $flag ]['pref'];
1968 + if ( 'member' === $flag ) {
1969 + $usces_members = $usces->get_member();
1970 + $pref = $usces_members['pref'];
1098 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 + }
1099 1978 $html .= "</select>\n";
1100 -
1101 - if( $out == 'return' ){
1102 - return $html;
1103 - }else{
1104 - echo $html;
1979 +
1980 + if ( 'return' === $out ) {
1981 + return wel_esc_script( $html );
1982 + } else {
1983 + wel_esc_script_e( $html );
1105 1984 }
1106 1985 }
1107 1986
1108 -function usces_the_company_name(){
1987 +/**
1988 + * Company name
1989 + */
1990 +function usces_the_company_name() {
1109 1991 global $usces;
1110 - echo esc_html($usces->options['company_name']);
1992 + echo esc_html( $usces->options['company_name'] );
1111 1993 }
1112 1994
1113 -function usces_the_zip_code(){
1995 +/**
1996 + * Zip code
1997 + */
1998 +function usces_the_zip_code() {
1114 1999 global $usces;
1115 - echo esc_html($usces->options['zip_code']);
2000 + echo esc_html( $usces->options['zip_code'] );
1116 2001 }
1117 2002
1118 -function usces_the_address1(){
2003 +/**
2004 + * Address1
2005 + */
2006 +function usces_the_address1() {
1119 2007 global $usces;
1120 - echo esc_html($usces->options['address1']);
2008 + echo esc_html( $usces->options['address1'] );
1121 2009 }
1122 2010
1123 -function usces_the_address2(){
2011 +/**
2012 + * Address2
2013 + */
2014 +function usces_the_address2() {
1124 2015 global $usces;
1125 - echo esc_html($usces->options['address2']);
2016 + echo esc_html( $usces->options['address2'] );
1126 2017 }
1127 2018
1128 -function usces_the_tel_number(){
2019 +/**
2020 + * Tel number
2021 + */
2022 +function usces_the_tel_number() {
1129 2023 global $usces;
1130 - echo esc_html($usces->options['tel_number']);
2024 + echo esc_html( $usces->options['tel_number'] );
1131 2025 }
1132 2026
1133 -function usces_the_fax_number(){
2027 +/**
2028 + * Fax number
2029 + */
2030 +function usces_the_fax_number() {
1134 2031 global $usces;
1135 - echo esc_html($usces->options['fax_number']);
2032 + echo esc_html( $usces->options['fax_number'] );
1136 2033 }
1137 2034
1138 -function usces_the_inquiry_mail(){
2035 +/**
2036 + * Inquiry email address
2037 + */
2038 +function usces_the_inquiry_mail() {
1139 2039 global $usces;
1140 - echo esc_html($usces->options['inquiry_mail']);
2040 + echo esc_html( $usces->options['inquiry_mail'] );
1141 2041 }
1142 2042
1143 -function usces_the_postage_privilege(){
2043 +/**
2044 + * Postage privilege
2045 + */
2046 +function usces_the_postage_privilege() {
1144 2047 global $usces;
1145 - echo esc_html($usces->options['postage_privilege']);
2048 + echo esc_html( $usces->options['postage_privilege'] );
1146 2049 }
1147 2050
1148 -function usces_the_start_point(){
2051 +/**
2052 + * Initial point
2053 + */
2054 +function usces_the_start_point() {
1149 2055 global $usces;
1150 - echo esc_html($usces->options['start_point']);
2056 + echo esc_html( $usces->options['start_point'] );
1151 2057 }
1152 2058
1153 -function usces_point_rate( $post_id = NULL, $out = '' ){
2059 +/**
2060 + * Point rate
2061 + *
2062 + * @param int $post_id Post ID.
2063 + * @param string $out Return value or echo.
2064 + * @return string|void
2065 + */
2066 +function usces_point_rate( $post_id = null, $out = '' ) {
1154 2067 global $usces;
1155 - if( $post_id == NULL ){
2068 +
2069 + if ( null === $post_id ) {
1156 2070 $rate = $usces->options['point_rate'];
1157 - }else{
1158 - $str = get_post_meta($post_id, '_itemPointrate', true);
1159 - $rate = (int)$str;
2071 + } else {
2072 + $product = wel_get_product( $post_id );
2073 + $str = $product['itemPointrate'];
2074 + $rate = (int) $str;
1160 2075 }
1161 - if( $out == 'return' ){
1162 - return $rate;
1163 - }else{
1164 - echo $rate;
2076 + if ( 'return' === $out ) {
2077 + return wel_esc_script( $rate );
2078 + } else {
2079 + wel_esc_script_e( $rate );
1165 2080 }
1166 2081 }
1167 2082
1168 -function usces_point_rate_discount( $post_id = NULL, $out = '' ) {
2083 +/**
2084 + * Point discount
2085 + *
2086 + * @param int $post_id Post ID.
2087 + * @param string $out Return value or echo.
2088 + * @return string|void
2089 + */
2090 +function usces_point_rate_discount( $post_id = null, $out = '' ) {
1169 2091 global $post, $usces;
1170 - if( $post_id == NULL )
2092 +
2093 + if ( null === $post_id ) {
1171 2094 $post_id = $post->ID;
2095 + }
1172 2096
1173 - $str = get_post_meta( $post_id, '_itemPointrate', true );
1174 - $rate = (int)$str;
1175 - if( $usces->options['campaign_privilege'] == 'point' ) {
1176 - if( in_category((int)$usces->options['campaign_category'], $post_id) ) {
2097 + $product = wel_get_product( $post_id );
2098 + $str = $product['itemPointrate'];
2099 + $rate = (int) $str;
2100 + if ( 'point' === $usces->options['campaign_privilege'] ) {
2101 + if ( in_category( (int) $usces->options['campaign_category'], $post_id ) ) {
1177 2102 $rate *= $usces->options['privilege_point'];
1178 2103 }
1179 2104 }
1180 - if( $out == 'return' ) {
1181 - return $rate;
2105 + if ( 'return' === $out ) {
2106 + return wel_esc_script( $rate );
1182 2107 } else {
1183 - echo $rate;
2108 + wel_esc_script_e( $rate );
1184 2109 }
1185 2110 }
1186 2111
1187 -function usces_get_point( $post_id, $sku_code ){
2112 +/**
2113 + * Item point
2114 + *
2115 + * @param int $post_id Post ID.
2116 + * @param string $sku_code SKU code.
2117 + * @return int
2118 + */
2119 +function usces_get_point( $post_id, $sku_code ) {
1188 2120 global $usces;
1189 - if( $post_id == NULL ){
2121 +
2122 + if ( null === $post_id ) {
1190 2123 $rate = $usces->options['point_rate'];
1191 - }else{
1192 - $str = get_post_meta($post_id, '_itemPointrate', true);
1193 - $rate = (int)$str;
2124 + } else {
2125 + $product = wel_get_product( $post_id );
2126 + $str = $product['itemPointrate'];
2127 + $rate = (int) $str;
1194 2128 }
1195 -
1196 - $skus = $usces->get_skus($post_id, 'code');
1197 - $point = ceil($skus[$sku_code]['price'] * $rate / 100);
1198 -
2129 +
2130 + $skus = wel_get_skus( $post_id, 'code' );
2131 + $point = ceil( $skus[ $sku_code ]['price'] * $rate / 100 );
2132 +
1199 2133 return $point;
1200 2134 }
1201 2135
1202 -function usces_the_payment_method( $value = '', $out = '' ){
2136 +/**
2137 + * Payment method field
2138 + *
2139 + * @param string $value Value.
2140 + * @param string $out Return value or echo.
2141 + * @return string|void
2142 + */
2143 +function usces_the_payment_method( $value = '', $out = '' ) {
1203 2144 global $usces;
2145 +
1204 2146 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
1205 - $payments = apply_filters('usces_fiter_the_payment_method', $payments, $value);
1206 - //if( empty($payments) ) return; 20120328ysk 0000454
1207 -
1208 - $cart = $usces->cart->get_cart();
1209 - //$charging_type = $usces->getItemChargingType($cart[0]['post_id']);
1210 - $charging_type = $usces->getItemChargingType($cart[0]['post_id'], $cart);
1211 - $html = "<dl>\n";
1212 - $list = '';
1213 - $payment_ct = count($payments);
1214 -//20120328ysk start 0000454
1215 - //foreach ($payments as $id => $payment) {
1216 - foreach ((array)$payments as $id => $payment) {
1217 -//20120328ysk end
1218 - if( 'continue' == $charging_type ){
1219 - //if( 'acting' != substr($payments['settlement'], 0, 6) )
1220 -//20110412ysk start
1221 - //if( 'acting_remise_card' != $payment['settlement'] && 'acting_paypal_ec' != $payment['settlement']) {
1222 - $continue_payment_method = apply_filters( 'usces_filter_the_continue_payment_method', array( 'acting_remise_card', 'acting_paypal_ec' ) );
1223 - if( !in_array( $payment['settlement'], $continue_payment_method ) ) {
1224 - $payment_ct--;
1225 - continue;
2147 + $payments = apply_filters( 'usces_fiter_the_payment_method', $payments, $value );
2148 +
2149 + if ( defined( 'WCEX_DLSELLER_VERSION' ) && version_compare( WCEX_DLSELLER_VERSION, '2.2-beta', '<=' ) ) {
2150 + $cart = $usces->cart->get_cart();
2151 + $have_continue_charge = usces_have_continue_charge( $cart );
2152 + $continue_payment_method = apply_filters( 'usces_filter_the_continue_payment_method', array( 'acting_remise_card', 'acting_paypal_ec' ) );
2153 + }
2154 +
2155 + $list = '';
2156 + $payment_ct = ( $payments && is_array( $payments ) ) ? count( $payments ) : 0;
2157 + foreach ( (array) $payments as $id => $payment ) {
2158 + if ( defined( 'WCEX_DLSELLER_VERSION' ) && version_compare( WCEX_DLSELLER_VERSION, '2.2-beta', '<=' ) ) {
2159 + if ( $have_continue_charge ) {
2160 + if ( ! in_array( $payment['settlement'], $continue_payment_method, true ) ) {
2161 + $payment_ct--;
2162 + continue;
2163 + }
2164 + if ( isset( $usces->options['acting_settings']['remise']['continuation'] ) && 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' === $payment['settlement'] ) {
2165 + $payment_ct--;
2166 + continue;
2167 + } elseif ( isset( $usces->options['acting_settings']['paypal']['continuation'] ) && 'on' !== $usces->options['acting_settings']['paypal']['continuation'] && 'acting_paypal_ec' === $payment['settlement'] ) {
2168 + $payment_ct--;
2169 + continue;
2170 + }
1226 2171 }
1227 - //if( 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' == $payment['settlement'])
1228 - // continue;
1229 - if( 'on' !== $usces->options['acting_settings']['remise']['continuation'] && 'acting_remise_card' == $payment['settlement']) {
1230 - $payment_ct--;
1231 - continue;
1232 - } elseif( 'on' !== $usces->options['acting_settings']['paypal']['continuation'] && 'acting_paypal_ec' == $payment['settlement']) {
1233 - $payment_ct--;
1234 - continue;
1235 - }
1236 -//20110412ysk end
1237 2172 }
1238 - if( $payment['name'] != '' and $payment['use'] != 'deactivate' ) {
1239 - $module = trim($payment['module']);
1240 - if( !WCUtils::is_blank($value) ){
1241 - $checked = ($payment['name'] == $value) ? ' checked' : '';
1242 - }else if( 1 == $payment_ct ){//0000428
2173 + if ( '' !== $payment['name'] && 'deactivate' !== $payment['use'] ) {
2174 + $module = trim( $payment['module'] );
2175 + if ( ! WCUtils::is_blank( $value ) ) {
2176 + $checked = ( $payment['name'] === $value ) ? ' checked' : '';
2177 + } elseif ( 1 === $payment_ct ) {
1243 2178 $checked = ' checked';
1244 - }else{
2179 + } else {
1245 2180 $checked = '';
1246 2181 }
1247 - if( (empty($module) || !file_exists($usces->options['settlement_path'] . $module)) && $payment['settlement'] == 'acting' ) {
1248 - $checked = '';
1249 - $list .= "\t".'<dt class="payment_'.$id.'"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="'.esc_attr($payment['name']).'"' . $checked . ' disabled onKeyDown="if (event.keyCode == 13) {return false;}" />'.esc_attr($payment['name'])."</label> <b> (" . __('cannot use this payment method now.','usces') . ") </b></dt>\n";
1250 - }else{
1251 - $list .= "\t".'<dt class="payment_'.$id.'"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="'.esc_attr($payment['name']).'"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}" />'.esc_attr($payment['name'])."</label></dt>\n";
2182 + $payment_row = '';
2183 + $checked = apply_filters( 'usces_fiter_the_payment_method_checked', $checked, $payment, $value );
2184 + $explanation = apply_filters( 'usces_fiter_the_payment_method_explanation', $payment['explanation'], $payment, $value );
2185 + if ( ( empty( $module ) || ! file_exists( $usces->options['settlement_path'] . $module ) ) && 'acting' === $payment['settlement'] ) {
2186 + $checked = '';
2187 + $payment_row .= '<dt class="payment_' . $id . '"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="' . esc_attr( $payment['name'] ) . '"' . $checked . ' disabled onKeyDown="if (event.keyCode == 13) {return false;}" />' . esc_attr( $payment['name'] ) . '</label> <b>(' . __( 'cannot use this payment method now.', 'usces' ) . ')</b></dt>';
2188 + } else {
2189 + $payment_row .= '<dt class="payment_' . $id . '"><label for="payment_name_' . $id . '"><input name="offer[payment_name]" id="payment_name_' . $id . '" type="radio" value="' . esc_attr( $payment['name'] ) . '"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}" />' . esc_attr( $payment['name'] ) . '</label></dt>';
1252 2190 }
1253 - $list .= "\t".'<dd class="payment_'.$id.'">'.$payment['explanation'].'</dd>'."\n";
2191 + if ( ! empty( $explanation ) ) {
2192 + $explanation = wel_esc_script( $explanation );
2193 + $payment_row .= '<dd class="payment_' . $id . '">' . $explanation . '</dd>';
2194 + }
2195 + $payment_row = apply_filters( 'usces_filter_the_payment_method_row', $payment_row, $id, $payment, $checked, $module, $value, $explanation );
2196 + if ( ! empty( $payment_row ) ) {
2197 + $list .= $payment_row;
2198 + }
1254 2199 }
1255 2200 }
1256 2201
1257 - $html .= $list . "</dl>\n";
1258 -
1259 - if( empty($list) )
1260 - $html = __('Not yet ready for the payment method. Please refer to a manager.', 'usces')."\n";
1261 -
1262 - if( $out == 'return' ){
2202 + if ( ! empty( $list ) ) {
2203 + $html = '<dl>' . $list . '</dl>';
2204 + } else {
2205 + $html = '<div>' . __( 'Not yet ready for the payment method. Please refer to a manager.', 'usces' ) . '</div>';
2206 + }
2207 +
2208 + $html = apply_filters( 'usces_filter_the_payment_method_choices', $html, $payments );
2209 + if ( 'return' === $out ) {
1263 2210 return $html;
1264 - }else{
1265 - echo $html;
2211 + } else {
2212 + echo $html; // no escape due to filter.
1266 2213 }
1267 2214 }
1268 2215
1269 -function usces_get_payments_by_name( $name ){
1270 - global $usces;
2216 +/**
2217 + * Payment method
2218 + *
2219 + * @param string $name Payment method name.
2220 + * @return array
2221 + */
2222 +function usces_get_payments_by_name( $name ) {
2223 +
2224 + $init = array(
2225 + 'id' => null,
2226 + 'name' => null,
2227 + 'explanation' => null,
2228 + 'settlement' => null,
2229 + 'module' => null,
2230 + 'sort' => null,
2231 + 'use' => null,
2232 + );
1271 2233 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
1272 - if( empty($payments) ) return false;
1273 -
1274 - if( isset($payments[$name]) ) {
1275 - return $payments[$name];
2234 + if ( empty( $payments ) ) {
2235 + return $init;
1276 2236 }
2237 + if ( isset( $payments[ $name ] ) ) {
2238 + return $payments[ $name ];
2239 + }
1277 2240
1278 - return false;
2241 + return $init;
1279 2242 }
1280 2243
1281 -function usces_the_delivery_method( $value = '', $out = '' ){
2244 +/**
2245 + * Delivery method field
2246 + *
2247 + * @param string $value Value.
2248 + * @param string $out Return value or echo.
2249 + * @return string|void
2250 + */
2251 +function usces_the_delivery_method( $value = '', $out = '' ) {
1282 2252 global $usces;
1283 - $deli_id = apply_filters('usces_filter_get_available_delivery_method', $usces->get_available_delivery_method());
1284 - if( empty($deli_id) ){
1285 - $html = '<p>' . __('No valid shipping methods.', 'usces') . '</p>';
1286 - }else{
1287 - $cdeliid = count($deli_id);
1288 - $html = '<select name="offer[delivery_method]" id="delivery_method_select" class="delivery_time" onKeyDown="if (event.keyCode == 13) {return false;}">'."\n";
1289 - foreach ($deli_id as $id) {
1290 - $index = $usces->get_delivery_method_index($id);
1291 - $selected = ($id == $value || 1 === $cdeliid) ? ' selected="selected"' : '';
1292 - $html .= "\t<option value='{$id}'{$selected}>" . esc_html($usces->options['delivery_method'][$index]['name']) . "</option>\n";
2253 +
2254 + $deli_id = apply_filters( 'usces_filter_get_available_delivery_method', $usces->get_available_delivery_method() );
2255 + if ( empty( $deli_id ) ) {
2256 + $html = '<p>' . __( 'No valid shipping methods.', 'usces' ) . '</p>';
2257 + } else {
2258 + $cdeliid = ( is_array( $deli_id ) ) ? count( $deli_id ) : 0;
2259 + $html = '<select name="offer[delivery_method]" id="delivery_method_select" class="delivery_time" onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
2260 + foreach ( (array) $deli_id as $id ) {
2261 + $index = $usces->get_delivery_method_index( $id );
2262 + if ( 0 <= $index ) {
2263 + $selected = ( (string) $id === (string) $value || 1 === $cdeliid ) ? ' selected="selected"' : '';
2264 + $html .= "\t<option value=\"{$id}\"{$selected}>" . esc_html( $usces->options['delivery_method'][ $index ]['name'] ) . "</option>\n";
2265 + }
1293 2266 }
1294 -
1295 2267 $html .= "</select>\n";
1296 2268 }
1297 -
1298 - if( $out == 'return' ){
2269 +
2270 + $html = apply_filters( 'usces_filter_the_delivery_method', $html, $deli_id );
2271 +
2272 + if ( 'return' === $out ) {
1299 2273 return $html;
1300 - }else{
1301 - echo $html;
2274 + } else {
2275 + echo $html; // no escape due to filter.
1302 2276 }
1303 2277 }
1304 -//20101208ysk start
1305 -function usces_the_delivery_date( $value = '', $out = '' ){
1306 - global $usces;
1307 2278
1308 - $html = "<select name='offer[delivery_date]' id='delivery_date_select' class='delivery_date'>\n";
2279 +/**
2280 + * Delivery date field
2281 + *
2282 + * @param string $value Value.
2283 + * @param string $out Return value or echo.
2284 + * @return string|void
2285 + */
2286 +function usces_the_delivery_date( $value = '', $out = '' ) {
2287 +
2288 + $html = "<select name=\"offer[delivery_date]\" id=\"delivery_date_select\" class=\"delivery_date\">\n";
1309 2289 $html .= "</select>\n";
2290 + $html = apply_filters( 'the_delivery_date', $html );
1310 2291
1311 - if( $out == 'return' ){
2292 + if ( 'return' === $out ) {
1312 2293 return $html;
1313 - }else{
1314 - echo $html;
2294 + } else {
2295 + echo $html; // no escape due to filter.
1315 2296 }
1316 2297 }
1317 -//20101208ysk end
1318 -function usces_the_delivery_time( $value = '', $out = '' ){
1319 - global $usces;
1320 -
1321 -//20101208ysk start
1322 - //$html = "<select name='offer[delivery_time]' id='delivery_time_select' class='delivery_time'>\n";
1323 - $html = "<div id='delivery_time_limit_message'></div>\n";
1324 - $html .= "<select name='offer[delivery_time]' id='delivery_time_select' class='delivery_time'>\n";
1325 -//20101208ysk end
1326 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";
1327 2310 $html .= "</select>\n";
1328 -
1329 - if( $out == 'return' ){
2311 + $html = apply_filters( 'the_delivery_time', $html );
2312 +
2313 + if ( 'return' === $out ) {
1330 2314 return $html;
1331 - }else{
1332 - echo $html;
2315 + } else {
2316 + echo $html; // no escape due to filter.
1333 2317 }
1334 2318 }
1335 2319
1336 -function usces_the_campaign_schedule($flag, $kind){
2320 +/**
2321 + * Campaign Schedule
2322 + *
2323 + * @param string $flag Flag.
2324 + * @param string $kind Kind.
2325 + */
2326 +function usces_the_campaign_schedule( $flag, $kind ) {
1337 2327 global $usces;
1338 - $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');
1339 - $starttime = $usces->options['campaign_schedule']['start']['hour'] . __('hour','usces') . $usces->options['campaign_schedule']['start']['min'] . __('min','usces');
1340 - $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');
1341 - $endtime = $usces->options['campaign_schedule']['end']['hour'] . __('hour','usces') . $usces->options['campaign_schedule']['end']['min'] . __('min','usces');
1342 - if( 'start' == $flag ) {
1343 - if( 'date' == $kind ) {
1344 - echo esc_html($startdate);
1345 - }elseif( 'datetime' == $kind ) {
1346 - echo esc_html($startdate . ' ' . $starttime);
2328 +
2329 + $startdate = $usces->options['campaign_schedule']['start']['year'] . __( 'year', 'usces' ) . $usces->options['campaign_schedule']['start']['month'] . __( 'month', 'usces' ) . $usces->options['campaign_schedule']['start']['day'] . __( 'day', 'usces' );
2330 + $starttime = $usces->options['campaign_schedule']['start']['hour'] . __( 'hour', 'usces' ) . $usces->options['campaign_schedule']['start']['min'] . __( 'min', 'usces' );
2331 + $enddate = $usces->options['campaign_schedule']['end']['year'] . __( 'year', 'usces' ) . $usces->options['campaign_schedule']['end']['month'] . __( 'month', 'usces' ) . $usces->options['campaign_schedule']['end']['day'] . __( 'day', 'usces' );
2332 + $endtime = $usces->options['campaign_schedule']['end']['hour'] . __( 'hour', 'usces' ) . $usces->options['campaign_schedule']['end']['min'] . __( 'min', 'usces' );
2333 + if ( 'start' === $flag ) {
2334 + if ( 'date' === $kind ) {
2335 + echo esc_html( $startdate );
2336 + } elseif ( 'datetime' === $kind ) {
2337 + echo esc_html( $startdate . ' ' . $starttime );
1347 2338 }
1348 - } elseif ( 'end' == $flag ) {
1349 - if( 'date' == $kind ) {
1350 - echo esc_html($enddate);
1351 - }elseif( 'datetime' == $kind ) {
1352 - echo esc_html($enddate . ' ' . $endtime);
2339 + } elseif ( 'end' === $flag ) {
2340 + if ( 'date' === $kind ) {
2341 + echo esc_html( $enddate );
2342 + } elseif ( 'datetime' === $kind ) {
2343 + echo esc_html( $enddate . ' ' . $endtime );
1353 2344 }
1354 2345 }
1355 2346 }
1356 2347
1357 -
2348 +/**
2349 + * Display cart confirm
2350 + */
1358 2351 function usces_the_confirm() {
1359 2352 global $usces;
1360 -
1361 2353 $usces->display_cart_confirm();
1362 2354 }
1363 2355
2356 +/**
2357 + * Inquiry
2358 + */
1364 2359 function usces_inquiry_condition() {
1365 2360 global $error_message, $reserve, $inq_name, $inq_mailaddress, $inq_contents;
1366 - require(USCES_PLUGIN_DIR.'/includes/inquiry_condition.php');
2361 + require USCES_PLUGIN_DIR . '/includes/inquiry_condition.php';
1367 2362 }
1368 2363
2364 +/**
2365 + * Inquiry form
2366 + */
1369 2367 function usces_the_inquiry_form() {
1370 2368 global $usces;
2369 +
1371 2370 $error_message = '';
1372 - if( isset($_POST['inq_name']) && !WCUtils::is_blank($_POST['inq_name']) ) {
1373 - $inq_name = trim($_POST['inq_name']);
1374 - }else{
2371 + if ( isset( $_POST['inq_name'] ) && ! WCUtils::is_blank( $_POST['inq_name'] ) ) {
2372 + $inq_name = trim( wp_unslash( $_POST['inq_name'] ) );
2373 + } else {
1375 2374 $inq_name = '';
1376 - if($usces->page == 'deficiency')
1377 - $error_message .= __('Please input your name.', 'usces') . "<br />";
2375 + if ( 'deficiency' === $usces->page ) {
2376 + $error_message .= __( 'Please input your name.', 'usces' ) . '<br />';
2377 + }
1378 2378 }
1379 - if( isset($_POST['inq_mailaddress']) && is_email(trim($_POST['inq_mailaddress'])) ) {
1380 - $inq_mailaddress = trim($_POST['inq_mailaddress']);
1381 - }elseif( isset($_POST['inq_mailaddress']) && !is_email(trim($_POST['inq_mailaddress'])) ) {
1382 - $inq_mailaddress = trim($_POST['inq_mailaddress']);
1383 - if($usces->page == 'deficiency')
1384 - $error_message .= __('E-mail address is not correct', 'usces') . "<br />";
1385 - }else{
2379 + if ( isset( $_POST['inq_mailaddress'] ) && is_email( trim( wp_unslash( $_POST['inq_mailaddress'] ) ) ) ) {
2380 + $inq_mailaddress = trim( wp_unslash( $_POST['inq_mailaddress'] ) );
2381 + } elseif ( isset( $_POST['inq_mailaddress'] ) && ! is_email( trim( wp_unslash( $_POST['inq_mailaddress'] ) ) ) ) {
2382 + $inq_mailaddress = trim( wp_unslash( $_POST['inq_mailaddress'] ) );
2383 + if ( 'deficiency' === $usces->page ) {
2384 + $error_message .= __( 'E-mail address is not correct', 'usces' ) . '<br />';
2385 + }
2386 + } else {
1386 2387 $inq_mailaddress = '';
1387 - if($usces->page == 'deficiency')
1388 - $error_message .= __('Please input your e-mail address.', 'usces') . "<br />";
2388 + if ( 'deficiency' === $usces->page ) {
2389 + $error_message .= __( 'Please input your e-mail address.', 'usces' ) . '<br />';
2390 + }
1389 2391 }
1390 - if( isset($_POST['inq_contents']) && !WCUtils::is_blank($_POST['inq_contents']) ) {
1391 - $inq_contents = trim($_POST['inq_contents']);
1392 - }else{
2392 + if ( isset( $_POST['inq_contents'] ) && ! WCUtils::is_blank( $_POST['inq_contents'] ) ) {
2393 + $inq_contents = trim( wp_unslash( $_POST['inq_contents'] ) );
2394 + } else {
1393 2395 $inq_contents = '';
1394 - if($usces->page == 'deficiency')
1395 - $error_message .= __('Please input contents.', 'usces');
2396 + if ( 'deficiency' === $usces->page ) {
2397 + $error_message .= __( 'Please input contents.', 'usces' );
2398 + }
1396 2399 }
1397 -
1398 2400
1399 - if($usces->page == 'inquiry_comp') :
1400 - $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') );
1401 -?>
1402 - <div class="inquiry_comp"><?php _e('sending completed','usces') ?></div>
1403 - <div class="compbox"><?php echo $inq_message; ?></div>
1404 -<?php
1405 - elseif($usces->page == 'inquiry_error') :
1406 -?>
1407 - <div class="inquiry_comp"><?php _e('Failure in sending','usces') ?></div>
1408 -<?php
2401 + if ( 'inquiry_comp' === $usces->page ) :
2402 + $inq_message = apply_filters( 'usces_filter_inquiry_message_completion', __( 'I send a reply email to a visitor. I ask in a few minutes to be able to have you refer in there being the fear that e-mail address is different again when the email from this shop does not arrive.', 'usces' ) );
2403 + ?>
2404 + <div class="inquiry_comp"><?php esc_html_e( 'sending completed', 'usces' ); ?></div>
2405 + <div class="compbox"><?php wel_esc_script_e( $inq_message ); ?></div>
2406 + <?php
2407 + elseif ( 'inquiry_error' === $usces->page ) :
2408 + ?>
2409 + <div class="inquiry_comp"><?php esc_html_e( 'Failure in sending', 'usces' ); ?></div>
2410 + <?php
1409 2411 else :
1410 -?>
1411 -<?php if( !empty($error_message) ): ?>
1412 -<div class="error_message"><?php echo $error_message; ?></div>
1413 -<?php endif; ?>
1414 -<form name="inquiry_form" action="<?php //echo USCES_CART_URL; ?>" method="post">
2412 + ?>
2413 + <?php if ( ! empty( $error_message ) ) : ?>
2414 +<div class="error_message"><?php wel_esc_script_e( $error_message ); ?></div>
2415 + <?php endif; ?>
2416 +<form name="inquiry_form" method="post">
1415 2417 <input type="hidden" name="kakuninyou" />
1416 2418 <table border="0" cellpadding="0" cellspacing="0" class="inquiry_table">
1417 2419 <tr>
1418 -<th scope="row"><?php _e('Full name','usces') ?></th>
1419 -<td><input name="inq_name" type="text" class="inquiry_name" value="<?php echo esc_attr($inq_name); ?>" /></td>
2420 +<th scope="row"><?php esc_html_e( 'Full name', 'usces' ); ?></th>
2421 +<td><input name="inq_name" type="text" class="inquiry_name" value="<?php echo esc_attr( $inq_name ); ?>" /></td>
1420 2422 </tr>
1421 2423 <tr>
1422 -<th scope="row"><?php _e('e-mail adress','usces') ?></th>
1423 -<td><input name="inq_mailaddress" type="text" class="inquiry_mailaddress" value="<?php echo esc_attr($inq_mailaddress); ?>" /></td>
2424 +<th scope="row"><?php esc_html_e( 'e-mail adress', 'usces' ); ?></th>
2425 +<td><input name="inq_mailaddress" type="text" class="inquiry_mailaddress" value="<?php echo esc_attr( $inq_mailaddress ); ?>" /></td>
1424 2426 </tr>
1425 2427 <tr>
1426 -<th scope="row"><?php _e('contents','usces') ?></th>
1427 -<td><textarea name="inq_contents" class="inquiry_contents"><?php echo esc_attr($inq_contents); ?></textarea></td>
2428 +<th scope="row"><?php esc_html_e( 'contents', 'usces' ); ?></th>
2429 +<td><textarea name="inq_contents" class="inquiry_contents"><?php echo esc_attr( $inq_contents ); ?></textarea></td>
1428 2430 </tr>
1429 2431 </table>
1430 -<div class="send"><input name="inquiry_button" type="submit" value="<?php _e('Admit to send it with this information.','usces') ?>" /></div>
2432 +<div class="send"><input name="inquiry_button" type="submit" value="<?php esc_attr_e( 'Admit to send it with this information.', 'usces' ); ?>" /></div>
1431 2433 </form>
1432 -<?php
2434 + <?php
1433 2435 endif;
1434 2436 }
1435 2437
2438 +/**
2439 + * Get Category ID
2440 + *
2441 + * @param string $slug Slag.
2442 + * @return int
2443 + */
1436 2444 function usces_get_cat_id( $slug ) {
1437 - $cat = get_category_by_slug( $slug );
1438 - return $cat->term_id;
2445 + $cat = get_category_by_slug( $slug );
2446 + $term_id = $cat->term_id ?? 0;
2447 + return $term_id;
1439 2448 }
1440 2449
2450 +/**
2451 + * Widget Calendar
2452 + */
1441 2453 function usces_the_calendar() {
1442 2454 global $usces;
1443 - include (USCES_PLUGIN_DIR . '/includes/widget_calendar.php');
2455 + include USCES_PLUGIN_DIR . '/includes/widget_calendar.php';
1444 2456 }
1445 2457
1446 -function usces_loginout( $out = '') {
2458 +/**
2459 + * Login/Logout link
2460 + *
2461 + * @param string $out Return value or echo.
2462 + * @return string|void
2463 + */
2464 +function usces_loginout( $out = '' ) {
1447 2465 global $usces;
1448 - if ( !$usces->is_member_logged_in() )
1449 - $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>';
1450 - else
1451 - $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>';
1452 2466
1453 - if( $out == 'return' ){
1454 - return $res;
1455 - }else{
1456 - echo $res;
2467 + if ( ! $usces->is_member_logged_in() ) {
2468 + $res = '<a href="' . apply_filters( 'usces_filter_login_uri', USCES_LOGIN_URL ) . '" class="usces_login_a">' . apply_filters( 'usces_filter_loginlink_label', __( 'Log-in', 'usces' ) ) . '</a>';
2469 + } else {
2470 + $res = '<a href="' . apply_filters( 'usces_filter_logout_uri', USCES_LOGOUT_URL ) . '" class="usces_logout_a">' . apply_filters( 'usces_filter_logoutlink_label', __( 'Log out', 'usces' ) ) . '</a>';
1457 2471 }
2472 + if ( 'return' === $out ) {
2473 + return wel_esc_script( $res );
2474 + } else {
2475 + wel_esc_script_e( $res );
2476 + }
1458 2477 }
1459 2478
2479 +/**
2480 + * Is Login
2481 + *
2482 + * @return bool
2483 + */
1460 2484 function usces_is_login() {
1461 2485 global $usces;
1462 -
1463 - if( false === $usces->is_member_logged_in() )
2486 +
2487 + if ( false === $usces->is_member_logged_in() ) {
1464 2488 $res = false;
1465 - else
2489 + } else {
1466 2490 $res = true;
1467 -
2491 + }
1468 2492 return $res;
1469 2493 }
1470 2494
1471 -function usces_the_member_name( $out = '') {
2495 +/**
2496 + * Member Name
2497 + *
2498 + * @param string $out Return value or echo.
2499 + * @return string|void
2500 + */
2501 +function usces_the_member_name( $out = '' ) {
1472 2502 global $usces;
2503 +
1473 2504 $usces->get_current_member();
1474 - $res = esc_html($usces->current_member['name']);
1475 - if( $out == 'return' ){
1476 - return $res;
1477 - }else{
1478 - echo $res;
2505 + $res = esc_html( $usces->current_member['name'] );
2506 + if ( 'return' === $out ) {
2507 + return wel_esc_script( $res );
2508 + } else {
2509 + wel_esc_script_e( $res );
1479 2510 }
1480 -
1481 2511 }
1482 2512
2513 +/**
2514 + * Membership Point
2515 + *
2516 + * @param string $out Return value or echo.
2517 + * @return string|void
2518 + */
1483 2519 function usces_the_member_point( $out = '' ) {
1484 2520 global $usces;
1485 -
1486 - if( !$usces->is_member_logged_in() ) return;
1487 -
2521 +
2522 + if ( ! $usces->is_member_logged_in() ) {
2523 + return;
2524 + }
2525 +
1488 2526 $member = $usces->get_member();
1489 - if( $out == 'return' ){
2527 +
2528 + if ( 'return' === $out ) {
1490 2529 return $member['point'];
1491 - }else{
1492 - echo number_format($member['point']);
2530 + } else {
2531 + echo number_format( $member['point'] );
1493 2532 }
1494 2533 }
1495 2534
2535 +/**
2536 + * Membership Rank
2537 + *
2538 + * @param string $out Return value or echo.
2539 + * @return string|void
2540 + */
1496 2541 function usces_the_member_status( $out = '' ) {
1497 2542 global $usces;
1498 - if( !$usces->is_member_logged_in() ) return;
1499 -
2543 +
2544 + if ( ! $usces->is_member_logged_in() ) {
2545 + return;
2546 + }
2547 +
1500 2548 $usces->get_current_member();
1501 - $member = $usces->get_member_info($usces->current_member['id']);
1502 - $status_name = $usces->member_status[$member['mem_status']];
2549 + $member = $usces->get_member_info( $usces->current_member['id'] );
2550 + $status_name = $usces->member_status[ $member['mem_status'] ];
1503 2551
1504 - if( $out == 'return' ){
2552 + if ( 'return' === $out ) {
1505 2553 return $status_name;
1506 - }else{
1507 - echo esc_html($status_name);
2554 + } else {
2555 + echo esc_html( $status_name );
1508 2556 }
1509 2557 }
1510 2558
1511 -function usces_get_assistance_id_list($post_id) {
2559 +/**
2560 + * Related item list
2561 + *
2562 + * @param int $post_id Post ID.
2563 + * @return array
2564 + */
2565 +function usces_get_assistance_id_list( $post_id ) {
1512 2566 global $usces;
1513 - $names = $usces->get_tag_names($post_id);
1514 - $list = '';
1515 - foreach ( $names as $itemname )
1516 - $list .= $usces->get_ID_byItemName($itemname, 'publish') . ',';
1517 -
1518 - $list = trim($list, ',');
1519 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, ',' );
1520 2574 return $list;
1521 2575 }
1522 -function usces_get_assistance_ids($post_id) {
2576 +
2577 +/**
2578 + * Related item
2579 + *
2580 + * @param int $post_id Post ID.
2581 + * @return array
2582 + */
2583 +function usces_get_assistance_ids( $post_id ) {
1523 2584 global $usces;
1524 - $names = $usces->get_tag_names($post_id);
1525 - $ids = array();
1526 - foreach ( $names as $itemname )
1527 - $ids[] = $usces->get_ID_byItemName($itemname, 'publish');
1528 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 + }
1529 2591 return $ids;
1530 2592 }
1531 -function usces_remembername( $out = '' ){
2593 +
2594 +/**
2595 + * Forgot account
2596 + *
2597 + * @param string $out Return value or echo.
2598 + * @return string|void
2599 + */
2600 +function usces_remembername( $out = '' ) {
1532 2601 global $usces;
2602 +
1533 2603 $value = $usces->get_cookie();
1534 -
1535 - if( $out == 'return' ){
1536 - if(isset($value['name']))
1537 - return $value['name'];
1538 - else
2604 + if ( 'return' === $out ) {
2605 +// if ( isset( $value['name'] ) )
2606 +// return $value['name'];
2607 +// else
1539 2608 return '';
1540 - }else{
1541 - if(isset($value['name']))
1542 - echo esc_html($value['name']);
1543 - else
2609 + } else {
2610 +// if ( isset( $value['name'] ) )
2611 +// echo esc_html( $value['name'] );
2612 +// else
1544 2613 echo '';
1545 2614 }
1546 2615 }
1547 -function usces_rememberpass( $out = '' ){
2616 +
2617 +/**
2618 + * Forgot password
2619 + *
2620 + * @param string $out Return value or echo.
2621 + * @return string|void
2622 + */
2623 +function usces_rememberpass( $out = '' ) {
1548 2624 global $usces;
2625 +
1549 2626 $value = $usces->get_cookie();
1550 -
1551 - if( $out == 'return' ){
1552 - if(isset($value['pass']))
1553 - return $value['pass'];
1554 - else
2627 + if ( 'return' === $out ) {
2628 +// if ( isset( $value['pass'] ) )
2629 +// return $value['pass'];
2630 +// else
1555 2631 return '';
1556 - }else{
1557 - if(isset($value['pass']))
1558 - echo esc_html($value['pass']);
1559 - else
2632 + } else {
2633 +// if ( isset( $value['pass'] ) )
2634 +// echo esc_html( $value['pass'] );
2635 +// else
1560 2636 echo '';
1561 2637 }
1562 2638 }
1563 -function usces_remembercheck( $out = '' ){
2639 +
2640 +/**
2641 + * Forgot account check
2642 + *
2643 + * @param string $out Return value or echo.
2644 + * @return string|void
2645 + */
2646 +function usces_remembercheck( $out = '' ) {
1564 2647 global $usces;
2648 +
1565 2649 $value = $usces->get_cookie();
1566 -
1567 - if( $out == 'return' ){
1568 - if(isset($value['name']) && $value['name'] != '')
1569 - return ' checked="checked"';
1570 - else
2650 + if ( 'return' === $out ) {
2651 +// if ( isset( $value['name'] ) && $value['name'] != '' )
2652 +// return ' checked="checked"';
2653 +// else
1571 2654 return '';
1572 - }else{
1573 - if(isset($value['name']) && $value['name'] != '')
1574 - echo ' checked="checked"';
1575 - else
2655 + } else {
2656 +// if ( isset( $value['name'] ) && $value['name'] != '' )
2657 +// echo ' checked="checked"';
2658 +// else
1576 2659 echo '';
1577 2660 }
1578 2661 }
1579 -function usces_shippingchargeTR( $index='' ) {
2662 +
2663 +/**
2664 + * Shipping charge table
2665 + *
2666 + * @param string $index Index.
2667 + */
2668 +function usces_shippingchargeTR( $index = '' ) {
1580 2669 global $usces;
1581 - if($index == ""){
2670 +
2671 + if ( '' === $index ) {
1582 2672 $index = 0;
1583 2673 }
1584 2674 $list = '';
1585 - if( !isset($usces->options['shipping_charge'][$index]) ) return;
1586 - $shipping_charge = $usces->options['shipping_charge'][$index];
1587 -//20120710ysk start 0000472
1588 - $entry = $usces->cart->get_entry();
1589 - $country = (isset($entry['delivery']['country']) && !empty($entry['delivery']['country'])) ? $entry['delivery']['country'] : $entry['customer']['country'];//20120710ysk 0000472
1590 - //foreach ($shipping_charge['value'] as $pref => $value) {
1591 - foreach ($shipping_charge[$country] as $pref => $value) {
1592 -//20120710ysk end
1593 - $list .= "<tr><th>" . esc_html($pref) . "</th>\n";
1594 - $list .= "<td class='rightnum'>" . number_format($value) . "</td>\n";
2675 + if ( ! isset( $usces->options['shipping_charge'][ $index ] ) ) {
2676 + return;
2677 + }
2678 + $shipping_charge = $usces->options['shipping_charge'][ $index ];
2679 + $entry = $usces->cart->get_entry();
2680 + $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
2681 + foreach ( $shipping_charge[ $country ] as $pref => $value ) {
2682 + $list .= '<tr><th>' . esc_html( $pref ) . "</th>\n";
2683 + $list .= '<td class="rightnum">' . number_format( $value ) . "</td>\n";
1595 2684 $list .= "</tr>\n";
1596 2685 }
1597 - echo $list;
2686 + wel_esc_script_e( $list );
1598 2687 }
2688 +
2689 +/**
2690 + * Shipping charge
2691 + */
1599 2692 function usces_sc_shipping_charge() {
1600 2693 global $usces;
1601 - echo esc_html($usces->sc_shipping_charge());
2694 + echo esc_html( $usces->sc_shipping_charge() );
1602 2695 }
2696 +
2697 +/**
2698 + * Postage privilege
2699 + */
1603 2700 function usces_sc_postage_privilege() {
1604 2701 global $usces;
1605 - echo esc_html($usces->sc_postage_privilege());
2702 + echo esc_html( $usces->sc_postage_privilege() );
1606 2703 }
2704 +
2705 +/**
2706 + * Payment title
2707 + */
1607 2708 function usces_sc_payment_title() {
1608 2709 global $usces;
1609 - echo $usces->sc_payment_title();
2710 + wel_esc_script_e( $usces->sc_payment_title() );
1610 2711 }
1611 2712
1612 -
1613 -
1614 -function usces_posts_random_offset( $posts ){
2713 +/**
2714 + * Posts offset
2715 + *
2716 + * @param object $posts Post data.
2717 + * @return int
2718 + */
2719 +function usces_posts_random_offset( $posts ) {
1615 2720 $ids = array();
1616 - foreach( (array)$posts as $post ){
2721 + foreach ( (array) $posts as $post ) {
1617 2722 $ids[] = $post->ID;
1618 2723 }
1619 - $ct = count($ids);
1620 - $index = rand(0, ($ct-1));
2724 + $ct = count( $ids );
2725 + $index = rand( 0, ( $ct - 1 ) );
1621 2726 return $index;
1622 2727 }
1623 2728
1624 -function usces_get_category_link_by_slug( $slug ){
1625 - $category = get_category_by_slug($slug);
2729 +/**
2730 + * Get category link
2731 + *
2732 + * @param string $slug Slug.
2733 + */
2734 +function usces_get_category_link_by_slug( $slug ) {
2735 + $category = get_category_by_slug( $slug );
1626 2736 echo get_category_link( $category->term_id );
1627 2737 }
1628 2738
1629 -function usces_get_page_ID_by_pname( $post_name, $return = 'echo' ){
2739 +/**
2740 + * Get page ID
2741 + *
2742 + * @param string $post_name Post name.
2743 + * @param string $return Return value or echo.
2744 + * @return string|void
2745 + */
2746 +function usces_get_page_ID_by_pname( $post_name, $return = 'echo' ) {
1630 2747 $page = get_page_by_path( $post_name );
1631 - if($return == 'return')
2748 + if ( 'return' === $return ) {
1632 2749 return $page->ID;
1633 - else
1634 - echo $page->ID;
2750 + } else {
2751 + echo esc_attr( $page->ID );
2752 + }
1635 2753 }
1636 2754
1637 -function usces_list_bestseller($num, $days = ''){
2755 +/**
2756 + * Bestseller
2757 + *
2758 + * @param int $num Number.
2759 + * @param string $days Days.
2760 + */
2761 +function usces_list_bestseller( $num, $days = '' ) {
1638 2762 global $usces;
2763 +
1639 2764 $ids = $usces->get_bestseller_ids( $days );
1640 - $htm = "";
1641 - for($i=0; $i<$num; $i++){
1642 - if(isset($ids[$i])){
1643 - $post = get_post($ids[$i]);
1644 - if( !is_object($post) )
2765 + $htm = '';
2766 + for ( $i = 0; $i < $num; $i++ ) {
2767 + if ( isset( $ids[ $i ] ) ) {
2768 + $post_id = (int) $ids[ $i ];
2769 + $product = wel_get_product( $post_id );
2770 + $post = $product['_pst'];
2771 +
2772 + if ( false === $product ) {
1645 2773 continue;
1646 -
1647 - $disp_text = apply_filters('usces_widget_bestseller_auto_text', esc_html($post->post_title), $ids[$i]);
1648 - $list = "<li><a href='" . get_permalink($ids[$i]) . "'>" . $disp_text . "</a></li>\n";
1649 - $htm .= apply_filters('usces_filter_bestseller', $list, $ids[$i], $i);
2774 + }
2775 +
2776 + $disp_text = apply_filters( 'usces_widget_bestseller_auto_text', esc_html( $post->post_title ), $post_id );
2777 + $list = '<li><a href="' . get_permalink( $post_id ) . '">' . $disp_text . "</a></li>\n";
2778 + $htm .= apply_filters( 'usces_filter_bestseller', $list, $post_id, $i );
1650 2779 }
1651 2780 }
1652 2781 wp_reset_postdata();
1653 - echo $htm;
2782 + wel_esc_script_e( $htm );
1654 2783 }
1655 2784
1656 -function usces_list_post( $slug, $rownum, $widget_id=NULL ){
1657 - global $usces, $post;
2785 +/**
2786 + * Post list
2787 + *
2788 + * @param string $slug Slug.
2789 + * @param string $rownum Page number.
2790 + * @param string $widget_id Widget ID.
2791 + */
2792 +function usces_list_post( $slug, $rownum, $widget_id = null ) {
2793 + global $post;
2794 +
1658 2795 usces_remove_filter();
1659 -
1660 - $li = '';
1661 - $infolist = new wp_query( array('category_name'=>$slug, 'post_status'=>'publish', 'posts_per_page'=>$rownum, 'order'=>'DESC', 'orderby'=>'date') );
1662 - if( NULL != $widget_id && $infolist->have_posts() ){
2796 +
2797 + $li = '';
2798 + $infolist = new WP_Query( array( 'category_name' => $slug, 'post_status' => 'publish', 'posts_per_page' => $rownum, 'order' => 'DESC', 'orderby' => 'date' ) );
2799 + if ( null !== $widget_id && $infolist->have_posts() ) {
1663 2800 remove_filter( 'excerpt_length', 'welcart_excerpt_length' );
1664 2801 remove_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' );
1665 2802 remove_filter( 'excerpt_more', 'welcart_auto_excerpt_more' );
1666 - if( function_exists('welcart_widget_post_excerpt_length_'.$widget_id) )
1667 - add_filter( 'excerpt_length', 'welcart_widget_post_excerpt_length_'.$widget_id );
1668 - if( function_exists('welcart_widget_post_excerpt_mblength_'.$widget_id) )
1669 - add_filter( 'excerpt_mblength', 'welcart_widget_post_excerpt_mblength_'.$widget_id );
2803 + if ( function_exists( 'welcart_widget_post_excerpt_length_' . $widget_id ) ) {
2804 + add_filter( 'excerpt_length', 'welcart_widget_post_excerpt_length_' . $widget_id );
2805 + }
2806 + if ( function_exists( 'welcart_widget_post_excerpt_mblength_' . $widget_id ) ) {
2807 + add_filter( 'excerpt_mblength', 'welcart_widget_post_excerpt_mblength_' . $widget_id );
2808 + }
1670 2809 }
1671 2810 $list_index = 0;
1672 - while ($infolist->have_posts()) {
2811 + while ( $infolist->have_posts() ) {
1673 2812 $infolist->the_post();
1674 - $list = '<li class="post_list'. apply_filters('usces_filter_post_list_class', NULL, $list_index, count($infolist)) . '">'."\n";
1675 - $list .= "<div class='title'><a href='" . get_permalink($post->ID) . "'>" . get_the_title() . "</a></div>\n";
1676 - $list .= "<p>" . get_the_excerpt() . "</p>\n";
2813 + $list = '<li class="post_list' . apply_filters( 'usces_filter_post_list_class', null, $list_index, $infolist->post_count ) . '">' . "\n";
2814 + $list .= "<div class='title'><a href='" . get_permalink( $post->ID ) . "'>" . get_the_title() . "</a></div>\n";
2815 + $list .= '<p>' . get_the_excerpt() . "</p>\n";
1677 2816 $list .= "</li>\n";
1678 - $li .= apply_filters( 'usces_filter_widget_post', $list, $post, $slug, $list_index);
2817 + $li .= apply_filters( 'usces_filter_widget_post', $list, $post, $slug, $list_index );
1679 2818 $list_index++;
1680 2819 }
1681 - wp_reset_query();
2820 + wp_reset_postdata();
1682 2821 usces_reset_filter();
1683 - if( NULL != $widget_id && $infolist->have_posts() ){
2822 + if ( null !== $widget_id && $infolist->have_posts() ) {
1684 2823 add_filter( 'excerpt_length', 'welcart_excerpt_length' );
1685 2824 add_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' );
1686 2825 add_filter( 'excerpt_more', 'welcart_auto_excerpt_more' );
1687 2826 }
1688 - echo $li;
2827 + wel_esc_script_e( $li );
1689 2828 }
1690 2829
1691 -function usces_categories_checkbox($output=''){
1692 - global $usces;
1693 - $retcats = apply_filters('usces_search_retcats', usces_search_categories());
1694 - $parent_id = apply_filters('usces_search_categories_checkbox_parent', USCES_ITEM_CAT_PARENT_ID);
1695 - $htm = usces_get_categories_checkbox($parent_id);
1696 - $htm = apply_filters('usces_filter_categories_checkbox', $htm, $parent_id);
1697 -
1698 - if($output == '' || $output == 'echo')
1699 - echo $htm;
1700 - else
1701 - return $htm;
2830 +/**
2831 + * Category checkbox
2832 + *
2833 + * @param string $output Return value or echo.
2834 + * @return string|void
2835 + */
2836 +function usces_categories_checkbox( $output = '' ) {
2837 +
2838 + $retcats = apply_filters( 'usces_search_retcats', usces_search_categories() );
2839 + $parent_id = apply_filters( 'usces_search_categories_checkbox_parent', USCES_ITEM_CAT_PARENT_ID );
2840 + $htm = usces_get_categories_checkbox( $parent_id );
2841 + $htm = apply_filters( 'usces_filter_categories_checkbox', $htm, $parent_id );
2842 +
2843 + if ( '' === $output || 'echo' === $output ) {
2844 + wel_esc_script_e( $htm );
2845 + } else {
2846 + return wel_esc_script( $htm );
2847 + }
1702 2848 }
1703 2849
1704 -function usces_get_categories_checkbox($parent_id){
2850 +/**
2851 + * Category checkbox
2852 + *
2853 + * @param int $parent_id Parent category ID.
2854 + */
2855 +function usces_get_categories_checkbox( $parent_id ) {
1705 2856 global $usces;
1706 - $htm = '';
1707 - $retcats = usces_search_categories();
1708 - $parent_cat = get_category($parent_id);
1709 - $categories = get_categories('parent='.$parent_id . "&hide_empty=0&orderby=" . $usces->options['fukugo_category_orderby'] . "&order=" . $usces->options['fukugo_category_order']);
1710 - $htm .= "<fieldset class='catfield-" . $parent_cat->term_id . "'><legend>" . $parent_cat->cat_name . "</legend><ul>\n";
1711 - foreach ($categories as $cat) {
1712 - $children = get_categories('parent='.$cat->term_id . "&hide_empty=0");
1713 - if( 0 === count($children) ){
1714 - $checked = in_array($cat->term_id, $retcats) ? " checked='checked'" : "";
1715 - $htm .= "<li><input name='category[".$cat->term_id."]' type='checkbox' id='category[".$cat->term_id."]' value='".$cat->term_id."'".$checked." /><label for='category[".$cat->term_id."]' class='catlabel-" . $cat->term_id . "'>".esc_html($cat->cat_name)."</label></li>\n";
2857 +
2858 + $htm = '';
2859 + $retcats = usces_search_categories();
2860 + $parent_cat = get_category( $parent_id );
2861 + $categories = get_categories( 'parent=' . $parent_id . '&hide_empty=0&orderby=' . $usces->options['fukugo_category_orderby'] . '&order=' . $usces->options['fukugo_category_order'] );
2862 + $htm .= '<fieldset class="catfield-' . $parent_cat->term_id . '"><legend>' . $parent_cat->cat_name . "</legend><ul>\n";
2863 + foreach ( $categories as $cat ) {
2864 + $children = get_categories( 'parent=' . $cat->term_id . '&hide_empty=0' );
2865 + if ( 0 === count( $children ) ) {
2866 + $checked = in_array( $cat->term_id, $retcats ) ? ' checked="checked"' : '';
2867 + $htm .= '<li><input name="category[' . $cat->term_id . ']" type="checkbox" id="category[' . $cat->term_id . ']" value="' . $cat->term_id . '"' . $checked . ' /><label for="category[' . $cat->term_id . ']" class="catlabel-' . $cat->term_id . '">' . esc_html( $cat->cat_name ) . "</label></li>\n";
1716 2868 }
1717 2869 }
1718 2870 $htm .= "</ul>\n";
1719 - foreach ($categories as $cat) {
1720 - $children = get_categories('parent='.$cat->term_id . "&hide_empty=0");
1721 - if( 0 < count($children) ){
1722 - $htm .= usces_get_categories_checkbox($cat->term_id);
2871 + foreach ( $categories as $cat ) {
2872 + $children = get_categories( 'parent=' . $cat->term_id . '&hide_empty=0' );
2873 + if ( 0 < count( $children ) ) {
2874 + $htm .= usces_get_categories_checkbox( $cat->term_id );
1723 2875 }
1724 2876 }
1725 2877 $htm .= "</fieldset>\n";
1726 2878
@@ -1726,316 +2878,375 @@
1726 2878
1727 2879 return $htm;
1728 2880 }
1729 2881
1730 -function usces_search_categories(){
2882 +/**
2883 + * Search categories
2884 + *
2885 + * @return array
2886 + */
2887 +function usces_search_categories() {
1731 2888 $cats = array();
1732 - //if(isset($_POST['category']))
1733 - // $cats = $_POST['category'];
1734 - if(isset($_REQUEST['category']))
1735 - $cats = $_REQUEST['category'];
1736 - else
2889 + if ( isset( $_REQUEST['category'] ) ) {
2890 + $cats = wp_unslash( $_REQUEST['category'] );
2891 + } else {
1737 2892 $cats[] = USCES_ITEM_CAT_PARENT_ID;
1738 - sort($cats);
2893 + }
2894 + sort( $cats );
1739 2895 return $cats;
1740 2896 }
1741 2897
1742 -function usces_delivery_method_name( $id, $out = '' ){
2898 +/**
2899 + * Delivery method name
2900 + *
2901 + * @param int $id Delivery ID.
2902 + * @param string $out Return value or echo.
2903 + * @return string|void
2904 + */
2905 +function usces_delivery_method_name( $id, $out = '' ) {
1743 2906 global $usces;
1744 -
1745 - if($id > -1){
1746 - $id =$usces->get_delivery_method_index($id);
1747 - $name = $usces->options['delivery_method'][$id]['name'];
1748 - }else{
1749 - $name = __('No preference','usces');
2907 +
2908 + $id = $usces->get_delivery_method_index( $id );
2909 + if ( $id > -1 ) {
2910 + $name = $usces->options['delivery_method'][ $id ]['name'];
2911 + } else {
2912 + $name = __( 'No preference', 'usces' );
1750 2913 }
1751 -
1752 - if($out == 'return'){
2914 +
2915 + if ( 'return' === $out ) {
1753 2916 return $name;
1754 - }else{
1755 - echo esc_html($name);
2917 + } else {
2918 + echo esc_html( $name );
1756 2919 }
1757 2920 }
1758 2921
1759 -function usces_is_membersystem_state(){
2922 +/**
2923 + * Use membership system
2924 + *
2925 + * @return bool
2926 + */
2927 +function usces_is_membersystem_state() {
1760 2928 global $usces;
1761 2929
1762 - if($usces->options['membersystem_state'] == 'activate') {
2930 + if ( 'activate' === $usces->options['membersystem_state'] ) {
1763 2931 return true;
1764 - }else{
2932 + } else {
1765 2933 return false;
1766 2934 }
1767 2935 }
1768 2936
1769 -function usces_is_membersystem_point(){
2937 +/**
2938 + * Use membership point
2939 + *
2940 + * @return bool
2941 + */
2942 +function usces_is_membersystem_point() {
1770 2943 global $usces;
1771 2944
1772 - if($usces->options['membersystem_point'] == 'activate') {
2945 + if ( 'activate' === $usces->options['membersystem_point'] ) {
1773 2946 return true;
1774 - }else{
2947 + } else {
1775 2948 return false;
1776 2949 }
1777 2950 }
1778 2951
1779 -function usces_copyright(){
2952 +/**
2953 + * Copyright
2954 + */
2955 +function usces_copyright() {
1780 2956 global $usces;
1781 -
1782 - echo esc_html($usces->options['copyright']);
2957 + echo esc_html( $usces->options['copyright'] );
1783 2958 }
1784 2959
1785 -function usces_totalprice_in_cart(){
2960 +/**
2961 + * Total amount in cart
2962 + */
2963 +function usces_totalprice_in_cart() {
1786 2964 global $usces;
1787 -
1788 - echo number_format($usces->get_total_price());
2965 + echo number_format( $usces->get_total_price() );
1789 2966 }
1790 2967
1791 -function usces_totalquantity_in_cart(){
2968 +/**
2969 + * Total quantities in cart
2970 + */
2971 +function usces_totalquantity_in_cart() {
1792 2972 global $usces;
1793 -
1794 - echo number_format($usces->get_total_quantity());
2973 + echo number_format( $usces->get_total_quantity() );
1795 2974 }
1796 2975
1797 -function usces_get_page_mode(){
2976 +/**
2977 + * Page mode
2978 + *
2979 + * @return string
2980 + */
2981 +function usces_get_page_mode() {
1798 2982 global $usces;
1799 -
1800 2983 return $usces->page;
1801 2984 }
1802 2985
1803 -function usces_is_cat_of_item( $cat_id ){
2986 +/**
2987 + * Is in item category
2988 + *
2989 + * @param int $cat_id Category ID.
2990 + * @return bool
2991 + */
2992 +function usces_is_cat_of_item( $cat_id ) {
1804 2993 global $usces;
1805 - $ids = $usces->get_item_cat_ids();
2994 +
2995 + $ids = $usces->get_item_cat_ids();
1806 2996 $ids[] = USCES_ITEM_CAT_PARENT_ID;
1807 - if(in_array($cat_id, $ids)){
2997 + if ( in_array( $cat_id, $ids ) ) {
1808 2998 return true;
1809 - }else{
2999 + } else {
1810 3000 return false;
1811 3001 }
1812 3002 }
1813 3003
1814 -function usces_get_item_custom( $post_id, $type = 'list', $out = '' ){
3004 +/**
3005 + * Item custom field
3006 + *
3007 + * @param int $post_id Post ID.
3008 + * @param string $type Type.
3009 + * @param string $out Return value or echo.
3010 + * @return string|void
3011 + */
3012 +function usces_get_item_custom( $post_id, $type = 'list', $out = '' ) {
1815 3013 global $usces;
1816 - $cfields = $usces->get_post_custom($post_id);
1817 - switch( $type ){
3014 +
3015 + $cfields = wel_get_extra_data( $post_id );
3016 + $html = '';
3017 +
3018 + switch ( $type ) {
1818 3019 case 'list':
1819 3020 $list = '';
1820 - $html = '<ul class="item_custom_field">'."\n";
1821 - foreach( $cfields as $key => $value ){
1822 - if( 'wccs_' == substr($key, 0, 5) ){
1823 - $list .= '<li>' . esc_html(substr($key, 5)) . ' : ' . nl2br(esc_html($value[0])) . '</li>'."\n";
3021 + $html = '<ul class="item_custom_field">' . "\n";
3022 + foreach ( $cfields as $key => $values ) {
3023 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3024 + if ( is_array( $values ) ) {
3025 + foreach ( $values as $value ) {
3026 + $list .= '<li>' . esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $value ) ) . '</li>' . "\n";
3027 + }
3028 + } else {
3029 + $list .= '<li>' . esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $values ) ) . '</li>' . "\n";
3030 + }
1824 3031 }
1825 3032 }
1826 - if(empty($list)){
3033 + if ( empty( $list ) ) {
1827 3034 $html = '';
1828 - }else{
1829 - $html .= $list . '</ul>'."\n";
3035 + } else {
3036 + $html .= $list . '</ul>' . "\n";
1830 3037 }
1831 3038 break;
1832 3039
1833 3040 case 'table':
1834 3041 $list = '';
1835 - $html = '<table class="item_custom_field">'."\n";
1836 - foreach($cfields as $key => $value){
1837 - if( 'wccs_' == substr($key, 0, 5) ){
1838 - $list .= '<tr><th>' . esc_html(substr($key, 5)) . '</th><td>' . nl2br(esc_html($value[0])) . '</td></tr>'."\n";
3042 + $html = '<table class="item_custom_field">' . "\n";
3043 + foreach ( $cfields as $key => $values ) {
3044 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3045 + if ( is_array( $values ) ) {
3046 + foreach ( $values as $value ) {
3047 + $list .= '<tr><th>' . esc_html( substr( $key, 5 ) ) . '</th><td>' . nl2br( esc_html( $value ) ) . '</td></tr>' . "\n";
3048 + }
3049 + } else {
3050 + $list .= '<tr><th>' . esc_html( substr( $key, 5 ) ) . '</th><td>' . nl2br( esc_html( $values ) ) . '</td></tr>' . "\n";
3051 + }
1839 3052 }
1840 3053 }
1841 - if(empty($list)){
3054 + if ( empty( $list ) ) {
1842 3055 $html = '';
1843 - }else{
1844 - $html .= $list . '</table>'."\n";
3056 + } else {
3057 + $html .= $list . '</table>' . "\n";
1845 3058 }
1846 3059 break;
1847 3060
1848 3061 case 'notag':
1849 3062 $list = '';
1850 - foreach($cfields as $key => $value){
1851 - if( 'wccs_' == substr($key, 0, 5) ){
1852 - $list .= esc_html(substr($key, 5)) . ' : ' . nl2br(esc_html($value[0])) . "\r\n";
3063 + foreach ( $cfields as $key => $values ) {
3064 + if ( 'wccs_' === substr( $key, 0, 5 ) ) {
3065 + if ( is_array( $values ) ) {
3066 + foreach ( $values as $value ) {
3067 + $list .= esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $value ) ) . "\r\n";
3068 + }
3069 + } else {
3070 + $list .= esc_html( substr( $key, 5 ) ) . ' : ' . nl2br( esc_html( $values ) ) . "\r\n";
3071 + }
1853 3072 }
1854 3073 }
1855 - if(empty($list)){
3074 + if ( empty( $list ) ) {
1856 3075 $html = '';
1857 - }else{
3076 + } else {
1858 3077 $html = $list;
1859 3078 }
1860 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;
1861 3110 }
1862 3111 $html = apply_filters( 'usces_filter_item_custom', $html, $post_id, $type );
1863 -
1864 - if( 'return' == $out){
3112 +
3113 + if ( 'return' === $out ) {
1865 3114 return $html;
1866 - }else{
1867 - echo $html;
3115 + } else {
3116 + echo $html; // no escape due to filter.
1868 3117 }
1869 3118 }
1870 3119
1871 -function usces_settle_info_field( $order_id, $type='nl', $out='echo' ){
3120 +/**
3121 + * Settlement information
3122 + *
3123 + * @param int $order_id Order ID.
3124 + * @param string $type Type.
3125 + * @param string $out Return value or echo.
3126 + * @return string|void
3127 + */
3128 +function usces_settle_info_field( $order_id, $type = 'nl', $out = 'echo' ) {
1872 3129 global $usces;
1873 - $str = '';
3130 +
3131 + $str = '';
1874 3132 $fields = $usces->get_settle_info_field( $order_id );
1875 -//20101018ysk start
1876 - $acting = isset($fields['acting']) ? $fields['acting'] : '';
1877 - foreach($fields as $key => $value){
1878 -//20101018ysk end
1879 - $keys = array(
1880 - 'acting','order_no','tracking_no','status','error_message','money',
1881 - 'pay_cvs', 'pay_no1', 'pay_no2', 'pay_limit', 'error_code',
1882 - 'settlement_id','RECDATE','JOB_ID','S_TORIHIKI_NO','TOTAL','CENDATE',
1883 - 'gid', 'rst', 'ap', 'ec', 'god', 'ta', 'cv', 'no', 'cu', 'mf', 'nk', 'nkd', 'bank', 'exp',
1884 - 'order_number',
1885 - 'res_tracking_id', 'res_payment_date', 'res_payinfo_key',
1886 - 'SID', 'DATE', 'TIME', 'CVS', 'SHNO', 'FURL', 'settltment_status', 'settltment_errmsg',
1887 - 'stran', 'mbtran', 'bktrans', 'tranid', 'TransactionId',
1888 - 'mStatus', 'vResultCode', 'orderId', 'cvsType', 'receiptNo', 'receiptDate', 'rcvAmount'
1889 - );
1890 - $keys = apply_filters( 'usces_filter_settle_info_field_keys', $keys );
1891 - if( !in_array($key, $keys) ) {
3133 + $acting = isset( $fields['acting'] ) ? $fields['acting'] : '';
3134 + $keys = array(
3135 + 'acting',
3136 + 'order_no',
3137 + 'tracking_no',
3138 + 'status',
3139 + 'error_message',
3140 + 'money',
3141 + 'pay_cvs',
3142 + 'pay_no1',
3143 + 'pay_no2',
3144 + 'pay_limit',
3145 + 'error_code',
3146 + 'settlement_id',
3147 + 'RECDATE',
3148 + 'JOB_ID',
3149 + 'S_TORIHIKI_NO',
3150 + 'TOTAL',
3151 + 'CENDATE',
3152 + 'gid',
3153 + 'rst',
3154 + 'ap',
3155 + 'ec',
3156 + 'god',
3157 + 'ta',
3158 + 'cv',
3159 + 'no',
3160 + 'cu',
3161 + 'mf',
3162 + 'nk',
3163 + 'nkd',
3164 + 'bank',
3165 + 'exp',
3166 + 'txn_id',
3167 + 'order_number',
3168 + 'res_tracking_id',
3169 + 'res_payment_date',
3170 + 'res_payinfo_key',
3171 + 'settltment_status',
3172 + 'settltment_errmsg',
3173 + 'stran',
3174 + 'mbtran',
3175 + 'bktrans',
3176 + 'tranid',
3177 + 'TransactionId',
3178 + 'mStatus',
3179 + 'vResultCode',
3180 + 'orderId',
3181 + 'cvsType',
3182 + 'receiptNo',
3183 + 'receiptDate',
3184 + 'rcvAmount',
3185 + 'trading_id',
3186 + 'payment_type',
3187 + 'seq_payment_id',
3188 + 'sendpoint',
3189 + 'option',
3190 + 'LINK_KEY',
3191 + );
3192 + $keys = apply_filters( 'usces_filter_settle_info_field_keys', $keys, $fields );
3193 + foreach ( $fields as $key => $value ) {
3194 + if ( ! in_array( $key, $keys, true ) ) {
1892 3195 continue;
1893 3196 }
1894 3197
1895 - switch($acting){
1896 - case 'zeus_bank':
1897 - if( 'status' == $key){
1898 - if( '01' === $value ){
1899 - $value = '受付中';
1900 - }elseif( '02' === $value ){
1901 - $value = '未入金';
1902 - }elseif( '03' === $value ){
1903 - $value = '入金済';
1904 - }elseif( '04' === $value ){
1905 - $value = 'エラー';
1906 - }elseif( '05' === $value ){
1907 - $value = '入金失敗';
1908 - }
1909 - }elseif( 'error_message' == $key){
1910 - if( '0002' === $value ){
1911 - $value = '入金不足';
1912 - }elseif( '0003' === $value ){
1913 - $value = '過剰入金';
1914 - }
3198 + if ( 'jpayment_conv' === $acting ) {
3199 + if ( 'rst' === $key ) {
3200 + if ( '1' === $value ) {
3201 + $value = 'OK';
3202 + } elseif ( '2' === $value ) {
3203 + $value = 'NG';
1915 3204 }
1916 - break;
1917 - case 'zeus_conv':
1918 - if( 'pay_cvs' == $key){
1919 - if( 'D001' === $value ){
1920 - $value = 'セブンイレブン';
1921 - }elseif( 'D002' === $value ){
1922 - $value = 'ローソン';
1923 - }elseif( 'D030' === $value ){
1924 - $value = 'ファミリーマート';
1925 - }elseif( 'D040' === $value ){
1926 - $value = 'サークルKサンクス';
1927 - }elseif( 'D015' === $value ){
1928 - $value = 'セイコーマート';
1929 - }elseif( 'D050' === $value ){
1930 - $value = 'ミニストップ';
1931 - }elseif( 'D060' === $value ){
1932 - $value = 'デイリーヤマザキ';
1933 - }
1934 - }elseif( 'status' == $key){
1935 - if( '01' === $value ){
1936 - $value = '未入金';
1937 - }elseif( '02' === $value ){
1938 - $value = '申込エラー';
1939 - }elseif( '03' === $value ){
1940 - $value = '期日切';
1941 - }elseif( '04' === $value ){
1942 - $value = '入金済';
1943 - }elseif( '05' === $value ){
1944 - $value = '売上確定';
1945 - }elseif( '06' === $value ){
1946 - $value = '入金取消';
1947 - }elseif( '11' === $value ){
1948 - $value = 'キャンセル後入金';
1949 - }elseif( '12' === $value ){
1950 - $value = 'キャンセル後売上';
1951 - }elseif( '13' === $value ){
1952 - $value = 'キャンセル後取消';
1953 - }
1954 - }elseif( 'pay_limit' == $key){
1955 - $value = substr($value, 0, 4).'年' . substr($value, 4, 2).'月' . substr($value, 6, 2).'日';
3205 + } elseif ( 'ap' === $key ) {
3206 + if ( 'CPL_PRE' === $value ) {
3207 + $value = 'コンビニペーパーレス決済識別コード';
3208 + } elseif ( 'CPL' === $value ) {
3209 + $value = '入金確定';
3210 + } elseif ( 'CVS_CAN' === $value ) {
3211 + $value = '入金取消';
1956 3212 }
1957 - break;
1958 -//20101018ysk start
1959 - case 'jpayment_conv':
1960 - switch($key) {
1961 - case 'rst':
1962 - switch($value) {
1963 - case '1':
1964 - $value = 'OK'; break;
1965 - case '2':
1966 - $value = 'NG'; break;
1967 - }
1968 - break;
1969 - case 'ap':
1970 - switch($value) {
1971 - case 'CPL_PRE':
1972 - $value = 'コンビニペーパーレス決済識別コード'; break;
1973 - case 'CPL':
1974 - $value = '入金確定'; break;
1975 - case 'CVS_CAN':
1976 - $value = '入金取消'; break;
1977 - }
1978 - break;
1979 - case 'cv':
1980 - $value = esc_html(usces_get_conv_name($value));
1981 - break;
1982 - case 'mf':
1983 - case 'nk':
1984 - case 'nkd':
1985 - case 'bank':
1986 - case 'exp':
1987 - continue;
1988 - break;
3213 + } elseif ( 'cv' === $key ) {
3214 + $value = esc_html( usces_get_conv_name( $value ) );
3215 + } else {
3216 + continue;
3217 + }
3218 + } elseif ( 'jpayment_bank' === $acting ) {
3219 + if ( 'rst' === $key ) {
3220 + if ( '1' === $value ) {
3221 + $value = 'OK';
3222 + } elseif ( '2' === $value ) {
3223 + $value = 'NG';
1989 3224 }
1990 - break;
1991 -
1992 - case 'jpayment_bank':
1993 - switch($key) {
1994 - case 'rst':
1995 - switch($value) {
1996 - case '1':
1997 - $value = 'OK'; break;
1998 - case '2':
1999 - $value = 'NG'; break;
2000 - }
2001 - break;
2002 - case 'ap':
2003 - switch($value) {
2004 - case 'BANK':
2005 - $value = '受付完了'; break;
2006 - case 'BAN_SAL':
2007 - $value = '入金完了'; break;
2008 - }
2009 - break;
2010 - case 'mf':
2011 - switch($value) {
2012 - case '1':
2013 - $value = 'マッチ'; break;
2014 - case '2':
2015 - $value = '過少'; break;
2016 - case '3':
2017 - $value = '過剰'; break;
2018 - }
2019 - break;
2020 - case 'nkd':
2021 - $value = substr($value, 0, 4).'年'.substr($value, 4, 2).'月'.substr($value, 6, 2).'日';
2022 - break;
2023 - case 'exp':
2024 - $value = substr($value, 0, 4).'年'.substr($value, 4, 2).'月'.substr($value, 6, 2).'日';
2025 - break;
2026 - case 'cv':
2027 - case 'no':
2028 - case 'cu':
2029 - continue;
2030 - break;
3225 + } elseif ( 'ap' === $key ) {
3226 + if ( 'BANK' === $value ) {
3227 + $value = '受付完了';
3228 + } elseif ( 'BAN_SAL' === $value ) {
3229 + $value = '入金完了';
2031 3230 }
2032 - break;
2033 -//20101018ysk end
2034 -//20140206ysk start
2035 - case 'veritrans_conv':
2036 - if( 'cvsType' == $key ) {
2037 - switch( $value ) {
3231 + } elseif ( 'mf' === $key ) {
3232 + if ( '1' === $value ) {
3233 + $value = 'マッチ';
3234 + } elseif ( '2' === $value ) {
3235 + $value = '過少';
3236 + } elseif ( '3' === $value ) {
3237 + $value = '過剰';
3238 + }
3239 + } elseif ( 'nkd' === $key ) {
3240 + $value = substr( $value, 0, 4 ) . '年' . substr( $value, 4, 2 ) . '月' . substr( $value, 6, 2 ) . '日';
3241 + } elseif ( 'exp' === $key ) {
3242 + $value = substr( $value, 0, 4 ) . '年' . substr( $value, 4, 2 ) . '月' . substr( $value, 6, 2 ) . '日';
3243 + } else {
3244 + continue;
3245 + }
3246 + } elseif ( 'veritrans_conv' === $acting ) {
3247 + if ( 'cvsType' === $key ) {
3248 + switch ( $value ) {
2038 3249 case 'sej':
2039 3250 $value = 'セブン-イレブン';
2040 3251 break;
2041 3252 case 'econ-lw':
@@ -2049,194 +3260,222 @@
2049 3260 break;
2050 3261 case 'econ-other':
2051 3262 $value = 'セイコーマート';
2052 3263 break;
2053 - }
3264 + case 'econ-sn':
3265 + $value = 'サンクス';
3266 + break;
3267 + case 'econ-ck':
3268 + $value = 'サークルK';
3269 + break;
2054 3270 }
2055 - break;
2056 -//20140206ysk end
3271 + }
2057 3272 }
2058 3273 $value = apply_filters( 'usces_filter_settle_info_field_value', $value, $key, $acting );
2059 - switch($type){
3274 + switch ( $type ) {
2060 3275 case 'nl':
2061 3276 $str .= $key . ' : ' . $value . "<br />\n";
2062 3277 break;
2063 -
2064 3278 case 'tr':
2065 3279 $str .= '<tr><td class="label">' . $key . '</td><td>' . $value . "</td></tr>\n";
2066 3280 break;
2067 -
2068 3281 case 'li':
2069 3282 $str .= '<li>' . $key . ' : ' . $value . "</li>\n";
2070 3283 break;
2071 3284 }
2072 3285 }
2073 - if( 'return' == $out){
2074 - return $str;
2075 - }else{
2076 - echo $str;
3286 + if ( 'return' === $out ) {
3287 + return wel_esc_script( $str );
3288 + } else {
3289 + wel_esc_script_e( $str );
2077 3290 }
2078 3291 }
2079 3292
2080 -//20100818ysk start
3293 +/**
3294 + * Custom field
3295 + *
3296 + * @param array $data Order data.
3297 + * @param string $custom_field Custom field.
3298 + * @param string $position Position.
3299 + * @param string $out Return value or echo.
3300 + * @return string|void
3301 + */
2081 3302 function usces_custom_field_input( $data, $custom_field, $position, $out = '' ) {
2082 3303
2083 3304 $html = '';
2084 - switch($custom_field) {
2085 - case 'order':
2086 - $label = 'custom_order';
2087 - $field = 'usces_custom_order_field';
2088 - break;
2089 - case 'customer':
2090 - $label = 'custom_customer';
2091 - $field = 'usces_custom_customer_field';
2092 - break;
2093 - case 'delivery':
2094 - $label = 'custom_delivery';
2095 - $field = 'usces_custom_delivery_field';
2096 - break;
2097 - case 'member':
2098 - $label = 'custom_member';
2099 - $field = 'usces_custom_member_field';
2100 - break;
2101 - default:
2102 - return;
3305 +
3306 + switch ( $custom_field ) {
3307 + case 'order':
3308 + $label = 'custom_order';
3309 + $field = 'usces_custom_order_field';
3310 + break;
3311 + case 'customer':
3312 + $label = 'custom_customer';
3313 + $field = 'usces_custom_customer_field';
3314 + break;
3315 + case 'delivery':
3316 + $label = 'custom_delivery';
3317 + $field = 'usces_custom_delivery_field';
3318 + break;
3319 + case 'member':
3320 + $label = 'custom_member';
3321 + $field = 'usces_custom_member_field';
3322 + break;
3323 + default:
3324 + return;
2103 3325 }
2104 3326
2105 - $meta = usces_has_custom_field_meta($custom_field);
3327 + $meta = usces_has_custom_field_meta( $custom_field );
2106 3328
2107 - if(!empty($meta) and is_array($meta)) {
2108 - foreach($meta as $key => $entry) {
2109 - if($custom_field == 'order' or $entry['position'] == $position) {
2110 - $name = $entry['name'];
2111 - $means = $entry['means'];
2112 - $essential = $entry['essential'];
2113 - $value = '';
2114 - if(is_array($entry['value'])) {
2115 - foreach($entry['value'] as $k => $v) {
2116 - $value .= $v."\n";
3329 + if ( ! empty( $meta ) && is_array( $meta ) ) {
3330 + foreach ( $meta as $key => $entry ) {
3331 + if ( 'order' === $custom_field || $entry['position'] === $position ) {
3332 + $name = $entry['name'];
3333 + $means = (int) $entry['means'];
3334 + $essential = (int) $entry['essential'];
3335 + $value = '';
3336 + if ( is_array( $entry['value'] ) ) {
3337 + foreach ( $entry['value'] as $k => $v ) {
3338 + $value .= $v . "\n";
2117 3339 }
2118 3340 }
2119 - $value = trim($value);
3341 + $value = usces_change_line_break( $value );
2120 3342
2121 - $e = ($essential == 1) ? '<em>' . __('*', 'usces') . '</em>' : '';
3343 + $e = ( 1 === $essential ) ? '<em>' . __( '*', 'usces' ) . '</em>' : '';
2122 3344 $html .= '
2123 3345 <tr class="customkey_' . $key . '">
2124 - <th scope="row">'.$e.esc_html($name).apply_filters('usces_filter_custom_field_input_label', NULL, $key, $entry).'</th>';
2125 - $html .= apply_filters( 'usces_filter_custom_field_input_td', '<td colspan="2">', $key, $entry);
2126 - switch($means) {
2127 - case 0://シングルセレクト
2128 - case 1://マルチセレクト
2129 - $selects = explode("\n", $value);
2130 - $multiple = ($means == 0) ? '' : ' multiple';
2131 - $multiple_array = ($means == 0) ? '' : '[]';
2132 - $html .= '<select name="'.$label.'['.esc_attr($key).']'.$multiple_array.'" class="iopt_select"'.$multiple.'>';
2133 - if($essential == 1)
3346 + <th scope="row">' . $e . esc_html( $name ) . apply_filters( 'usces_filter_custom_field_input_label', null, $key, $entry ) . '</th>';
3347 + $html .= apply_filters( 'usces_filter_custom_field_input_td', '<td colspan="2">', $key, $entry );
3348 + switch ( $means ) {
3349 + case 0: // Single-select.
3350 + case 1: // Multi-select.
3351 + $selects = explode( "\n", $value );
3352 + $multiple = ( 0 === $means ) ? '' : ' multiple';
3353 + $multiple_array = ( 0 === $means ) ? '' : '[]';
3354 + $html .= '<select name="' . $label . '[' . esc_attr( $key ) . ']' . $multiple_array . '" class="iopt_select"' . $multiple . '>';
3355 + if ( 1 === $essential ) {
2134 3356 $html .= '
2135 - <option value="#NONE#">'.__('Choose','usces').'</option>';
2136 - foreach($selects as $v) {
2137 - $selected = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' selected' : '';
2138 - $html .= '
2139 - <option value="'.esc_attr($v).'"'.$selected.'>'.esc_html($v).'</option>';
3357 + <option value="#NONE#">' . __( 'Choose', 'usces' ) . '</option>';
2140 3358 }
3359 + foreach ( (array) $selects as $v ) {
3360 + $selected = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' selected' : '';
3361 + $html .= '
3362 + <option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_html( $v ) . '</option>';
3363 + }
2141 3364 $html .= '
2142 3365 </select>';
2143 3366 break;
2144 - case 2://テキスト
2145 - $text = isset($data[$label][$key]) ? $data[$label][$key] : '';
2146 - $html .= '<input type="text" name="'.$label.'['.esc_attr($key).']" value="'.esc_attr($text).'" />';
3367 + case 2: // Text.
3368 + $text = isset( $data[ $label ][ $key ] ) ? $data[ $label ][ $key ] : '';
3369 + $html .= '<input type="text" name="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_text" value="' . esc_attr( $text ) . '" />';
2147 3370 break;
2148 - case 3://ラジオボタン
2149 - $selects = explode("\n", $value);
2150 - foreach($selects as $v) {
2151 - $checked = ( isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' checked' : '';
2152 - $html .= '
2153 - <label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label"><input type="radio" name="'.$label.'['.esc_attr($key).']" id="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" value="'.esc_attr($v).'"'.$checked.'>'.esc_html($v).'</label>';
3371 + case 3: // Radio-button.
3372 + $selects = explode( "\n", $value );
3373 + foreach ( (array) $selects as $v ) {
3374 + $checked = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' checked' : '';
3375 + $html .= '
3376 + <label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label"><input type="radio" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '>' . esc_html( $v ) . '</label>';
2154 3377 }
2155 3378 break;
2156 - case 4://チェックボックス
2157 - $selects = explode("\n", $value);
2158 - foreach($selects as $v) {
2159 - if( isset($data[$label][$key]) && is_array($data[$label][$key]) ) {
2160 - $checked = (isset($data[$label][$key]) && array_key_exists($v, $data[$label][$key])) ? ' checked' : '';
3379 + case 4: // Check-box.
3380 + $selects = explode( "\n", $value );
3381 + foreach ( $selects as $v ) {
3382 + if ( isset( $data[ $label ][ $key ] ) && is_array( $data[ $label ][ $key ] ) ) {
3383 + $checked = ( isset( $data[ $label ][ $key ] ) && array_key_exists( $v, $data[ $label ][ $key ] ) ) ? ' checked' : '';
2161 3384 } else {
2162 - $checked = (isset($data[$label][$key]) && $data[$label][$key] == $v) ? ' checked' : '';
3385 + $checked = ( isset( $data[ $label ][ $key ] ) && $data[ $label ][ $key ] == $v ) ? ' checked' : '';
2163 3386 }
2164 3387 $html .= '
2165 - <label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label"><input type="checkbox" name="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" id="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" value="'.esc_attr($v).'"'.$checked.'>'.esc_html($v).'</label>';
3388 + <label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label"><input type="checkbox" name="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '>' . esc_html( $v ) . '</label>';
2166 3389 }
2167 3390 break;
3391 + case 5: // Text-area.
3392 + $text = ( isset( $data[ $label ][ $key ] ) ) ? $data[ $label ][ $key ] : '';
3393 + $html .= '<textarea name="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_textarea">' . esc_attr( $text ) . '</textarea>';
3394 + break;
2168 3395 }
2169 - $html .= apply_filters('usces_filter_custom_field_input_value', NULL, $key, $entry).'</td>';
3396 + $html .= apply_filters( 'usces_filter_custom_field_input_value', null, $key, $entry ) . '</td>';
2170 3397 $html .= '
2171 3398 </tr>';
2172 3399 }
2173 3400 }
2174 3401 }
2175 -
2176 - $html = apply_filters('usces_filter_custom_field_input', $html, $data, $custom_field, $position);
2177 3402
2178 - if($out == 'return') {
2179 - return stripslashes($html);
3403 + $html = apply_filters( 'usces_filter_custom_field_input', $html, $data, $custom_field, $position );
3404 +
3405 + if ( 'return' === $out ) {
3406 + return stripslashes( $html );
2180 3407 } else {
2181 - echo stripslashes($html);
3408 + echo stripslashes( $html );
2182 3409 }
2183 3410 }
2184 3411
3412 +/**
3413 + * Custom field information
3414 + *
3415 + * @param array $data Order data.
3416 + * @param string $custom_field Custom field.
3417 + * @param string $position Position.
3418 + * @param string $out Return value or echo.
3419 + * @return string|void
3420 + */
2185 3421 function usces_custom_field_info( $data, $custom_field, $position, $out = '' ) {
2186 3422
2187 3423 $html = '';
2188 - switch($custom_field) {
2189 - case 'order':
2190 - $label = 'custom_order';
2191 - $field = 'usces_custom_order_field';
2192 - break;
2193 - case 'customer':
2194 - $label = 'custom_customer';
2195 - $field = 'usces_custom_customer_field';
2196 - break;
2197 - case 'delivery':
2198 - $label = 'custom_delivery';
2199 - $field = 'usces_custom_delivery_field';
2200 - break;
2201 - case 'member':
2202 - $label = 'custom_member';
2203 - $field = 'usces_custom_member_field';
2204 - break;
2205 - default:
2206 - return;
3424 + switch ( $custom_field ) {
3425 + case 'order':
3426 + $label = 'custom_order';
3427 + $field = 'usces_custom_order_field';
3428 + break;
3429 + case 'customer':
3430 + $label = 'custom_customer';
3431 + $field = 'usces_custom_customer_field';
3432 + break;
3433 + case 'delivery':
3434 + $label = 'custom_delivery';
3435 + $field = 'usces_custom_delivery_field';
3436 + break;
3437 + case 'member':
3438 + $label = 'custom_member';
3439 + $field = 'usces_custom_member_field';
3440 + break;
3441 + default:
3442 + return;
2207 3443 }
2208 3444
2209 - $meta = usces_has_custom_field_meta($custom_field);
3445 + $meta = usces_has_custom_field_meta( $custom_field );
2210 3446
2211 - if(!empty($meta) and is_array($meta)) {
2212 - foreach($meta as $key => $entry) {
2213 - if($custom_field == 'order' or $entry['position'] == $position) {
2214 - $name = $entry['name'];
2215 - $means = $entry['means'];
3447 + if ( ! empty( $meta ) && is_array( $meta ) ) {
3448 + foreach ( $meta as $key => $entry ) {
3449 + if ( 'order' === $custom_field || $entry['position'] === $position ) {
3450 + $name = $entry['name'];
3451 + $means = (int) $entry['means'];
2216 3452
2217 3453 $html .= '<tr>
2218 - <th>'.esc_html($name).'</th>
3454 + <th>' . esc_html( $name ) . '</th>
2219 3455 <td>';
2220 - if(!empty($data[$label][$key])) {
2221 - switch($means) {
2222 - case 0://シングルセレクト
2223 - case 2://テキスト
2224 - case 3://ラジオボタン
2225 - $html .= esc_html($data[$label][$key]);
2226 - break;
2227 - case 1://マルチセレクト
2228 - case 4://チェックボックス
2229 - if(is_array($data[$label][$key])) {
2230 - $c = '';
2231 - foreach($data[$label][$key] as $v) {
2232 - $html .= $c.esc_html($v);
2233 - $c = ', ';
3456 + if ( ! empty( $data[ $label ][ $key ] ) ) {
3457 + switch ( $means ) {
3458 + case 0: // Single-select.
3459 + case 2: // Text.
3460 + case 3: // Radio-button.
3461 + case 5: // Text-area.
3462 + $html .= esc_html( $data[ $label ][ $key ] );
3463 + break;
3464 + case 1: // Multi-select.
3465 + case 4: // Check-box.
3466 + if ( is_array( $data[ $label ][ $key ] ) ) {
3467 + $c = '';
3468 + foreach ( $data[ $label ][ $key ] as $v ) {
3469 + $html .= $c . esc_html( $v );
3470 + $c = ', ';
3471 + }
3472 + } else {
3473 + if ( ! empty( $data[ $label ][ $key ] ) ) {
3474 + $html .= esc_html( $data[ $label ][ $key ] );
3475 + }
2234 3476 }
2235 - } else {
2236 - if(!empty($data[$label][$key])) $html .= esc_html($data[$label][$key]);
2237 - }
2238 - break;
3477 + break;
2239 3478 }
2240 3479 }
2241 3480 $html .= '
2242 3481 </td>
@@ -2244,151 +3483,173 @@
2244 3483 }
2245 3484 }
2246 3485 }
2247 3486
2248 - $html = apply_filters('usces_filter_custom_field_info', $html, $data, $custom_field, $position);
3487 + $html = apply_filters( 'usces_filter_custom_field_info', $html, $data, $custom_field, $position );
2249 3488
2250 - if($out == 'return') {
2251 - return stripslashes($html);
3489 + if ( 'return' === $out ) {
3490 + return stripslashes( $html );
2252 3491 } else {
2253 - echo stripslashes($html);
3492 + echo stripslashes( $html );
2254 3493 }
2255 3494 }
2256 3495
3496 +/**
3497 + * Admin Custom field
3498 + *
3499 + * @param array $meta Order meta data.
3500 + * @param string $custom_field Custom field.
3501 + * @param string $position Position.
3502 + * @param string $out Return value or echo.
3503 + * @return string|void
3504 + */
2257 3505 function usces_admin_custom_field_input( $meta, $custom_field, $position, $out = '' ) {
2258 3506
2259 3507 $html = '';
2260 - switch($custom_field) {
2261 - case 'order':
2262 - $label = 'custom_order';
2263 - $class = '';
2264 - break;
2265 - case 'customer':
2266 - $label = 'custom_customer';
2267 - $class = ' class="col2"';
2268 - break;
2269 - case 'delivery':
2270 - $label = 'custom_delivery';
2271 - $class = ' class="col3"';
2272 - break;
2273 - case 'member':
2274 - $label = 'custom_member';
2275 - $class = '';
2276 - break;
2277 - default:
2278 - return;
3508 + switch ( $custom_field ) {
3509 + case 'order':
3510 + $label = 'custom_order';
3511 + $class = '';
3512 + break;
3513 + case 'customer':
3514 + $label = 'custom_customer';
3515 + $class = ' class="col2"';
3516 + break;
3517 + case 'delivery':
3518 + $label = 'custom_delivery';
3519 + $class = ' class="col3"';
3520 + break;
3521 + case 'member':
3522 + $label = 'custom_member';
3523 + $class = '';
3524 + break;
3525 + case 'admin_member':
3526 + $label = 'admin_custom_member';
3527 + $class = '';
3528 + break;
3529 + default:
3530 + return;
2279 3531 }
2280 3532
2281 -
2282 - if(!empty($meta) and is_array($meta)) {
2283 - foreach($meta as $key => $entry) {
2284 - if($custom_field == 'order' or $entry['position'] == $position) {
2285 - $name = $entry['name'];
2286 - $means = $entry['means'];
2287 - $essential = $entry['essential'];
2288 - $value = '';
2289 - if(is_array($entry['value'])) {
2290 - foreach($entry['value'] as $k => $v) {
2291 - $value .= $v."\n";
3533 + if ( ! empty( $meta ) && is_array( $meta ) ) {
3534 + foreach ( $meta as $key => $entry ) {
3535 + if ( 'order' === $custom_field || $entry['position'] === $position ) {
3536 + $name = $entry['name'];
3537 + $means = (int) $entry['means'];
3538 + $essential = (int) $entry['essential'];
3539 + $value = '';
3540 + if ( is_array( $entry['value'] ) ) {
3541 + foreach ( $entry['value'] as $k => $v ) {
3542 + $value .= $v . "\n";
2292 3543 }
2293 3544 }
2294 - $value = trim($value);
2295 - $data = $entry['data'];
3545 + $value = usces_change_line_break( $value );
3546 + $value = apply_filters( 'usces_filter_admin_custom_field_input_value', $value, $key, $entry, $custom_field );
3547 + $data = ( isset( $entry['data'] ) ) ? $entry['data'] : null;
2296 3548
2297 3549 $html .= '
2298 3550 <tr>
2299 - <td class="label">'.esc_html($name).'</td>';
2300 - switch($means) {
2301 - case 0://シングルセレクト
2302 - case 1://マルチセレクト
2303 - $selects = explode("\n", $value);
2304 - $multiple = ($means == 0) ? '' : ' multiple';
2305 - $multiple_array = ($means == 0) ? '' : '[]';
2306 - $html .= '
2307 - <td'.$class.'>
2308 - <select name="'.$label.'['.esc_attr($key).']'.$multiple_array.'" id="'.$label.'['.esc_attr($key).']" class="iopt_select"'.$multiple.'>';
2309 - if($essential == 1)
3551 + <td class="label">' . esc_html( $name ) . '</td>';
3552 + switch ( $means ) {
3553 + case 0: /* Single-select */
3554 + case 1: /* Multi-select */
3555 + $selects = explode( "\n", $value );
3556 + $multiple = ( 0 === $means ) ? '' : ' multiple';
3557 + $multiple_array = ( 0 === $means ) ? '' : '[]';
3558 + $html .= '
3559 + <td' . $class . '>
3560 + <select name="' . $label . '[' . esc_attr( $key ) . ']' . $multiple_array . '" id="' . $label . '[' . esc_attr( $key ) . ']" class="iopt_select"' . $multiple . '>';
3561 + if ( 1 === $essential ) {
3562 + $html .= '
3563 + <option value="#NONE#">' . __( 'Choose', 'usces' ) . '</option>';
3564 + }
3565 + foreach ( $selects as $v ) {
3566 + $selected = ( $data == $v ) ? ' selected' : '';
3567 + $html .= '
3568 + <option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_html( $v ) . '</option>';
3569 + }
2310 3570 $html .= '
2311 - <option value="#NONE#">'.__('Choose','usces').'</option>';
2312 - foreach($selects as $v) {
2313 - $selected = ($data == $v) ? ' selected' : '';
3571 + </select></td>';
3572 + break;
3573 + case 2: /* Text */
2314 3574 $html .= '
2315 - <option value="'.esc_attr($v).'"'.$selected.'>'.esc_html($v).'</option>';
2316 - }
2317 - $html .= '
2318 - </select></td>';
2319 - break;
2320 - case 2://テキスト
2321 - $html .= '
2322 - <td'.$class.'><input type="text" name="'.$label.'['.esc_attr($key).']" id="'.$label.'['.esc_attr($key).']" size="30" value="'.esc_attr($data).'" /></td>';
2323 - break;
2324 - case 3://ラジオボタン
2325 - $selects = explode("\n", $value);
2326 - $html .= '
2327 - <td'.$class.'>';
2328 - foreach($selects as $v) {
2329 - $checked = ($data == $v) ? ' checked' : '';
3575 + <td' . $class . '><input type="text" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . ']" size="30" value="' . esc_attr( $data ) . '" /></td>';
3576 + break;
3577 + case 3: /* Radio-button */
3578 + $selects = explode( "\n", $value );
3579 + $html .= '
3580 + <td' . $class . '>';
3581 + foreach ( $selects as $v ) {
3582 + $checked = ( $data == $v ) ? ' checked' : '';
3583 + $html .= '
3584 + <input type="radio" name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '><label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label">' . esc_html( $v ) . '</label>';
3585 + }
2330 3586 $html .= '
2331 - <input type="radio" name="'.$label.'['.esc_attr($key).']" value="'.esc_attr($v).'"'.$checked.'><label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label">'.esc_html($v).'</label>';
2332 - }
2333 - $html .= '
2334 - </td>';
2335 - break;
2336 - case 4://チェックボックス
2337 - $selects = explode("\n", $value);
2338 - $html .= '
2339 - <td'.$class.'>';
2340 - foreach($selects as $v) {
2341 - if(is_array($data)) {
2342 - $checked = (array_key_exists($v, $data)) ? ' checked' : '';
2343 - } else {
2344 - $checked = ($data == $v) ? ' checked' : '';
3587 + </td>';
3588 + break;
3589 + case 4: /* Check-box */
3590 + $selects = explode( "\n", $value );
3591 + $html .= '
3592 + <td' . $class . '>';
3593 + foreach ( $selects as $v ) {
3594 + if ( is_array( $data ) ) {
3595 + $checked = ( array_key_exists( $v, $data ) ) ? ' checked' : '';
3596 + } else {
3597 + $checked = ( $data == $v ) ? ' checked' : '';
3598 + }
3599 + $html .= '
3600 + <input type="checkbox" name="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" id="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" value="' . esc_attr( $v ) . '"' . $checked . '><label for="' . $label . '[' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" class="iopt_label">' . esc_html( $v ) . '</label>';
2345 3601 }
2346 3602 $html .= '
2347 - <input type="checkbox" name="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" value="'.esc_attr($v).'"'.$checked.'><label for="'.$label.'['.esc_attr($key).']['.esc_attr($v).']" class="iopt_label">'.esc_html($v).'</label>';
2348 - }
2349 - $html .= '
2350 - </td>';
2351 - break;
3603 + </td>';
3604 + break;
3605 + case 5: /* Text-area */
3606 + $html .= '
3607 + <td' . $class . '><textarea name="' . $label . '[' . esc_attr( $key ) . ']" id="' . $label . '[' . esc_attr( $key ) . ']" >' . esc_attr( $data ) . '</textarea></td>';
3608 + break;
2352 3609 }
2353 3610 $html .= '
2354 3611 </tr>';
2355 3612 }
2356 -
2357 3613 }
2358 3614 }
2359 - $html = apply_filters( 'usces_filter_admin_custom_field_input', $html, $meta, $custom_field, $position, $out );
3615 + $html = apply_filters( 'usces_filter_admin_custom_field_input', $html, $meta, $custom_field, $position, $out );
2360 3616
2361 - if($out == 'return') {
2362 - return stripslashes($html);
3617 + if ( 'return' === $out ) {
3618 + return stripslashes( $html );
2363 3619 } else {
2364 - echo stripslashes($html);
3620 + echo stripslashes( $html );
2365 3621 }
2366 3622 }
2367 3623
3624 +/**
3625 + * Required Custom Field
3626 + *
3627 + * @return string
3628 + */
2368 3629 function has_custom_customer_field_essential() {
2369 3630
2370 - $mes = '';
3631 + $mes = '';
2371 3632 $essential = array();
2372 3633
2373 - $csmb_meta = usces_has_custom_field_meta('member');
2374 - if(!empty($csmb_meta) and is_array($csmb_meta)) {
2375 - foreach($csmb_meta as $key => $entry) {
2376 - if($entry['essential'] == 1) {
2377 - $essential[$key] = $key;
3634 + $csmb_meta = usces_has_custom_field_meta( 'member' );
3635 + if ( ! empty( $csmb_meta ) && is_array( $csmb_meta ) ) {
3636 + foreach ( $csmb_meta as $key => $entry ) {
3637 + if ( 1 === (int) $entry['essential'] ) {
3638 + $essential[ $key ] = $key;
2378 3639 }
2379 3640 }
2380 3641 }
2381 - if(!empty($essential)) {
2382 - $cscs_meta = usces_has_custom_field_meta('customer');
2383 - if(!empty($cscs_meta) and is_array($cscs_meta)) {
2384 - foreach($cscs_meta as $key => $entry) {
2385 - if($entry['essential'] == 1) {
2386 - if(!array_key_exists($key, $essential)) {
2387 - if($entry['means'] == 2) {//Text
2388 - $mes .= sprintf(__("Input the %s", 'usces'), esc_html($entry['name']))."<br />";
3642 + if ( ! empty( $essential ) ) {
3643 + $cscs_meta = usces_has_custom_field_meta( 'customer' );
3644 + if ( ! empty( $cscs_meta ) && is_array( $cscs_meta ) ) {
3645 + foreach ( $cscs_meta as $key => $entry ) {
3646 + if ( 1 === (int) $entry['essential'] ) {
3647 + if ( ! array_key_exists( $key, $essential ) ) {
3648 + if ( 2 === (int) $entry['means'] ) { // Text.
3649 + $mes .= sprintf( __( "Input the %s", 'usces' ), esc_html( $entry['name'] ) ) . '<br />';
2389 3650 } else {
2390 - $mes .= sprintf(__("Chose the %s", 'usces'), esc_html($entry['name']))."<br />";
3651 + $mes .= sprintf( __( "Chose the %s", 'usces' ), esc_html( $entry['name'] ) ) . '<br />';
2391 3652 }
2392 3653 }
2393 3654 }
2394 3655 }
@@ -2395,973 +3656,1713 @@
2395 3656 }
2396 3657 }
2397 3658 return $mes;
2398 3659 }
2399 -//20100818ysk end
2400 3660
2401 -function usces_order_discount( $out = '' ){
3661 +/**
3662 + * Discount
3663 + *
3664 + * @param string $out Return value or echo.
3665 + * @return string|void
3666 + */
3667 +function usces_order_discount( $out = '' ) {
2402 3668 global $usces;
2403 - $res = abs($usces->get_order_discount());
2404 -
2405 - if($out == 'return') {
3669 +
3670 + $res = abs( $usces->get_order_discount() );
3671 +
3672 + if ( 'return' === $out ) {
2406 3673 return $res;
2407 3674 } else {
2408 - echo number_format($res);
3675 + echo number_format( $res );
2409 3676 }
2410 3677 }
2411 3678
2412 -function usces_item_discount( $out = '', $post_id = '', $sku = '' ){
3679 +/**
3680 + * Item discount
3681 + *
3682 + * @param string $out Return value or echo.
3683 + * @param int $post_id Post ID.
3684 + * @param string $sku SKU code.
3685 + * @return string|void
3686 + */
3687 +function usces_item_discount( $out = '', $post_id = '', $sku = '' ) {
2413 3688 global $usces, $post;
2414 -
2415 - if( '' == $post_id )
3689 +
3690 + if ( '' === $post_id ) {
2416 3691 $post_id = $post->ID;
2417 - if( '' == $sku )
3692 + }
3693 + if ( '' === $sku ) {
2418 3694 $sku = $usces->itemsku['code'];
2419 -
2420 - $res = $usces->getItemDiscount($post_id, $sku);
2421 -
2422 - if($out == 'return') {
3695 + }
3696 + $res = $usces->getItemDiscount( $post_id, $sku );
3697 +
3698 + if ( 'return' === $out ) {
2423 3699 return $res;
2424 3700 } else {
2425 - echo number_format($res);
3701 + echo number_format( $res );
2426 3702 }
2427 3703 }
2428 3704
2429 -function usces_singleitem_error_message($post_id, $skukey, $out = ''){
2430 - if( !isset($_SESSION['usces_singleitem']['error_message'][$post_id][$skukey]) )
3705 +/**
3706 + * Item page error message
3707 + *
3708 + * @param int $post_id Post ID.
3709 + * @param string $skukey SKU code.
3710 + * @param string $out Return value or echo.
3711 + * @return string|void
3712 + */
3713 +function usces_singleitem_error_message( $post_id, $skukey, $out = '' ) {
3714 + if ( ! isset( $_SESSION['usces_singleitem']['error_message'][ $post_id ][ $skukey ] ) ) {
2431 3715 $ret = '';
2432 - else
2433 - $ret = $_SESSION['usces_singleitem']['error_message'][$post_id][$skukey];
2434 -
2435 - if($out == 'return') {
2436 - return $ret;
2437 3716 } else {
2438 - echo $ret;
3717 + $ret = $_SESSION['usces_singleitem']['error_message'][ $post_id ][ $skukey ];
2439 3718 }
3719 + if ( 'return' === $out ) {
3720 + return wel_esc_script( $ret );
3721 + } else {
3722 + wel_esc_script_e( $ret );
3723 + }
2440 3724 }
2441 3725
3726 +/**
3727 + * Amount Formatting
3728 + *
3729 + * @param float $float Price.
3730 + * @param bool $symbol_pre Forward symbol.
3731 + * @param bool $symbol_post Backward symbol.
3732 + * @param string $out Return value or echo.
3733 + * @param bool $seperator_flag Seperator.
3734 + * @return string|void
3735 + */
2442 3736 function usces_crform( $float, $symbol_pre = true, $symbol_post = true, $out = '', $seperator_flag = true ) {
2443 3737 global $usces;
2444 - $price = esc_html($usces->get_currency($float, $symbol_pre, $symbol_post, $seperator_flag ));
2445 - $res = apply_filters('usces_filter_crform', $price, $float);
2446 -
2447 - if($out == 'return'){
3738 +
3739 + $price = esc_html( $usces->get_currency( $float, $symbol_pre, $symbol_post, $seperator_flag ) );
3740 + $res = apply_filters( 'usces_filter_crform', $price, $float );
3741 +
3742 + if ( 'return' === $out ) {
2448 3743 return $res;
2449 - }else{
2450 - echo $res;
3744 + } else {
3745 + echo $res; // no escape due to filter.
2451 3746 }
2452 3747 }
2453 3748
2454 -function usces_memberinfo( $key, $out = '' ){
3749 +/**
3750 + * Member Information
3751 + *
3752 + * @param string $key Key.
3753 + * @param string $out Return value or echo.
3754 + * @return string|void
3755 + */
3756 +function usces_memberinfo( $key, $out = '' ) {
2455 3757 global $usces, $wpdb;
3758 +
2456 3759 $info = $usces->get_member();
2457 3760
2458 - if( empty($key) ) return $info;
2459 -
2460 - switch ($key){
3761 + if ( empty( $key ) ) {
3762 + return $info;
3763 + }
3764 +
3765 + switch ( $key ) {
2461 3766 case 'registered':
2462 - $res = mysql2date(__('Mj, Y', 'usces'), $info['registered']);
3767 + $res = mysql2date( __( 'Mj, Y', 'usces' ), $info['registered'] );
2463 3768 break;
2464 -//20120919ysk start 0000573
2465 3769 case 'point':
2466 - $member_table = $wpdb->prefix."usces_member";
2467 - $query = $wpdb->prepare("SELECT mem_point FROM $member_table WHERE ID = %d", $info['ID']);
2468 - $res = $wpdb->get_var( $query );
3770 + $member_table = usces_get_tablename( 'usces_member' );
3771 + $query = $wpdb->prepare( "SELECT mem_point FROM $member_table WHERE ID = %d", $info['ID'] );
3772 + $res = $wpdb->get_var( $query );
2469 3773 break;
2470 -//20120919ysk end
2471 3774 default:
2472 - $res = isset($info[$key]) ? $info[$key] : '';
3775 + $res = isset( $info[ $key ] ) ? $info[ $key ] : '';
2473 3776 }
2474 -
2475 - if($out == 'return'){
2476 - return $res;
2477 - }else{
2478 - echo esc_html($res);
2479 - }
2480 -}
2481 3777
2482 -function usces_localized_name( $Familly_name, $Given_name, $out = '' ){
2483 - global $usces_settings, $usces;
2484 -
2485 - $options = get_option('usces');
2486 - $form = $options['system']['addressform'];
2487 - if( $usces_settings['nameform'][$form] ){
2488 - $res = $Given_name . ' ' . $Familly_name;
2489 - }else{
2490 - $res = $Familly_name . ' ' . $Given_name;
2491 - }
2492 -
2493 - if($out == 'return'){
3778 + if ( 'return' === $out ) {
2494 3779 return $res;
2495 - }else{
2496 - echo esc_html($res);
3780 + } else {
3781 + echo esc_html( $res );
2497 3782 }
2498 3783 }
2499 3784
2500 -function usces_member_history( $out = '' ){
3785 +/**
3786 + * Member Purchase History
3787 + *
3788 + * @param string $out Return value or echo.
3789 + * @return string|void
3790 + */
3791 +function usces_member_history( $out = '' ) {
2501 3792 global $usces;
2502 -
2503 - $usces_members = $usces->get_member();
2504 - $usces_member_history = $usces->get_member_history($usces_members['ID']);
2505 - $colspan = usces_is_membersystem_point() ? 9 : 7;
2506 3793
2507 - $html = '<div class="history-area">
2508 - <table>';
2509 - if ( !count($usces_member_history) ) {
2510 - $html .= '<tr>
2511 - <td>' . __('There is no purchase history for this moment.', 'usces') . '</td>
2512 - </tr>';
2513 - }
2514 - foreach ( $usces_member_history as $umhs ) {
2515 - $cart = $umhs['cart'];
2516 - $history_member_head = '<tr>
2517 - <th class="historyrow">' . __('Order number', 'usces') . '</th>
2518 - <th class="historyrow">' . __('Purchase date', 'usces') . '</th>
2519 - <th class="historyrow">' . __('Purchase price', 'usces') . '</th>';
2520 - if( usces_is_membersystem_point() ){
2521 - $history_member_head .= '<th class="historyrow">' . __('Used points', 'usces') . '</th>';
2522 - }
2523 - $history_member_head .= '<th class="historyrow">' . apply_filters( 'usces_member_discount_label', __('Special Price', 'usces'), $umhs['ID'] ) . '</th>
2524 - <th class="historyrow">' . __('Shipping', 'usces') . '</th>
2525 - <th class="historyrow">' . __('C.O.D', 'usces') . '</th>
2526 - <th class="historyrow">' . __('consumption tax', 'usces') . '</th>';
2527 - if( usces_is_membersystem_point() ){
2528 - $history_member_head .= '<th class="historyrow">' . __('Acquired points', 'usces') . '</th>';
2529 - }
2530 - $history_member_head .= '</tr>
2531 - <tr>
2532 - <td class="rightnum">' . usces_get_deco_order_id($umhs['ID']) . '</td>
2533 - <td class="date">' . $umhs['date'] . '</td>
2534 - <td class="rightnum">' . usces_crform(($usces->get_total_price($cart)-$umhs['usedpoint']+$umhs['discount']+$umhs['shipping_charge']+$umhs['cod_fee']+$umhs['tax']), true, false, 'return') . '</td>';
2535 - if( usces_is_membersystem_point() ){
2536 - $history_member_head .= '<td class="rightnum">' . number_format($umhs['usedpoint']) . '</td>';
2537 - }
2538 - $history_member_head .= '<td class="rightnum">' . usces_crform($umhs['discount'], true, false, 'return') . '</td>
2539 - <td class="rightnum">' . usces_crform($umhs['shipping_charge'], true, false, 'return') . '</td>
2540 - <td class="rightnum">' . usces_crform($umhs['cod_fee'], true, false, 'return') . '</td>
2541 - <td class="rightnum">' . usces_crform($umhs['tax'], true, false, 'return') . '</td>';
2542 - if( usces_is_membersystem_point() ){
2543 - $history_member_head .= '<td class="rightnum">' . number_format($umhs['getpoint']) . '</td>';
2544 - }
2545 - $history_member_head .= '</tr>';
2546 - $html .= apply_filters( 'usces_filter_history_member_head', $history_member_head, $umhs );
2547 - $html .= apply_filters('usces_filter_member_history_header', NULL, $umhs);
2548 - $html .= '<tr>
2549 - <td class="retail" colspan="' . $colspan . '">
2550 - <table id="retail_table_' . $umhs['ID'] . '" class="retail">';
2551 - $history_cart_head = '<tr>
2552 - <th scope="row" class="num">No.</th>
2553 - <th class="thumbnail">&nbsp;</th>
2554 - <th>' . __('Items', 'usces') . '</th>
2555 - <th class="price ">' . __('Unit price', 'usces') . '</th>
2556 - <th class="quantity">' . __('Quantity', 'usces') . '</th>
2557 - <th class="subtotal">' . __('Amount', 'usces') . '</th>
2558 - </tr>';
2559 - $html .= apply_filters('usces_filter_history_cart_head', $history_cart_head, $umhs);
2560 -
2561 - for($i=0; $i<count($cart); $i++) {
2562 - $cart_row = $cart[$i];
2563 - $ordercart_id = $cart_row['cart_id'];
2564 - $post_id = $cart_row['post_id'];
2565 - $sku = urldecode($cart_row['sku']);
2566 - $quantity = $cart_row['quantity'];
2567 - $options = $cart_row['options'];
2568 - //$options = usces_get_ordercart_meta_value( 'option', $ordercart_id );
2569 - //$options = usces_get_ordercart_meta( 'option', $ordercart_id );
2570 - $itemCode = $usces->getItemCode($post_id);
2571 - $itemName = $usces->getItemName($post_id);
2572 - $cartItemName = $usces->getCartItemName($post_id, $sku);
2573 - //$skuPrice = $usces->getItemPrice($post_id, $sku);
2574 - $skuPrice = $cart_row['price'];
2575 - $pictid = (int)$usces->get_mainpictid($itemCode);
2576 - $optstr = '';
2577 - if( is_array($options) && count($options) > 0 ){
2578 - $optstr = '';
2579 - foreach($options as $key => $value){
2580 - if( !empty($key) ) {
2581 - $key = urldecode($key);
2582 - $value = maybe_unserialize($value);
2583 - if(is_array($value)) {
2584 - $c = '';
2585 - $optstr .= esc_html($key) . ' : ';
2586 - foreach($value as $v) {
2587 - $optstr .= $c.nl2br(esc_html(urldecode($v)));
2588 - $c = ', ';
3794 + $usces_members = $usces->get_member();
3795 + $history = $usces->get_member_history( $usces_members['ID'], true );
3796 + $usces_member_history = apply_filters( 'usces_filter_get_member_history', $history, $usces_members['ID'] );
3797 +
3798 + $usces_member_history_count = ( $usces_member_history && is_array( $usces_member_history ) ) ? count( $usces_member_history ) : 0;
3799 +
3800 + $html = usces_load_filter_purchase_date();
3801 + $html .= '<div class="history-area">';
3802 + if ( 0 === $usces_member_history_count ) {
3803 + $no_history_message = apply_filters( 'usces_filter_no_history_message', __( 'There is no purchase history during the period.', 'usces' ) );
3804 + $html .= '<table id="history_head"><tr>
3805 + <td>' . $no_history_message . '</td>
3806 + </tr></table>';
3807 + } else {
3808 + $management_status = apply_filters( 'usces_filter_management_status', get_option( 'usces_management_status' ) );
3809 + foreach ( $usces_member_history as $umhs ) {
3810 + $condition = $umhs['condition'];
3811 + $tax_display = ( isset( $condition['tax_display'] ) ) ? $condition['tax_display'] : usces_get_tax_display();
3812 + $tax_mode = ( isset( $condition['tax_mode'] ) ) ? $condition['tax_mode'] : usces_get_tax_mode();
3813 + $tax_target = ( isset( $condition['tax_target'] ) ) ? $condition['tax_target'] : usces_get_tax_target();
3814 + $tax_label = ( 'exclude' === $tax_mode ) ? __( 'consumption tax', 'usces' ) : __( 'Internal tax', 'usces' );
3815 + $member_system_point = ( isset( $condition['membersystem_point'] ) && 'activate' === $condition['membersystem_point'] ) ? true : usces_is_membersystem_point();
3816 + $point_coverage = ( isset( $condition['point_coverage'] ) ) ? (int) $condition['point_coverage'] : (int) usces_point_coverage();
3817 + $cart = $umhs['cart'];
3818 + $value = $umhs['order_status'];
3819 +
3820 + $p_status = '';
3821 + if ( $usces->is_status( 'duringorder', $value ) ) {
3822 + $p_status = isset( $management_status['duringorder'] ) ? esc_html( $management_status['duringorder'] ) : '';
3823 + } elseif ( $usces->is_status( 'cancel', $value ) ) {
3824 + $p_status = isset( $management_status['cancel'] ) ? esc_html( $management_status['cancel'] ) : '';
3825 + } elseif ( $usces->is_status( 'completion', $value ) ) {
3826 + $p_status = isset( $management_status['completion'] ) ? esc_html( $management_status['completion'] ) : '';
3827 + } else {
3828 + $p_status = esc_html( __( 'new order', 'usces' ) );
3829 + }
3830 + $p_status = apply_filters( 'usces_filter_orderlist_process_status', $p_status, $value, $management_status, $umhs['ID'] );
3831 +
3832 + $r_status = '';
3833 + if ( $usces->is_status( 'noreceipt', $value ) ) {
3834 + $r_status = isset( $management_status['noreceipt'] ) ? esc_html( $management_status['noreceipt'] ) : '';
3835 + } elseif ( $usces->is_status( 'pending', $value ) ) {
3836 + $r_status = isset( $management_status['pending'] ) ? esc_html( $management_status['pending'] ) : '';
3837 + } elseif ( $usces->is_status( 'receipted', $value ) ) {
3838 + $r_status = isset( $management_status['receipted'] ) ? esc_html( $management_status['receipted'] ) : '';
3839 + }
3840 + $r_status = apply_filters( 'usces_filter_orderlist_receipt_status', $r_status, $value, $management_status, $umhs['ID'] );
3841 +
3842 + $shipping = usces_have_shipped( $cart );
3843 + $delivery_company = '';
3844 + $tracking_number = '';
3845 + $delivery_company_url = '';
3846 + if ( $shipping ) {
3847 + $tracking_number = $usces->get_order_meta_value( apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' ), $umhs['ID'] );
3848 + $delivery_company = $usces->get_order_meta_value( 'delivery_company', $umhs['ID'] );
3849 + $delivery_company_url = usces_get_delivery_company_url( $delivery_company, $tracking_number );
3850 + }
3851 +
3852 + $head_col = 4;
3853 + $history_member_head = '<table id="history_head"><thead>
3854 + <tr class="order_head_label">
3855 + <th class="historyrow order_number">' . __( 'Order number', 'usces' ) . '</th>
3856 + <th class="historyrow purchase_date">' . __( 'Purchase date', 'usces' ) . '</th>';
3857 + if ( ! empty( $p_status ) ) {
3858 + $history_member_head .= '<th class="historyrow processing_status">' . __( 'Processing status', 'usces' ) . '</th>';
3859 + $head_col++;
3860 + }
3861 + if ( ! empty( $r_status ) ) {
3862 + $history_member_head .= '<th class="historyrow transfer_statement">' . __( 'transfer statement', 'usces' ) . '</th>';
3863 + $head_col++;
3864 + }
3865 + $history_member_head .= '<th class="historyrow purchase_price">' . __( 'Purchase price', 'usces' ) . '</th>
3866 + <th class="historyrow discount">' . apply_filters( 'usces_member_discount_label', __( 'Discount', 'usces' ), $umhs['ID'] ) . '</th>';
3867 + if ( $tax_display && 'products' === $tax_target ) {
3868 + $history_member_head .= '<th class="historyrow tax">' . $tax_label . '</th>';
3869 + $head_col++;
3870 + }
3871 + if ( $member_system_point && 0 === $point_coverage ) {
3872 + $history_member_head .= '<th class="historyrow used_point">' . __( 'Used points', 'usces' ) . '</th>';
3873 + $head_col++;
3874 + }
3875 + if ( $shipping ) {
3876 + $history_member_head .= '<th class="historyrow shipping">' . __( 'Shipping', 'usces' ) . '</th>';
3877 + $head_col++;
3878 + }
3879 + if ( ! empty( $umhs['cod_fee'] ) ) {
3880 + $payment = usces_get_payments_by_name( $umhs['payment_name'] );
3881 + $cod_label = ( isset( $payment['settlement'] ) && 'COD' === $payment['settlement'] ) ? __( 'C.O.D', 'usces' ) : __( 'Fee', 'usces' );
3882 + $cod_label = apply_filters( 'usces_filter_member_history_cod_label', $cod_label, $umhs['ID'] );
3883 + $history_member_head .= '<th class="historyrow cod">' . $cod_label . '</th>';
3884 + $head_col++;
3885 + }
3886 + if ( $tax_display && 'all' === $tax_target ) {
3887 + $history_member_head .= '<th class="historyrow tax">' . $tax_label . '</th>';
3888 + $head_col++;
3889 + }
3890 + if ( $member_system_point && 1 === $point_coverage ) {
3891 + $history_member_head .= '<th class="historyrow used_point">' . __( 'Used points', 'usces' ) . '</th>';
3892 + $head_col++;
3893 + }
3894 + if ( $member_system_point ) {
3895 + $history_member_head .= '<th class="historyrow get_point">' . __( 'Acquired points', 'usces' ) . '</th>';
3896 + $head_col++;
3897 + }
3898 + if ( ! empty( $tracking_number ) ) {
3899 + $history_member_head .= '<th class="historyrow">' . __( 'Tracking number', 'usces' ) . '</th>';
3900 + $head_col++;
3901 + }
3902 + $total_price = $umhs['total_items_price'] - $umhs['usedpoint'] + $umhs['discount'] + $umhs['shipping_charge'] + $umhs['cod_fee'] + $umhs['tax'];
3903 + if ( $total_price < 0 ) {
3904 + $total_price = 0;
3905 + }
3906 + $history_member_head .= '</tr></thead>
3907 + <tbody>
3908 + <tr class="order_head_value">
3909 + <td class="order_number" data-label="' . __( 'Order number', 'usces' ) . '">' . usces_get_deco_order_id( $umhs['ID'] ) . '</td>
3910 + <td class="date purchase_date" data-label="' . __( 'Purchase date', 'usces' ) . '">' . $umhs['date'] . '</td>';
3911 + if ( ! empty( $p_status ) ) {
3912 + $history_member_head .= '<td class="rightnum" data-label="' . __( 'Processing status', 'usces' ) . '">' . $p_status . '</td>';
3913 + }
3914 + if ( ! empty( $r_status ) ) {
3915 + $history_member_head .= '<td class="rightnum" data-label="' . __( 'transfer statement', 'usces' ) . '">' . $r_status . '</td>';
3916 + }
3917 + $history_member_head .= '<td class="rightnum purchase_price" data-label="' . __( 'Purchase price', 'usces' ) . '">' . usces_crform( $total_price, true, false, 'return' ) . '</td>
3918 + <td class="rightnum discount" data-label="' . apply_filters( 'usces_filter_discount_label', __( 'Discount', 'usces' ) ) . '">' . usces_crform( $umhs['discount'], true, false, 'return' ) . '</td>';
3919 + if ( $tax_display && 'products' === $tax_target ) {
3920 + $history_member_head .= '<td class="rightnum tax" data-label="' . $tax_label . '">' . usces_order_history_tax( $umhs, $tax_mode ) . '</td>';
3921 + }
3922 + if ( $member_system_point && 0 === $point_coverage ) {
3923 + $history_member_head .= '<td class="rightnum used_point" data-label="' . __( 'Used points', 'usces' ) . '">' . number_format( $umhs['usedpoint'] ) . '</td>';
3924 + }
3925 + if ( $shipping ) {
3926 + $history_member_head .= '<td class="rightnum shipping" data-label="' . __( 'Shipping', 'usces' ) . '">' . usces_crform( $umhs['shipping_charge'], true, false, 'return' ) . '</td>';
3927 + }
3928 + if ( ! empty( $umhs['cod_fee'] ) ) {
3929 + $history_member_head .= '<td class="rightnum cod" data-label="' . apply_filters( 'usces_filter_cod_label', __( 'C.O.D', 'usces' ) ) . '">' . usces_crform( $umhs['cod_fee'], true, false, 'return' ) . '</td>';
3930 + }
3931 + if ( $tax_display && 'all' === $tax_target ) {
3932 + $history_member_head .= '<td class="rightnum tax" data-label="' . $tax_label . '">' . usces_order_history_tax( $umhs, $tax_mode ) . '</td>';
3933 + }
3934 + if ( $member_system_point && 1 === $point_coverage ) {
3935 + $history_member_head .= '<td class="rightnum used_point" data-label="' . __( 'Used points', 'usces' ) . '">' . number_format( $umhs['usedpoint'] ) . '</td>';
3936 + }
3937 + if ( $member_system_point ) {
3938 + $history_member_head .= '<td class="rightnum get_point" data-label="' . __( 'Acquired points', 'usces' ) . '">' . number_format( $umhs['getpoint'] ) . '</td>';
3939 + }
3940 + if ( ! empty( $tracking_number ) ) {
3941 + if ( ! empty( $delivery_company_url ) ) {
3942 + $history_member_head .= '<td data-label="' . __( 'Tracking number', 'usces' ) . '"><a href="' . esc_url( $delivery_company_url ) . '">' . esc_attr( $tracking_number ) . '</a></td>';
3943 + } else {
3944 + $history_member_head .= '<td data-label="' . __( 'Tracking number', 'usces' ) . '">' . esc_attr( $tracking_number ) . '</td>';
3945 + }
3946 + }
3947 + $history_member_head .= '</tr>';
3948 + $html .= apply_filters( 'usces_filter_history_member_head', $history_member_head, $umhs );
3949 + $html .= apply_filters( 'usces_filter_member_history_header', null, $umhs, $head_col );
3950 + $html .= '</tbody></table>
3951 + <table id="retail_table_' . $umhs['ID'] . '" class="retail">';
3952 + $history_cart_head = '<thead><tr>
3953 + <th scope="row" class="cartrownum">No.</th>
3954 + <th class="thumbnail">&nbsp;</th>
3955 + <th class="productname">' . __( 'Items', 'usces' ) . '</th>
3956 + <th class="price">' . __( 'Unit price', 'usces' ) . '</th>
3957 + <th class="quantity">' . __( 'Quantity', 'usces' ) . '</th>
3958 + <th class="subtotal">' . __( 'Amount', 'usces' ) . '</th>
3959 + </tr></thead><tbody>';
3960 + $html .= apply_filters( 'usces_filter_history_cart_head', $history_cart_head, $umhs );
3961 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
3962 + for ( $i = 0; $i < $cart_count; $i++ ) {
3963 + $cart_row = $cart[ $i ];
3964 + $ordercart_id = $cart_row['cart_id'];
3965 + $post_id = $cart_row['post_id'];
3966 + $sku = $cart_row['sku'];
3967 + $sku_code = urldecode( $cart_row['sku'] );
3968 + $quantity = $cart_row['quantity'];
3969 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
3970 + $itemCode = $cart_row['item_code'];
3971 + $itemName = $cart_row['item_name'];
3972 + $cartItemName = $usces->getCartItemName_byOrder( $cart_row );
3973 + $skuPrice = $cart_row['price'];
3974 + $pictid = (int) $usces->get_mainpictid( $itemCode );
3975 + $optstr = '';
3976 + if ( is_array( $options ) && count( $options ) > 0 ) {
3977 + foreach ( $options as $key => $value ) {
3978 + if ( ! empty( $key ) ) {
3979 + $key = urldecode( $key );
3980 + $value = wel_safe_maybe_unserialize( $value );
3981 + if ( is_array( $value ) ) {
3982 + $c = '';
3983 + $optstr .= esc_html( $key ) . ' : ';
3984 + foreach ( $value as $v ) {
3985 + $optstr .= $c . nl2br( esc_html( rawurldecode( $v ) ) );
3986 + $c = ', ';
3987 + }
3988 + $optstr .= "<br />\n";
3989 + } else {
3990 + $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( rawurldecode( $value ) ) ) . "<br />\n";
2589 3991 }
2590 - $optstr .= "<br />\n";
2591 - } else {
2592 - $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2593 3992 }
2594 3993 }
3994 + $optstr = apply_filters( 'usces_filter_option_history', $optstr, $options );
2595 3995 }
2596 - $optstr = apply_filters( 'usces_filter_option_history', $optstr, $options);
3996 + $optstr = apply_filters( 'usces_filter_option_info_history', $optstr, $umhs, $cart_row, $i );
3997 + $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
3998 +
3999 + $cart_item_name = '<a href="' . get_permalink( $post_id ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />' . $optstr . '</a>' . apply_filters( 'usces_filter_history_item_name', null, $umhs, $cart_row, $i );
4000 + $cart_item_name = apply_filters( 'usces_filter_history_cart_item_name', $cart_item_name, $cartItemName, $optstr, $cart_row, $i, $umhs );
4001 +
4002 + $history_cart_row = '<tr>
4003 + <td class="cartrownum">' . ( $i + 1 ) . '</td>
4004 + <td class="thumbnail">';
4005 + $cart_thumbnail = '<a href="' . get_permalink( $post_id ) . '">' . wp_get_attachment_image( $pictid, array( 60, 60 ), true ) . '</a>';
4006 + $history_cart_row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4007 + $history_cart_row .= '</td>
4008 + <td class="aleft productname" data-label="' . __( 'Items', 'usces' ) . '">' . $cart_item_name . '</td>
4009 + <td class="rightnum price" data-label="' . __( 'Unit price', 'usces' ) . '">' . usces_crform( $skuPrice, true, false, 'return' ) . '</td>
4010 + <td class="rightnum quantity" data-label="' . __( 'Quantity', 'usces' ) . '">' . number_format( $cart_row['quantity'] ) . '</td>
4011 + <td class="rightnum subtotal" data-label="' . __( 'Amount', 'usces' ) . '">' . usces_crform( $skuPrice * $cart_row['quantity'], true, false, 'return' ) . '</td>
4012 + </tr>';
4013 + $materials = compact( 'cart_thumbnail', 'post_id', 'pictid', 'cartItemName', 'optstr' );
4014 + $html .= apply_filters( 'usces_filter_history_cart_row', $history_cart_row, $umhs, $cart_row, $i, $materials );
2597 4015 }
2598 - $optstr = apply_filters( 'usces_filter_option_info_history', $optstr, $umhs, $cart_row, $i );
2599 -
2600 - $history_cart_row = '<tr>
2601 - <td>' . ($i + 1) . '</td>
2602 - <td>';
2603 - $cart_thumbnail = '<a href="' . get_permalink($post_id) . '">' . wp_get_attachment_image( $pictid, array(60, 60), true ) . '</a>';
2604 - $history_cart_row .= apply_filters('usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row);
2605 - $history_cart_row .= '</td>
2606 - <td class="aleft"><a href="' . get_permalink($post_id) . '">' . esc_html($cartItemName) . '<br />' . $optstr . '</a>' . apply_filters('usces_filter_history_item_name', NULL, $umhs, $cart_row, $i) . '</td>
2607 - <td class="rightnum">' . usces_crform($skuPrice, true, false, 'return') . '</td>
2608 - <td class="rightnum">' . number_format($cart_row['quantity']) . '</td>
2609 - <td class="rightnum">' . usces_crform($skuPrice * $cart_row['quantity'], true, false, 'return') . '</td>
2610 - </tr>';
2611 - $materials = compact( 'cart_thumbnail', 'post_id', 'pictid', 'cartItemName', 'optstr' );
2612 - $html .= apply_filters( 'usces_filter_history_cart_row', $history_cart_row, $umhs, $cart_row, $i, $materials );
4016 + $html .= '</tbody></table>';
4017 + $html .= apply_filters( 'usces_filter_member_history_row', '', $umhs, $cart );
2613 4018 }
2614 - $html .= '</table>
2615 - </td>
2616 - </tr>';
2617 4019 }
2618 -
2619 - $html .= '</table>
2620 - </div>';
4020 + $html .= '</div>';
4021 + $html = apply_filters( 'usces_filter_member_history', $html, $usces_member_history );
2621 4022
2622 - if($out == 'return'){
4023 + if ( 'return' === $out ) {
2623 4024 return $html;
2624 - }else{
2625 - echo $html;
4025 + } else {
4026 + echo $html; // no escape due to filter.
2626 4027 }
2627 4028 }
2628 4029
2629 -function usces_newmember_button($member_regmode){
2630 - $html = '<input name="member_regmode" type="hidden" value="' . $member_regmode . '" />';
2631 - $newmemberbutton = '<input name="regmember" type="submit" value="' . __('transmit a message', 'usces') . '" />';
2632 - $html .= apply_filters('usces_filter_newmember_button', $newmemberbutton);
2633 - echo $html;
4030 +/**
4031 + * Load select list filter purchase history.
4032 + */
4033 +function usces_load_filter_purchase_date() {
4034 + global $usces;
4035 +
4036 + $pur_date = $usces->usces_get_member_cookies( 'pur-date' );
4037 + $current_year = (int) gmdate( 'Y' );
4038 + $year_filter = 11;
4039 + $arr_filter = array(
4040 + '' => __( 'All of period', 'usces' ),
4041 + 'm_0' => __( 'This month', 'usces' ),
4042 + 'm_1' => __( 'Previous month', 'usces' ),
4043 + 'm_2' => __( 'Two months ago', 'usces' ),
4044 + 'd_30' => __( 'Last 30 days', 'usces' ),
4045 + 'd_60' => __( 'Last 60 days', 'usces' ),
4046 + );
4047 + for ( $i = 0; $i < $year_filter; $i++ ) {
4048 + $year = $current_year - $i;
4049 + $arr_filter[ 'y_' . $year ] = $year . __( 'year', 'usces' );
4050 + }
4051 + $exclude_cancel = $usces->usces_get_member_cookies( 'ord_ex_cancel' );
4052 + $add_ex_args = array(
4053 + 'ord_ex_cancel' => ( 'on' === (string) $exclude_cancel ) ? 'off' : 'on',
4054 + 'pur-date' => $pur_date,
4055 + );
4056 + $url_ex_filter = add_query_arg( $add_ex_args, USCES_MEMBER_URL ) . '#usces_history';
4057 + $html = '<div id="usces_history" class="usces_filter_history">';
4058 + $content = '<div class="exclude_cancel">';
4059 + $content .= '<label for="ord_exclude_cancel">';
4060 + $content .= '<input type="checkbox" id="ord_exclude_cancel" name="ord_exclude_cancel" onchange="memberOrderHistory.onChangeFilter(this);" value="' . esc_url( $url_ex_filter ) . '" ' . checked( $exclude_cancel, 'on', false ) . ' />';
4061 + $content .= __( 'Exclude cancellations', 'usces' ) . '</label>';
4062 + $content .= '</div>';
4063 + $content .= '<div class="usce_period">';
4064 + $content .= '<span>' . __( 'Period', 'usces' ) . '</span>';
4065 + $content .= '<select name="usces_purdate" id="usces_purdate" onchange="memberOrderHistory.onChangeFilter(this);">';
4066 + foreach ( $arr_filter as $key => $name ) {
4067 + $selected = '';
4068 + $add_args = array(
4069 + 'pur-date' => $key,
4070 + );
4071 + if ( (string) $key === (string) $pur_date ) {
4072 + $selected = 'selected';
4073 + }
4074 + $url_filter = add_query_arg( $add_args, USCES_MEMBER_URL ) . '#usces_history';
4075 + $content .= '<option cvalue="' . $key . '" value="' . esc_url( $url_filter ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $name ) . '</option>';
4076 + }
4077 + $content .= '</select>';
4078 + $content .= '</div>';
4079 + $html .= apply_filters( 'usces_filter_member_history_top_navi', $content );
4080 + $html .= '</div>';
4081 + return $html;
2634 4082 }
2635 4083
2636 -function usces_login_button(){
2637 - $loginbutton = '<input type="submit" name="member_login" id="member_login" class="member_login_button" value="' . __('Log-in', 'usces') . '" />';
2638 - $html = apply_filters('usces_filter_login_button', $loginbutton);
2639 - echo $html;
4084 +/**
4085 + * New registration button
4086 + *
4087 + * @param string $member_regmode Registration mode.
4088 + */
4089 +function usces_newmember_button( $member_regmode ) {
4090 + $html = '<input name="member_regmode" type="hidden" value="' . $member_regmode . '" />';
4091 + $newmemberbutton = '<input name="regmember" type="submit" value="' . __( 'transmit a message', 'usces' ) . '" />';
4092 + $html .= apply_filters( 'usces_filter_newmember_button', $newmemberbutton );
4093 + wel_esc_script_e( $html );
2640 4094 }
2641 4095
2642 -function usces_assistance_item($post_id, $title ){
2643 - if (usces_get_assistance_id_list($post_id)) :
4096 +/**
4097 + * Login button
4098 + */
4099 +function usces_login_button() {
4100 + $loginbutton = '<input type="submit" name="member_login" id="member_login" class="member_login_button" value="' . __( 'Log-in', 'usces' ) . '" />';
4101 + $html = apply_filters( 'usces_filter_login_button', $loginbutton );
4102 + wel_esc_script_e( $html );
4103 +}
4104 +
4105 +/**
4106 + * Related item
4107 + *
4108 + * @param int $post_id Post ID.
4109 + * @param string $title Title.
4110 + */
4111 +function usces_assistance_item( $post_id, $title ) {
4112 + if ( usces_get_assistance_id_list( $post_id ) ) :
2644 4113 global $post;
2645 - $r = new WP_Query( array('post__in'=>usces_get_assistance_ids($post_id), 'ignore_sticky_posts'=>1) );
2646 - if($r->have_posts()) :
2647 - add_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
2648 - add_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
2649 - $width = apply_filters( 'usces_filter_assistance_item_width', 100 );
2650 - $height = apply_filters( 'usces_filter_assistance_item_height', 100 );
2651 -?>
4114 + $r = new WP_Query( array( 'post__in' => usces_get_assistance_ids( $post_id ), 'ignore_sticky_posts' => 1 ) );
4115 + if ( $r->have_posts() ) :
4116 + add_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
4117 + add_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
4118 + $width = apply_filters( 'usces_filter_assistance_item_width', 100 );
4119 + $height = apply_filters( 'usces_filter_assistance_item_height', 100 );
4120 + ?>
2652 4121 <div class="assistance_item">
2653 - <h3><?php echo $title; ?></h3>
4122 + <h3><?php wel_esc_script_e( $title ); ?></h3>
2654 4123 <ul class="clearfix">
2655 -<?php
2656 - while ($r->have_posts()) :
2657 - $r->the_post();
2658 - usces_remove_filter();
2659 - usces_the_item();
2660 - ob_start();
2661 -?>
4124 + <?php
4125 + while ( $r->have_posts() ) :
4126 + $r->the_post();
4127 + usces_remove_filter();
4128 + usces_the_item();
4129 + ob_start();
4130 + ?>
2662 4131 <li>
2663 4132 <div class="listbox clearfix">
2664 4133 <div class="slit">
2665 - <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses(get_the_title()); ?>"><?php usces_the_itemImage(0, $width, $height, $post); ?></a>
4134 + <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses( get_the_title() ); ?>"><?php usces_the_itemImage( 0, $width, $height, $post ); ?></a>
2666 4135 </div>
2667 4136 <div class="detail">
2668 4137 <div class="assist_excerpt">
2669 - <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses(get_the_title()); ?>"><h4><?php usces_the_itemName(); ?></h4></a>
4138 + <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo wp_filter_nohtml_kses( get_the_title() ); ?>"><h4><?php usces_the_itemName(); ?></h4></a>
2670 4139 <?php the_excerpt(); ?>
2671 4140 </div>
4141 + <?php if ( usces_is_skus() ) : ?>
2672 4142 <div class="assist_price">
2673 - <?php if (usces_is_skus()) : ?>
2674 - <?php _e('$', 'usces'); ?><?php usces_the_firstPrice(); ?>
4143 + <?php usces_crform( usces_the_firstPrice( 'return' ), true, false ); ?>
4144 + </div>
4145 + <?php usces_crform_the_itemPriceCr_taxincluded(); ?>
2675 4146 <?php endif; ?>
2676 - </div>
2677 4147 </div>
2678 4148 </div>
2679 4149 </li>
2680 - <?php
2681 - $list = ob_get_contents();
2682 - ob_end_clean();
2683 - echo apply_filters('usces_filter_assistance_item_list', $list, $post);
2684 - endwhile; ?>
2685 -
4150 + <?php
4151 + $list = ob_get_contents();
4152 + ob_end_clean();
4153 + echo apply_filters( 'usces_filter_assistance_item_list', $list, $post );
4154 + endwhile;
4155 + ?>
2686 4156 </ul>
2687 4157 </div><!-- end of assistance_item -->
2688 -<?php
2689 - wp_reset_postdata();
2690 - usces_reset_filter();
2691 - remove_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
2692 - remove_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
4158 + <?php
4159 + wp_reset_postdata();
4160 + usces_reset_filter();
4161 + remove_filter( 'excerpt_length', 'welcart_assistance_excerpt_length' );
4162 + remove_filter( 'excerpt_mblength', 'welcart_assistance_excerpt_mblength' );
2693 4163 endif;
2694 4164 endif;
2695 4165 }
2696 4166
4167 +/**
4168 + * Cart Item Details
4169 + *
4170 + * @param string $out Return value or echo.
4171 + * @return string|void
4172 + */
2697 4173 function usces_get_cart_rows( $out = '' ) {
2698 4174 global $usces, $usces_gp;
2699 - $cart = $usces->cart->get_cart();
2700 - $usces_gp = 0;
2701 - $res = '';
2702 4175
2703 - for($i=0; $i<count($cart); $i++) {
2704 - $cart_row = $cart[$i];
2705 - $post_id = $cart_row['post_id'];
2706 - $sku = $cart_row['sku'];
2707 - $sku_code = esc_attr(urldecode($cart_row['sku']));
2708 - $quantity = $cart_row['quantity'];
2709 - $options = $cart_row['options'];
2710 - $advance = $usces->cart->wc_serialize($cart_row['advance']);
2711 - $itemCode = $usces->getItemCode($post_id);
2712 - $itemName = $usces->getItemName($post_id);
2713 - $cartItemName = $usces->getCartItemName($post_id, $sku_code);
2714 - $itemRestriction = $usces->getItemRestriction($post_id);
2715 - $skuPrice = $cart_row['price'];
2716 - $skuZaikonum = $usces->getItemZaikonum($post_id, $sku_code);
2717 - $stockid = $usces->getItemZaikoStatusId($post_id, $sku_code);
2718 - $stock = $usces->getItemZaiko($post_id, $sku_code);
2719 - $red = (in_array($stock, array(__('sellout','usces'), __('Out Of Stock','usces'), __('Out of print','usces')))) ? 'class="signal_red"' : '';
2720 - $pictid = (int)$usces->get_mainpictid($itemCode);
2721 - $args = compact('cart', 'i', 'cart_row', 'post_id', 'sku' );
2722 - $row = '';
2723 - if ( empty($options) ) {
2724 - $optstr = '';
2725 - $options = array();
2726 - }
2727 - $row .= '<tr>
2728 - <td>' . ($i + 1) . '</td>
2729 - <td>';
2730 - $cart_thumbnail = '<a href="' . get_permalink($post_id) . '">' . wp_get_attachment_image( $pictid, array(60, 60), true ) . '</a>';
2731 - $row .= apply_filters('usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i,$cart_row);
2732 - $row .= '</td><td class="aleft">' . esc_html($cartItemName) . '<br />';
2733 - if( is_array($options) && count($options) > 0 ){
4176 + $cart = $usces->cart->get_cart();
4177 + $usces_gp = 0;
4178 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
4179 + $res = '';
4180 +
4181 + for ( $i = 0; $i < $cart_count; $i++ ) {
4182 + $cart_row = $cart[ $i ];
4183 + $post_id = (int) $cart_row['post_id'];
4184 + $sku = $cart_row['sku'];
4185 + $sku_code = urldecode( $cart_row['sku'] );
4186 + $quantity = $cart_row['quantity'];
4187 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
4188 + $advance = ( ! empty( $cart_row['advance'] ) ) ? $cart_row['advance'] : '';
4189 + $itemCode = $usces->getItemCode( $post_id );
4190 + $itemName = $usces->getItemName( $post_id );
4191 + $cartItemName = $usces->getCartItemName( $post_id, $sku_code );
4192 + $itemRestriction = $usces->getItemRestriction( $post_id );
4193 + $itemOrderAcceptable = $usces->getItemOrderAcceptable( $post_id );
4194 + $skuPrice = $cart_row['price'];
4195 + $skuZaikonum = $usces->getItemZaikonum( $post_id, $sku_code );
4196 + $stockid = $usces->getItemZaikoStatusId( $post_id, $sku_code );
4197 + $stock = $usces->getItemZaiko( $post_id, $sku_code );
4198 + $red = ( 1 < $stockid ) ? 'class="signal_red stock"' : 'class="stock"';
4199 + $pictid = (int) $usces->get_mainpictid( $itemCode );
4200 + $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
4201 +
4202 + $row = '';
4203 + $row .= '<tr>
4204 + <td class="num">' . ( $i + 1 ) . '</td>
4205 + <td class="thumbnail">';
4206 + $cart_thumbnail = '<a href="' . get_permalink( $post_id ) . '">' . wp_get_attachment_image( $pictid, array( 60, 60 ), true ) . '</a>';
4207 + $row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4208 + $row .= '</td>
4209 + <td class="aleft productname" data-label="' . esc_html__( 'Items', 'usces' ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />';
4210 + if ( is_array( $options ) && count( $options ) > 0 ) {
2734 4211 $optstr = '';
2735 - foreach($options as $key => $value){
2736 -//20110629ysk start 0000190
2737 - //if( !empty($key) )
2738 - // $row .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2739 - if( !empty($key) ) {
2740 - $key = urldecode($key);
2741 - if(is_array($value)) {
2742 - $c = '';
2743 - $optstr .= esc_html($key) . ' : ';
2744 - foreach($value as $v) {
2745 - $optstr .= $c.nl2br(esc_html(urldecode($v)));
2746 - $c = ', ';
4212 + foreach ( $options as $key => $value ) {
4213 + if ( ! empty( $key ) ) {
4214 + $key = urldecode( $key );
4215 + if ( is_array( $value ) ) {
4216 + $c = '';
4217 + $optstr .= esc_html( $key ) . ' : ';
4218 + foreach ( $value as $v ) {
4219 + $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
4220 + $c = ', ';
2747 4221 }
2748 - $optstr .= "<br />\n";
4222 + $optstr .= "<br />\n";
2749 4223 } else {
2750 - $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
4224 + $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . "<br />\n";
2751 4225 }
2752 4226 }
2753 -//20110629ysk end
2754 4227 }
2755 - $row .= apply_filters( 'usces_filter_option_cart', $optstr, $options);
4228 + $row .= apply_filters( 'usces_filter_option_cart', $optstr, $options, $args );
2756 4229 }
2757 4230 $row .= apply_filters( 'usces_filter_option_info_cart', '', $cart_row, $args );
2758 4231 $row .= '</td>
2759 - <td class="aright">';
2760 - if( usces_is_gptekiyo($post_id, $sku_code, $quantity) ) {
2761 - $usces_gp = 1;
2762 - $Business_pack_mark = '<img src="' . get_template_directory_uri() . '/images/gp.gif" alt="' . __('Business package discount','usces') . '" /><br />';
2763 - $row .= apply_filters('usces_filter_itemGpExp_cart_mark', $Business_pack_mark);
4232 + <td class="aright unitprice" data-label="' . esc_html__( 'Unit price', 'usces' ) . '">';
4233 + if ( usces_is_gptekiyo( $post_id, $sku_code, $quantity ) ) {
4234 + $usces_gp = 1;
4235 + $gp_src = file_exists( get_template_directory() . '/images/gp.gif' ) ? get_template_directory_uri() . '/images/gp.gif' : USCES_PLUGIN_URL . '/images/gp.gif';
4236 + $Business_pack_mark = '<img src="' . $gp_src . '" alt="' . __( 'Business package discount', 'usces' ) . '" /><br />';
4237 + $row .= apply_filters( 'usces_filter_itemGpExp_cart_mark', $Business_pack_mark );
2764 4238 }
2765 - $row .= usces_crform($skuPrice, true, false, 'return') . '
4239 + $row .= usces_crform( $skuPrice, true, false, 'return' ) . '
2766 4240 </td>
2767 - <td>';
2768 - $row_quant = '<input name="quant[' . $i . '][' . $post_id . '][' . $sku . ']" class="quantity" type="text" value="' . esc_attr($cart_row['quantity']) . '" />';
2769 - $row .= apply_filters( 'usces_filter_cart_rows_quant', $row_quant, $args );
2770 - $row .= '</td>
2771 - <td class="aright">' . usces_crform(($skuPrice * $cart_row['quantity']), true, false, 'return') . '</td>
2772 - <td ' . $red . '>' . $stock . '</td>
2773 - <td>';
2774 - foreach($options as $key => $value){
2775 -//20110629ysk start 0000190
2776 - //$row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . $sku . '][' . $key . ']" type="hidden" value="' . $value . '" />';
2777 - if(is_array($value)) {
2778 - foreach($value as $v) {
2779 - $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . $sku . '][' . $key . '][' . $v . ']" type="hidden" value="' . $v . '" />';
4241 + <td class="quantity" data-label="' . esc_html__( 'Quantity', 'usces' ) . '">';
4242 + $row_quant = '<input name="quant[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" class="quantity" type="text" value="' . esc_attr( $cart_row['quantity'] ) . '" />';
4243 + $row .= apply_filters( 'usces_filter_cart_rows_quant', $row_quant, $args );
4244 + $row .= '</td>
4245 + <td class="aright subtotal" data-label="' . esc_html__( 'Amount', 'usces' ) . usces_guid_tax( 'return', false ) . '">' . usces_crform( ( $skuPrice * $cart_row['quantity'] ), true, false, 'return' ) . '</td>';
4246 + $stock_column = '<td ' . $red . ' data-label="' . esc_html__( 'stock status', 'usces' ) . '">' . esc_html( $stock ) . '</td>';
4247 + $row .= apply_filters( 'usces_filter_cart_rows_stock', $stock_column, $args, $red, $stock );
4248 + $row .= '<td class="action">';
4249 + if ( is_array( $options ) && count( $options ) > 0 ) {
4250 + foreach ( $options as $key => $value ) {
4251 + if ( is_array( $value ) ) {
4252 + foreach ( $value as $v ) {
4253 + $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . '][' . esc_attr( $key ) . '][' . esc_attr( $v ) . ']" type="hidden" value="' . esc_attr( $v ) . '" />' . "\n";
4254 + }
4255 + } else {
4256 + $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . '][' . esc_attr( $key ) . ']" type="hidden" value="' . esc_attr( $value ) . '" />' . "\n";
2780 4257 }
2781 - } else {
2782 - $row .= '<input name="itemOption[' . $i . '][' . $post_id . '][' . $sku . '][' . $key . ']" type="hidden" value="' . $value . '" />';
2783 4258 }
2784 -//20110629ysk end
2785 4259 }
2786 - $row .= '<input name="itemRestriction[' . $i . ']" type="hidden" value="' . $itemRestriction . '" />
2787 - <input name="stockid[' . $i . ']" type="hidden" value="' . $stockid . '" />
2788 - <input name="itempostid[' . $i . ']" type="hidden" value="' . $post_id . '" />
2789 - <input name="itemsku[' . $i . ']" type="hidden" value="' . $sku . '" />
2790 - <input name="zaikonum[' . $i . '][' . $post_id . '][' . $sku . ']" type="hidden" value="' . esc_attr($skuZaikonum) . '" />
2791 - <input name="skuPrice[' . $i . '][' . $post_id . '][' . $sku . ']" type="hidden" value="' . esc_attr($skuPrice) . '" />
2792 - <input name="advance[' . $i . '][' . $post_id . '][' . $sku . ']" type="hidden" value="' . esc_attr($advance) . '" />
2793 - <input name="delButton[' . $i . '][' . $post_id . '][' . $sku . ']" class="delButton" type="submit" value="' . __('Delete','usces') . '" />
4260 + $row .= '<input name="itemRestriction[' . $i . ']" type="hidden" value="' . esc_attr( $itemRestriction ) . '" />
4261 + <input name="itemOrderAcceptable[' . $i . ']" type="hidden" value="' . $itemOrderAcceptable . '" />
4262 + <input name="stockid[' . $i . ']" type="hidden" value="' . esc_attr( $stockid ) . '" />
4263 + <input name="itempostid[' . $i . ']" type="hidden" value="' . esc_attr( $post_id ) . '" />
4264 + <input name="itemsku[' . $i . ']" type="hidden" value="' . esc_attr( $sku ) . '" />
4265 + <input name="zaikonum[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $skuZaikonum ) . '" />
4266 + <input name="skuPrice[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $skuPrice ) . '" />
4267 + <input name="advance[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" type="hidden" value="' . esc_attr( $advance ) . '" />
4268 + <input name="delButton[' . $i . '][' . $post_id . '][' . esc_attr( $sku ) . ']" class="delButton" type="submit" value="' . __( 'Delete', 'usces' ) . '" />
2794 4269 </td>
2795 4270 </tr>';
2796 - $materials = compact('i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance',
2797 - 'itemCode', 'itemName', 'cartItemName', 'itemRestriction', 'skuPrice', 'skuZaikonum',
2798 - 'stockid', 'stock', 'red', 'pictid');
2799 - $res .= apply_filters( 'usces_filter_cart_row', $row, $cart, $materials);
4271 + $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance', 'itemCode', 'itemName', 'cartItemName', 'itemRestriction', 'skuPrice', 'skuZaikonum', 'stockid', 'stock', 'red', 'pictid' );
4272 + $res .= apply_filters( 'usces_filter_cart_row', $row, $cart, $materials );
2800 4273 }
2801 -
2802 - $res = apply_filters( 'usces_filter_cart_rows', $res, $cart);
2803 4274
2804 - if($out == 'return'){
4275 + $res = apply_filters( 'usces_filter_cart_rows', $res, $cart );
4276 +
4277 + if ( 'return' === $out ) {
2805 4278 return $res;
2806 - }else{
2807 - echo $res;
4279 + } else {
4280 + echo $res; // no escape due to filter.
2808 4281 }
2809 4282 }
4283 +
4284 +/**
4285 + * Confirm Cart Item Details
4286 + *
4287 + * @param string $out Return value or echo.
4288 + * @return string|void
4289 + */
2810 4290 function usces_get_confirm_rows( $out = '' ) {
2811 4291 global $usces, $usces_members, $usces_entries;
2812 -// $usces_members = $usces->get_member();
2813 - $memid = ( empty($usces_members['ID']) ) ? 999999999 : $usces_members['ID'];
2814 -// $usces_entries = $usces->cart->get_entry();
4292 +
4293 + $memid = ( empty( $usces_members['ID'] ) ) ? 999999999 : $usces_members['ID'];
2815 4294 $usces->set_cart_fees( $usces_members, $usces_entries );
2816 4295 $usces_entries = $usces->cart->get_entry();
2817 -
2818 - $cart = $usces->cart->get_cart();
2819 - $res = '';
2820 - for($i=0; $i<count($cart); $i++) {
2821 - $cart_row = $cart[$i];
2822 - $post_id = $cart_row['post_id'];
2823 - $sku = esc_attr($cart_row['sku']);
2824 - $sku_code = esc_attr(urldecode($cart_row['sku']));
2825 - $quantity = $cart_row['quantity'];
2826 - $options = $cart_row['options'];
2827 - $advance = $usces->cart->wc_serialize($cart_row['advance']);
2828 - $itemCode = $usces->getItemCode($post_id);
2829 - $itemName = $usces->getItemName($post_id);
2830 - $cartItemName = $usces->getCartItemName($post_id, $sku_code);
2831 - $skuPrice = $cart_row['price'];
2832 - $pictid = $usces->get_mainpictid($itemCode);
2833 - $args = compact('cart', 'i', 'cart_row', 'post_id', 'sku' );
2834 - $row = '';
2835 - if (empty($options)) {
2836 - $optstr = '';
2837 - $options = array();
2838 - }
2839 -
2840 - $row .= '<tr>
2841 - <td>' . ($i + 1) . '</td>
2842 - <td>';
2843 - $cart_thumbnail = wp_get_attachment_image( $pictid, array(60, 60), true );
2844 - $row .= apply_filters('usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row);
2845 - $row .= '</td><td class="aleft">' . $cartItemName . '<br />';
2846 - if( is_array($options) && count($options) > 0 ){
4296 +
4297 + $cart = $usces->cart->get_cart();
4298 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
4299 + $res = '';
4300 +
4301 + for ( $i = 0; $i < $cart_count; $i++ ) {
4302 + $cart_row = $cart[ $i ];
4303 + $post_id = (int) $cart_row['post_id'];
4304 + $sku = $cart_row['sku'];
4305 + $sku_code = urldecode( $cart_row['sku'] );
4306 + $quantity = $cart_row['quantity'];
4307 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
4308 + $advance = $cart_row['advance'];
4309 + $itemCode = $usces->getItemCode( $post_id );
4310 + $itemName = $usces->getItemName( $post_id );
4311 + $cartItemName = $usces->getCartItemName( $post_id, $sku_code );
4312 + $skuPrice = $cart_row['price'];
4313 + $pictid = $usces->get_mainpictid( $itemCode );
4314 + $args = compact( 'cart', 'i', 'cart_row', 'post_id', 'sku' );
4315 +
4316 + $row = '';
4317 + $row .= '<tr>
4318 + <td class="num">' . ( $i + 1 ) . '</td>
4319 + <td class="thumbnail">';
4320 + $cart_thumbnail = wp_get_attachment_image( $pictid, array( 60, 60 ), true );
4321 + $row .= apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4322 + $row .= '</td><td class="productname" data-label="' . esc_html__( 'Items', 'usces' ) . '">' . apply_filters( 'usces_filter_cart_item_name', esc_html( $cartItemName ), $args ) . '<br />';
4323 + if ( is_array( $options ) && count( $options ) > 0 ) {
2847 4324 $optstr = '';
2848 - foreach($options as $key => $value){
2849 -//20110629ysk start 0000190
2850 - //if( !empty($key) )
2851 - // $row .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
2852 - if( !empty($key) ) {
2853 - $key = urldecode($key);
2854 - if(is_array($value)) {
2855 - $c = '';
2856 - $optstr .= esc_html($key) . ' : ';
2857 - foreach($value as $v) {
2858 - $optstr .= $c.nl2br(esc_html(urldecode($v)));
2859 - $c = ', ';
4325 + foreach ( $options as $key => $value ) {
4326 + if ( ! empty( $key ) ) {
4327 + $key = urldecode( $key );
4328 + if ( is_array( $value ) ) {
4329 + $c = '';
4330 + $optstr .= esc_html( $key ) . ' : ';
4331 + foreach ( $value as $v ) {
4332 + $optstr .= $c . nl2br( esc_html( urldecode( $v ) ) );
4333 + $c = ', ';
2860 4334 }
2861 - $optstr .= "<br />\n";
4335 + $optstr .= "<br />\n";
2862 4336 } else {
2863 - $optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
4337 + $optstr .= esc_html( $key ) . ' : ' . nl2br( esc_html( urldecode( $value ) ) ) . "<br />\n";
2864 4338 }
2865 4339 }
2866 -//20110629ysk end
2867 4340 }
2868 - $row .= apply_filters( 'usces_filter_option_confirm', $optstr, $options);
4341 + $row .= apply_filters( 'usces_filter_option_confirm', $optstr, $options, $args );
2869 4342 }
2870 4343 $row .= apply_filters( 'usces_filter_option_info_confirm', '', $cart_row, $args );
2871 4344 $row .= '</td>
2872 - <td class="aright">' . usces_crform($skuPrice, true, false, 'return') . '</td>
2873 - <td>' . $cart_row['quantity'] . '</td>
2874 - <td class="aright">' . usces_crform(($skuPrice * $cart_row['quantity']), true, false, 'return') . '</td>
2875 - <td>';
2876 - $res = apply_filters('usces_additional_confirm', $res, array($i, $post_id, $sku_code));
4345 + <td class="unitprice" data-label="' . esc_html__( 'Unit price', 'usces' ) . '">' . esc_html( usces_crform( $skuPrice, true, false, 'return' ) ) . '</td>
4346 + <td class="quantity" data-label="' . esc_html__( 'Quantity', 'usces' ) . '">' . esc_html( $cart_row['quantity'] ) . '</td>
4347 + <td class="subtotal" data-label="' . esc_html__( 'Amount', 'usces' ) . '">' . esc_html( usces_crform( ( $skuPrice * $cart_row['quantity'] ), true, false, 'return' ) ) . '</td>
4348 + <td class="action">';
4349 + $row .= apply_filters( 'usces_additional_confirm', '', array( $i, $post_id, $sku_code ) );
2877 4350 $row .= '</td>
2878 4351 </tr>';
2879 -
2880 - $materials = compact('i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance',
2881 - 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'pictid');
2882 - $res .= apply_filters( 'usces_filter_confirm_row', $row, $cart, $materials);
2883 - }
2884 -
2885 - $res = apply_filters( 'usces_filter_confirm_rows', $res, $cart);
2886 4352
2887 - if($out == 'return'){
4353 + $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance', 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'pictid' );
4354 + $res .= apply_filters( 'usces_filter_confirm_row', $row, $cart, $materials );
4355 + }
4356 +
4357 + $res = apply_filters( 'usces_filter_confirm_rows', $res, $cart );
4358 +
4359 + if ( 'return' === $out ) {
2888 4360 return $res;
2889 - }else{
2890 - echo $res;
4361 + } else {
4362 + echo $res; // no escape due to filter.
2891 4363 }
2892 4364 }
2893 4365
2894 -function uesces_addressform( $type, $data, $out = 'return' ){
4366 +/**
4367 + * Address Information
4368 + *
4369 + * @param string $type Type.
4370 + * @param array $data Entry data.
4371 + * @param string $out Return value or echo.
4372 + * @return string|void
4373 + */
4374 +function uesces_addressform( $type, $data, $out = 'return' ) {
2895 4375 global $usces, $usces_settings;
2896 - $options = get_option('usces');
2897 - $form = $options['system']['addressform'];
2898 - $nameform = $usces_settings['nameform'][$form];
2899 - $applyform = usces_get_apply_addressform($form);
2900 - $formtag = '';
2901 - switch( $type ){
2902 - case 'confirm':
2903 - case 'member':
2904 - $values = $data;
2905 - break;
2906 - case 'customer':
2907 - case 'delivery':
2908 - $values = $data[$type];
2909 - break;
2910 - }
2911 - $data['type'] = $type;
2912 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
2913 - $values = $usces->stripslashes_deep_post($values);
2914 - if( 'confirm' == $type ){
2915 -
2916 - switch ($applyform){
2917 -
2918 - case 'JP':
2919 - $formtag .= usces_custom_field_info($data, 'customer', 'name_pre', 'return');
2920 - $formtag .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['customer']['name1']) . ' ' . esc_html($values['customer']['name2']) . '</td></tr>';
2921 - $furigana_customer = '<tr><th>'.__('furigana', 'usces').'</th><td>' . esc_html($values['customer']['name3']) . ' ' . esc_html($values['customer']['name4']) . '</td></tr>';
2922 - $formtag .= apply_filters( 'usces_filter_furigana_confirm_customer', $furigana_customer, $type, $values );
2923 - $formtag .= usces_custom_field_info($data, 'customer', 'name_after', 'return');
2924 - $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : '';
2925 - $formtag .= '<tr><th>'.__('Zip/Postal Code', 'usces').'</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>';
2926 -//20131213_kitamura_start
2927 - if( count( $options['system']['target_market'] ) != 1 ){
2928 - $formtag .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($customer_country) . '</td></tr>';
2929 - }
2930 -//20131213_kitamura_end
2931 - $formtag .= '
2932 - <tr><th>'.__('Province', 'usces').'</th><td>' . esc_html($values['customer']['pref']) . '</td></tr>
2933 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['customer']['address1']) . '</td></tr>
2934 - <tr><th>'.__('numbers', 'usces').'</th><td>' . esc_html($values['customer']['address2']) . '</td></tr>
2935 - <tr><th>'.__('building name', 'usces').'</th><td>' . esc_html($values['customer']['address3']) . '</td></tr>
2936 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['customer']['tel']) . '</td></tr>
2937 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>';
2938 - $formtag .= usces_custom_field_info($data, 'customer', 'fax_after', 'return');
2939 -
2940 - $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>'.__('Shipping address information', 'usces').'</h3></td></tr>';
2941 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return');
2942 - $shipping_address_info .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['delivery']['name1']) . ' ' . esc_html($values['delivery']['name2']) . '</td></tr>';
2943 - $furigana_delivery = '<tr><th>'.__('furigana', 'usces').'</th><td>' . esc_html($values['delivery']['name3']) . ' ' . esc_html($values['delivery']['name4']) . '</td></tr>';
2944 - $shipping_address_info .= apply_filters( 'usces_filter_furigana_confirm_delivery', $furigana_delivery, $type, $values );
2945 - $shipping_address_info .= usces_custom_field_info($values, 'delivery', 'name_after', 'return');
2946 - $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : '';
2947 - $shipping_address_info .= '<tr><th>'.__('Zip/Postal Code', 'usces').'</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>';
2948 -//20131213_kitamura_start
2949 - if( count( $options['system']['target_market'] ) != 1 ){
2950 - $shipping_address_info .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($shipping_country) . '</td></tr>';
2951 - }
2952 -//20131213_kitamura_end
2953 - $shipping_address_info .= '
2954 - <tr><th>'.__('Province', 'usces').'</th><td>' . esc_html($values['delivery']['pref']) . '</td></tr>
2955 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr>
2956 - <tr><th>'.__('numbers', 'usces').'</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr>
2957 - <tr><th>'.__('building name', 'usces').'</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr>
2958 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>
2959 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>';
2960 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return');
2961 - $formtag .= apply_filters('usces_filter_shipping_address_info', $shipping_address_info);
4376 +
4377 + $options = get_option( 'usces', array() );
4378 + $form = $options['system']['addressform'];
4379 + $nameform = $usces_settings['nameform'][ $form ];
4380 + $applyform = usces_get_apply_addressform( $form );
4381 + $formtag = '';
4382 + switch ( $type ) {
4383 + case 'confirm':
4384 + case 'member':
4385 + $values = $data;
2962 4386 break;
2963 -
2964 - case 'CN':
2965 - $formtag .= usces_custom_field_info($data, 'customer', 'name_pre', 'return');
2966 - $formtag .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html(usces_localized_name( $values['customer']['name1'], $values['customer']['name2'], 'return' )) . '</td></tr>';
2967 - $formtag .= usces_custom_field_info($data, 'customer', 'name_after', 'return');
2968 -//20131213_kitamura_start
2969 - if( count( $options['system']['target_market'] ) != 1 ){
2970 - $formtag .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($usces_settings['country'][$values['customer']['country']]) . '</td></tr>';
2971 - }
2972 -//20131213_kitamura_end
2973 - $formtag .= '
2974 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['customer']['pref']) . '</td></tr>
2975 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['customer']['address1']) . '</td></tr>
2976 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['customer']['address2']) . '</td></tr>
2977 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['customer']['address3']) . '</td></tr>
2978 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>
2979 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['customer']['tel']) . '</td></tr>
2980 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>';
2981 - $formtag .= usces_custom_field_info($data, 'customer', 'fax_after', 'return');
2982 -
2983 - $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>'.__('Shipping address information', 'usces').'</h3></td></tr>';
2984 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return');
2985 - $shipping_address_info .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html(usces_localized_name( $values['delivery']['name1'], $values['delivery']['name2'], 'return' )) . '</td></tr>';
2986 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_after', 'return');
2987 -//20131213_kitamura_start
2988 - if( count( $options['system']['target_market'] ) != 1 ){
2989 - $shipping_address_info .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($usces_settings['country'][$values['delivery']['country']]) . '</td></tr>';
2990 - }
2991 -//20131213_kitamura_end
2992 - $shipping_address_info .= '
2993 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['delivery']['pref']) . '</td></tr>
2994 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr>
2995 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr>
2996 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr>
2997 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>
2998 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>
2999 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>';
3000 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return');
3001 - $formtag .= apply_filters('usces_filter_shipping_address_info', $shipping_address_info);
4387 + case 'customer':
4388 + case 'delivery':
4389 + $values = $data[ $type ];
3002 4390 break;
3003 -
3004 - case 'US':
3005 - default :
3006 - $formtag .= usces_custom_field_info($data, 'customer', 'name_pre', 'return');
3007 - $formtag .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['customer']['name2']) . ' ' . esc_html($values['customer']['name1']) . '</td></tr>';
3008 - $formtag .= usces_custom_field_info($data, 'customer', 'name_after', 'return');
3009 - $customer_country = (!empty($usces_settings['country'][$values['customer']['country']])) ? $usces_settings['country'][$values['customer']['country']] : '';
3010 - $formtag .= '
3011 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['customer']['address2']) . '</td></tr>
3012 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['customer']['address3']) . '</td></tr>
3013 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['customer']['address1']) . '</td></tr>
3014 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['customer']['pref']) . '</td></tr>';
4391 + }
4392 + $data['type'] = $type;
4393 + $values['country'] = ! empty( $values['country'] ) ? $values['country'] : usces_get_local_addressform();
4394 + $values = $usces->stripslashes_deep_post( $values );
4395 + $target_market_count = ( isset( $options['system']['target_market'] ) && is_array( $options['system']['target_market'] ) ) ? count( $options['system']['target_market'] ) : 1;
3015 4396
3016 -//20131213_kitamura_start
3017 - if( count( $options['system']['target_market'] ) != 1 ){
3018 - $formtag .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($customer_country) . '</td></tr>';
3019 - }
3020 -//20131213_kitamura_end
3021 - $formtag .= '
3022 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['customer']['zipcode']) . '</td></tr>
3023 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['customer']['tel']) . '</td></tr>
3024 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['customer']['fax']) . '</td></tr>';
3025 - $formtag .= usces_custom_field_info($data, 'customer', 'fax_after', 'return');
3026 -
3027 - $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>'.__('Shipping address information', 'usces').'</h3></td></tr>';
3028 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_pre', 'return');
3029 - $shipping_address_info .= '<tr><th>'.__('Full name', 'usces').'</th><td>' . esc_html($values['delivery']['name2']) . ' ' . esc_html($values['delivery']['name1']) . '</td></tr>';
3030 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'name_after', 'return');
3031 - $shipping_country = (!empty($usces_settings['country'][$values['delivery']['country']])) ? $usces_settings['country'][$values['delivery']['country']] : '';
3032 - $shipping_address_info .= '
3033 - <tr><th>'.__('Address Line1', 'usces').'</th><td>' . esc_html($values['delivery']['address2']) . '</td></tr>
3034 - <tr><th>'.__('Address Line2', 'usces').'</th><td>' . esc_html($values['delivery']['address3']) . '</td></tr>
3035 - <tr><th>'.__('city', 'usces').'</th><td>' . esc_html($values['delivery']['address1']) . '</td></tr>
3036 - <tr><th>'.__('State', 'usces').'</th><td>' . esc_html($values['delivery']['pref']) . '</td></tr>';
3037 -//20131213_kitamura_start
3038 - if( count( $options['system']['target_market'] ) != 1 ){
3039 - $shipping_address_info .= '<tr><th>'.__('Country', 'usces').'</th><td>' . esc_html($shipping_country) . '</td></tr>';
3040 - }
3041 -//20131213_kitamura_end
3042 - $shipping_address_info .= '
3043 - <tr><th>'.__('Zip', 'usces').'</th><td>' . esc_html($values['delivery']['zipcode']) . '</td></tr>
3044 - <tr><th>'.__('Phone number', 'usces').'</th><td>' . esc_html($values['delivery']['tel']) . '</td></tr>
3045 - <tr><th>'.__('FAX number', 'usces').'</th><td>' . esc_html($values['delivery']['fax']) . '</td></tr>';
3046 - $shipping_address_info .= usces_custom_field_info($data, 'delivery', 'fax_after', 'return');
3047 - $formtag .= apply_filters('usces_filter_shipping_address_info', $shipping_address_info);
3048 - break;
3049 -
4397 + if ( 'confirm' === $type ) {
4398 +
4399 + switch ( $applyform ) {
4400 +
4401 + case 'JP':
4402 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4403 + $formtag .= '<tr class="name-row member-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . esc_html( sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name1'] ) . ' ' . esc_html( $values['customer']['name2'] ) ) ) ) . '</td></tr>';
4404 + $furigana = ( '' === ( trim( $values['customer']['name3'] ) . trim( $values['customer']['name4'] ) ) ) ? '' : sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name3'] ) . ' ' . esc_html( $values['customer']['name4'] ) ) );
4405 + $furigana_customer = '<tr class="furikana-row member-furikana-row"><th>' . __( 'furigana', 'usces' ) . '</th><td>' . $furigana . '</td></tr>';
4406 + $formtag .= apply_filters( 'usces_filter_furigana_confirm_customer', $furigana_customer, $type, $values );
4407 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4408 + $formtag .= '<tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip/Postal Code', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>';
4409 + if ( 1 < $target_market_count ) {
4410 + $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4411 + $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4412 + }
4413 + $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4414 + $formtag .= '
4415 + <tr class="states-row member-states-row"><th>' . __( 'Province', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>
4416 + <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4417 + <tr class="address2-row member-address2-row"><th>' . __( 'numbers', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4418 + <tr class="address3-row member-address3-row"><th>' . __( 'building name', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4419 + <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4420 + <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4421 + $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4422 +
4423 + $shipping_address_info = '';
4424 + if ( isset( $values['delivery'] ) ) {
4425 + $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4426 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4427 + $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['delivery']['name1'] ) . ' ' . esc_html( $values['delivery']['name2'] ) ) ) . '</td></tr>';
4428 + $deli_furigana = ( '' === ( trim( $values['delivery']['name3'] ) . trim( $values['delivery']['name4'] ) ) ) ? '' : sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['delivery']['name3'] ) . ' ' . esc_html( $values['delivery']['name4'] ) ) );
4429 + $furigana_delivery = '<tr class="furikana-row delivery-furikana-row"><th>' . __( 'furigana', 'usces' ) . '</th><td>' . $deli_furigana . '</td></tr>';
4430 + $shipping_address_info .= apply_filters( 'usces_filter_furigana_confirm_delivery', $furigana_delivery, $type, $values );
4431 + $shipping_address_info .= usces_custom_field_info( $values, 'delivery', 'name_after', 'return' );
4432 + $shipping_address_info .= '<tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip/Postal Code', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>';
4433 + if ( 1 < $target_market_count ) {
4434 + $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4435 + $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4436 + }
4437 + $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4438 + $shipping_address_info .= '
4439 + <tr class="states-row delivery-states-row"><th>' . __( 'Province', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>
4440 + <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4441 + <tr class="address2-row delivery-address2-row"><th>' . __( 'numbers', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4442 + <tr class="address3-row delivery-address3-row"><th>' . __( 'building name', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4443 + <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4444 + <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4445 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4446 + }
4447 + $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4448 + break;
4449 +
4450 + case 'CN':
4451 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4452 + $formtag .= '<tr class="name-row member-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), esc_html( usces_localized_name( $values['customer']['name1'], $values['customer']['name2'], 'return' ) ) ) . '</td></tr>';
4453 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4454 + if ( 1 < $target_market_count ) {
4455 + $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4456 + $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4457 + }
4458 + $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4459 + $formtag .= '
4460 + <tr class="states-row member-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>
4461 + <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4462 + <tr class="address2-row member-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4463 + <tr class="address3-row member-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4464 + <tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>
4465 + <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4466 + <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4467 + $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4468 +
4469 + $shipping_address_info = '';
4470 + if ( isset( $values['delivery'] ) ) {
4471 + $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4472 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4473 + $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), esc_html( usces_localized_name( $values['delivery']['name1'], $values['delivery']['name2'], 'return' ) ) ) . '</td></tr>';
4474 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_after', 'return' );
4475 + if ( 1 < $target_market_count ) {
4476 + $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4477 + $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4478 + }
4479 + $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4480 + $shipping_address_info .= '
4481 + <tr class="states-row delivery-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>
4482 + <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4483 + <tr class="address2-row delivery-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4484 + <tr class="address3-row delivery-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4485 + <tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>
4486 + <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4487 + <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4488 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4489 + }
4490 + $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4491 + break;
4492 +
4493 + case 'US':
4494 + default:
4495 + $customer_pref = ( __( '-- Select --', 'usces' ) === $values['customer']['pref'] || '-- Select --' === $values['customer']['pref'] ) ? '' : $values['customer']['pref'];
4496 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_pre', 'return' );
4497 + $formtag .= '<tr class="name-row member-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['customer']['name2'] ) . ' ' . esc_html( $values['customer']['name1'] ) ) ) . '</td></tr>';
4498 + $formtag .= usces_custom_field_info( $data, 'customer', 'name_after', 'return' );
4499 + $formtag .= '
4500 + <tr class="address2-row member-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address2'] ) . '</td></tr>
4501 + <tr class="address3-row member-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address3'] ) . '</td></tr>
4502 + <tr class="address1-row member-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['customer']['address1'] ) . '</td></tr>
4503 + <tr class="states-row member-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $customer_pref ) . '</td></tr>';
4504 + if ( 1 < $target_market_count ) {
4505 + $customer_country = ( ! empty( $usces_settings['country'][ $values['customer']['country'] ] ) ) ? $usces_settings['country'][ $values['customer']['country'] ] : '';
4506 + $formtag .= '<tr class="country-row member-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $customer_country ) . '</td></tr>';
4507 + }
4508 + $formtag .= '
4509 + <tr class="zipcode-row member-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['customer']['zipcode'] ) . '</td></tr>
4510 + <tr class="tel-row member-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['tel'] ) . '</td></tr>
4511 + <tr class="fax-row member-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['customer']['fax'] ) . '</td></tr>';
4512 + $formtag .= usces_custom_field_info( $data, 'customer', 'fax_after', 'return' );
4513 +
4514 + $shipping_address_info = '';
4515 + if ( isset( $values['delivery'] ) ) {
4516 + $delivery_pref = ( __( '-- Select --', 'usces' ) === $values['delivery']['pref'] || '-- Select --' === $values['delivery']['pref'] ) ? '' : $values['delivery']['pref'];
4517 + $shipping_address_info = '<tr class="ttl"><td colspan="2"><h3>' . __( 'Shipping address information', 'usces' ) . '</h3></td></tr>';
4518 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_pre', 'return' );
4519 + $shipping_address_info .= '<tr class="name-row delivery-name-row"><th>' . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th><td>' . sprintf( _x( '%s', 'honorific', 'usces' ), ( esc_html( $values['delivery']['name2'] ) . ' ' . esc_html( $values['delivery']['name1'] )) ) . '</td></tr>';
4520 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'name_after', 'return' );
4521 + $shipping_address_info .= '
4522 + <tr class="address2-row delivery-address2-row"><th>' . __( 'Address Line1', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address2'] ) . '</td></tr>
4523 + <tr class="address3-row delivery-address3-row"><th>' . __( 'Address Line2', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address3'] ) . '</td></tr>
4524 + <tr class="address1-row delivery-address1-row"><th>' . __( 'city', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['address1'] ) . '</td></tr>
4525 + <tr class="states-row delivery-states-row"><th>' . __( 'State', 'usces' ) . '</th><td>' . esc_html( $delivery_pref ) . '</td></tr>';
4526 + if ( 1 < $target_market_count ) {
4527 + $shipping_country = ( ! empty( $usces_settings['country'][ $values['delivery']['country'] ] ) ) ? $usces_settings['country'][ $values['delivery']['country'] ] : '';
4528 + $shipping_address_info .= '<tr class="country-row delivery-country-row"><th>' . __( 'Country', 'usces' ) . '</th><td>' . esc_html( $shipping_country ) . '</td></tr>';
4529 + }
4530 + $shipping_address_info .= '
4531 + <tr class="zipcode-row delivery-zipcode-row"><th>' . __( 'Zip', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['zipcode'] ) . '</td></tr>
4532 + <tr class="tel-row delivery-tel-row"><th>' . __( 'Phone number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['tel'] ) . '</td></tr>
4533 + <tr class="fax-row delivery-fax-row"><th>' . __( 'FAX number', 'usces' ) . '</th><td>' . esc_html( $values['delivery']['fax'] ) . '</td></tr>';
4534 + $shipping_address_info .= usces_custom_field_info( $data, 'delivery', 'fax_after', 'return' );
4535 + }
4536 + $formtag .= apply_filters( 'usces_filter_shipping_address_info', $shipping_address_info );
4537 + break;
3050 4538 }
3051 - $res = apply_filters('usces_filter_apply_addressform_confirm', $formtag, $type, $data);
3052 -
3053 - }else{
3054 -
3055 - switch ($applyform){
3056 -
3057 - case 'JP':
3058 - $formtag .= usces_custom_field_input($data, $type, 'name_pre', 'return');
3059 - $formtag .= '<tr class="inp1">
3060 - <th width="127" scope="row">' . usces_get_essential_mark('name1', $data) . __('Full name', 'usces').'</th>';
3061 - if( $nameform ){
3062 - $formtag .= '<td class="name_td">'.__('Given name', 'usces').'<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3063 - $formtag .= '<td class="name_td">'.__('Familly name', 'usces').'<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3064 - }else{
3065 - $formtag .= '<td class="name_td">'.__('Familly name', 'usces').'<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr($values['name1']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3066 - $formtag .= '<td class="name_td">'.__('Given name', 'usces').'<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr($values['name2']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3067 - }
3068 - $formtag .= '</tr>';
3069 - $furigana = '<tr class="inp1">
3070 - <th scope="row">' . usces_get_essential_mark('name3', $data).__('furigana', 'usces').'</th>';
3071 - if( $nameform ){
3072 - $furigana .= '<td>'.__('Given name', 'usces').'<input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr($values['name4']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3073 - $furigana .= '<td>'.__('Familly name', 'usces').'<input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr($values['name3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3074 - }else{
3075 - $furigana .= '<td>'.__('Familly name', 'usces').'<input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr($values['name3']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3076 - $furigana .= '<td>'.__('Given name', 'usces').'<input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr($values['name4']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
3077 - }
3078 - $furigana .= '</tr>';
3079 - $formtag .= apply_filters( 'usces_filter_furigana_form', $furigana, $type, $values );
3080 - $formtag .= usces_custom_field_input($data, $type, 'name_after', 'return');
3081 - $formtag .= '<tr>
3082 - <th scope="row">' . usces_get_essential_mark('zipcode', $data).__('Zip/Postal Code', 'usces').'</th>
3083 - <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr($values['zipcode']) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />'.apply_filters('usces_filter_addressform_zipcode', NULL, $type) . apply_filters( 'usces_filter_after_zipcode', '100-1000', $applyform ) . '</td>
3084 - </tr>';
3085 -//20131213_kitamura_start
3086 - if( count( $options['system']['target_market'] ) == 1 ){
3087 - $formtag .= '<input type="hidden" name="' .$type. '[country]" id="' .$type. '_country" value="' .$options['system']['target_market'][0]. '">';
3088 - }else{
3089 - $formtag .= '<tr>
3090 - <th scope="row">' . usces_get_essential_mark('country', $data) . __('Country', 'usces') . '</th>
3091 - <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', NULL, $applyform ) . '</td>
4539 + $res = apply_filters( 'usces_filter_apply_addressform_confirm', $formtag, $type, $data );
4540 +
4541 + } else {
4542 +
4543 + switch ( $applyform ) {
4544 +
4545 + case 'JP':
4546 + $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4547 + $formtag .= '<tr id="name_row" class="inp1">
4548 + <th width="127" scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4549 + if ( $nameform ) {
4550 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Given name', 'usces' ) . '</span><input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4551 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Familly name', 'usces' ) . '</span><input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4552 + } else {
4553 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Familly name', 'usces' ) . '</span><input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4554 + $formtag .= '<td class="name_td"><span class="member_name">' . __( 'Given name', 'usces' ) . '</span><input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4555 + }
4556 + $formtag .= '</tr>';
4557 + $furigana = '<tr id="furikana_row" class="inp1">
4558 + <th scope="row">' . usces_get_essential_mark( 'name3', $data ) . __( 'furigana', 'usces' ) . '</th>';
4559 + if ( $nameform ) {
4560 + $furigana .= '<td><span class="member_furigana">' . _x( 'Given name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr( $values['name4'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4561 + $furigana .= '<td><span class="member_furigana">' . _x( 'Familly name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr( $values['name3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4562 + } else {
4563 + $furigana .= '<td><span class="member_furigana">' . _x( 'Familly name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name3]" id="name3" type="text" value="' . esc_attr( $values['name3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4564 + $furigana .= '<td><span class="member_furigana">' . _x( 'Given name', 'furigana', 'usces' ) . '</span><input name="' . $type . '[name4]" id="name4" type="text" value="' . esc_attr( $values['name4'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" /></td>';
4565 + }
4566 + $furigana .= '</tr>';
4567 + $formtag .= apply_filters( 'usces_filter_furigana_form', $furigana, $type, $values );
4568 + $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4569 + $formtag .= '<tr id="zipcode_row">
4570 + <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip/Postal Code', 'usces' ) . '</th>
4571 + <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr( $values['zipcode'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . usces_postal_code_address_search( $type ) . apply_filters( 'usces_filter_addressform_zipcode', null, $type ) . apply_filters( 'usces_filter_after_zipcode', '100-1000', $applyform ) . '</td>
3092 4572 </tr>';
3093 - }
3094 -//20131213_kitamura_end
3095 - $formtag .= '<tr>
3096 - <th scope="row">' . usces_get_essential_mark('states', $data).__('Province', 'usces').'</th>
3097 - <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', NULL, $applyform ) . '</td>
3098 - </tr>
3099 - <tr class="inp2">
3100 - <th scope="row">' . usces_get_essential_mark('address1', $data).__('city', 'usces').'</th>
3101 - <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>
3102 - </tr>
3103 - <tr>
3104 - <th scope="row">' . usces_get_essential_mark('address2', $data).__('numbers', 'usces').'</th>
3105 - <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>
3106 - </tr>
3107 - <tr>
3108 - <th scope="row">' . usces_get_essential_mark('address3', $data).__('building name', 'usces').'</th>
3109 - <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>
3110 - </tr>
3111 - <tr>
3112 - <th scope="row">' . usces_get_essential_mark('tel', $data).__('Phone number', 'usces').'</th>
3113 - <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>
3114 - </tr>
3115 - <tr>
3116 - <th scope="row">' . usces_get_essential_mark('fax', $data).__('FAX number', 'usces').'</th>
3117 - <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>
3118 - </tr>';
3119 - $formtag .= usces_custom_field_input($data, $type, 'fax_after', 'return');
3120 - break;
3121 -
3122 - case 'CN':
3123 - $formtag .= usces_custom_field_input($data, $type, 'name_pre', 'return');
3124 - $formtag .= '<tr class="inp1">
3125 - <th scope="row">' . usces_get_essential_mark('name1', $data) . __('Full name', 'usces') . '</th>';
3126 - if( $nameform ){
3127 - $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>';
3128 - $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>';
3129 - }else{
3130 - $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>';
3131 - $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>';
3132 - }
3133 - $formtag .= '</tr>';
3134 - $formtag .= usces_custom_field_input($data, $type, 'name_after', 'return');
3135 -//20131213_kitamura_start
3136 - if( count( $options['system']['target_market'] ) == 1 ){
3137 - $formtag .= '<input type="hidden" name="' .$type. '[country]" id="' .$type. '_country" value="' .$options['system']['target_market'][0]. '">';
3138 - }else{
3139 - $formtag .= '<tr>
3140 - <th scope="row">' . usces_get_essential_mark('country', $data) . __('Country', 'usces') . '</th>
3141 - <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', NULL, $applyform ) . '</td>
4573 + if ( 1 < $target_market_count ) {
4574 + $formtag .= '<tr id="country_row">
4575 + <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4576 + <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4577 + </tr>';
4578 + } else {
4579 + $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . $options['system']['target_market'][0] . '">';
4580 + }
4581 + $formtag .= '<tr id="states_row">
4582 + <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'Province', 'usces' ) . '</th>
4583 + <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4584 + </tr>
4585 + <tr id="address1_row" class="inp2">
4586 + <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4587 + <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr( $values['address1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address1', __( 'Kitakami Yokohama', 'usces' ), $applyform ) . '</td>
4588 + </tr>
4589 + <tr id="address2_row">
4590 + <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'numbers', 'usces' ) . '</th>
4591 + <td colspan="2"><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr( $values['address2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address2', '3-24-555', $applyform ) . '</td>
4592 + </tr>
4593 + <tr id="address3_row">
4594 + <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'building name', 'usces' ) . '</th>
4595 + <td colspan="2"><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr( $values['address3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: active" />' . apply_filters( 'usces_filter_after_address3', __( 'tuhanbuild 4F', 'usces' ), $applyform ) . '</td>
4596 + </tr>
4597 + <tr id="tel_row">
4598 + <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4599 + <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr( $values['tel'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . apply_filters( 'usces_filter_after_tel', '1000-10-1000', $applyform ) . '</td>
4600 + </tr>
4601 + <tr id="fax_row">
4602 + <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4603 + <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr( $values['fax'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" style="ime-mode: inactive" />' . apply_filters( 'usces_filter_after_fax', '1000-10-1000', $applyform ) . '</td>
3142 4604 </tr>';
3143 - }
3144 -//20131213_kitamura_end
3145 - $formtag .= '<tr>
3146 - <th scope="row">' . usces_get_essential_mark('states', $data) . __('State', 'usces') . '</th>
3147 - <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', NULL, $applyform ) . '</td>
3148 - </tr>
3149 - <tr class="inp2">
3150 - <th scope="row">' . usces_get_essential_mark('address1', $data) . __('city', 'usces') . '</th>
3151 - <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>
3152 - </tr>
3153 - <tr>
3154 - <th scope="row">' . usces_get_essential_mark('address2', $data) . __('Address Line1', 'usces') . '</th>
3155 - <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>
3156 - </tr>
3157 - <tr>
3158 - <th scope="row">' . usces_get_essential_mark('address3', $data) . __('Address Line2', 'usces') . '</th>
3159 - <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>
3160 - </tr>
3161 - <tr>
3162 - <th scope="row">' . usces_get_essential_mark('zipcode', $data) . __('Zip', 'usces') . '</th>
3163 - <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>
3164 - </tr>
3165 - <tr>
3166 - <th scope="row">' . usces_get_essential_mark('tel', $data) . __('Phone number', 'usces') . '</th>
3167 - <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>
3168 - </tr>
3169 - <tr>
3170 - <th scope="row">' . usces_get_essential_mark('fax', $data) . __('FAX number', 'usces') . '</th>
3171 - <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>
3172 - </tr>';
3173 - $formtag .= usces_custom_field_input($data, $type, 'fax_after', 'return');
3174 - break;
3175 -
3176 - case 'US':
3177 - default :
3178 - $formtag .= usces_custom_field_input($data, $type, 'name_pre', 'return');
3179 - $formtag .= '<tr class="inp1">
3180 - <th scope="row">' . usces_get_essential_mark('name1', $data) . __('Full name', 'usces') . '</th>';
3181 - if( $nameform ){
3182 - $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>';
3183 - $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>';
3184 - }else{
3185 - $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>';
3186 - $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>';
3187 - }
3188 - $formtag .= '</tr>';
3189 - $formtag .= usces_custom_field_input($data, $type, 'name_after', 'return');
3190 - $formtag .= '
3191 - <tr>
3192 - <th scope="row">' . usces_get_essential_mark('address2', $data) . __('Address Line1', 'usces') . '</th>
3193 - <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>
3194 - </tr>
3195 - <tr>
3196 - <th scope="row">' . usces_get_essential_mark('address3', $data) . __('Address Line2', 'usces') . '</th>
3197 - <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>
3198 - </tr>
3199 - <tr class="inp2">
3200 - <th scope="row">' . usces_get_essential_mark('address1', $data) . __('city', 'usces') . '</th>
3201 - <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>
3202 - </tr>
3203 - <tr>
3204 - <th scope="row">' . usces_get_essential_mark('states', $data) . __('State', 'usces') . '</th>
3205 - <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', NULL, $applyform ) . '</td>
3206 - </tr>';
3207 -//20131213_kitamura_start
3208 - if( count( $options['system']['target_market'] ) == 1 ){
3209 - $formtag .= '<input type="hidden" name="' .$type. '[country]" id="' .$type. '_country" value="' .$options['system']['target_market'][0]. '">';
3210 - }else{
3211 - $formtag .= '<tr>
3212 - <th scope="row">' . usces_get_essential_mark('country', $data) . __('Country', 'usces') . '</th>
3213 - <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', NULL, $applyform ) . '</td>
4605 + $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4606 + break;
4607 +
4608 + case 'CN':
4609 + $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4610 + $formtag .= '<tr id="name_row" class="inp1">
4611 + <th scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4612 + if ( $nameform ) {
4613 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4614 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4615 + } else {
4616 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4617 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4618 + }
4619 + $formtag .= '</tr>';
4620 + $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4621 + if ( 1 < $target_market_count ) {
4622 + $formtag .= '<tr id="country_row">
4623 + <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4624 + <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4625 + </tr>';
4626 + } else {
4627 + $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . $options['system']['target_market'][0] . '">';
4628 + }
4629 + $formtag .= '<tr id="states_row">
4630 + <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'State', 'usces' ) . '</th>
4631 + <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4632 + </tr>
4633 + <tr id="address1_row" class="inp2">
4634 + <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4635 + <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr( $values['address1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address1', null, $applyform ) . '</td>
4636 + </tr>
4637 + <tr id="address2_row">
4638 + <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'Address Line1', 'usces' ) . '</th>
4639 + <td colspan="2">' . __( 'Street address', 'usces' ) . '<br /><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr( $values['address2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address2', null, $applyform ) . '</td>
4640 + </tr>
4641 + <tr id="address3_row">
4642 + <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'Address Line2', 'usces' ) . '</th>
4643 + <td colspan="2">' . __( 'Apartment, building, etc.', 'usces' ) . '<br /><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr( $values['address3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address3', null, $applyform ) . '</td>
4644 + </tr>
4645 + <tr id="zipcode_row">
4646 + <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip', 'usces' ) . '</th>
4647 + <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr( $values['zipcode'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_zipcode', null, $applyform ) . '</td>
4648 + </tr>
4649 + <tr id="tel_row">
4650 + <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4651 + <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr( $values['tel'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_tel', null, $applyform ) . '</td>
4652 + </tr>
4653 + <tr id="fax_row">
4654 + <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4655 + <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr( $values['fax'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_fax', null, $applyform ) . '</td>
3214 4656 </tr>';
3215 - }
3216 -//20131213_kitamura_end
3217 - $formtag .= '<tr>
3218 - <th scope="row">' . usces_get_essential_mark('zipcode', $data) . __('Zip', 'usces') . '</th>
3219 - <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>
3220 - </tr>
3221 - <tr>
3222 - <th scope="row">' . usces_get_essential_mark('tel', $data) . __('Phone number', 'usces') . '</th>
3223 - <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>
3224 - </tr>
3225 - <tr>
3226 - <th scope="row">' . usces_get_essential_mark('fax', $data) . __('FAX number', 'usces') . '</th>
3227 - <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>
3228 - </tr>';
3229 - $formtag .= usces_custom_field_input($data, $type, 'fax_after', 'return');
3230 - break;
4657 + $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4658 + break;
4659 +
4660 + case 'US':
4661 + default:
4662 + $formtag .= usces_custom_field_input( $data, $type, 'name_pre', 'return' );
4663 + $formtag .= '<tr id="name_row" class="inp1">
4664 + <th scope="row">' . usces_get_essential_mark( 'name1', $data ) . apply_filters( 'usces_filters_addressform_name_label', __( 'Full name', 'usces' ), $type, $values, $applyform ) . '</th>';
4665 + if ( $nameform ) {
4666 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4667 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4668 + } else {
4669 + $formtag .= '<td>' . __( 'Familly name', 'usces' ) . '<input name="' . $type . '[name1]" id="name1" type="text" value="' . esc_attr( $values['name1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4670 + $formtag .= '<td>' . __( 'Given name', 'usces' ) . '<input name="' . $type . '[name2]" id="name2" type="text" value="' . esc_attr( $values['name2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" /></td>';
4671 + }
4672 + $formtag .= '</tr>';
4673 + $formtag .= usces_custom_field_input( $data, $type, 'name_after', 'return' );
4674 + $formtag .= '
4675 + <tr id="address2_row">
4676 + <th scope="row">' . usces_get_essential_mark( 'address2', $data ) . __( 'Address Line1', 'usces' ) . '</th>
4677 + <td colspan="2">' . __( 'Street address', 'usces' ) . '<br /><input name="' . $type . '[address2]" id="address2" type="text" value="' . esc_attr( $values['address2'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address2', null, $applyform ) . '</td>
4678 + </tr>
4679 + <tr id="address3_row">
4680 + <th scope="row">' . usces_get_essential_mark( 'address3', $data ) . __( 'Address Line2', 'usces' ) . '</th>
4681 + <td colspan="2">' . __( 'Apartment, building, etc.', 'usces' ) . '<br /><input name="' . $type . '[address3]" id="address3" type="text" value="' . esc_attr( $values['address3'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address3', null, $applyform ) . '</td>
4682 + </tr>
4683 + <tr id="address1_row" class="inp2">
4684 + <th scope="row">' . usces_get_essential_mark( 'address1', $data ) . __( 'city', 'usces' ) . '</th>
4685 + <td colspan="2"><input name="' . $type . '[address1]" id="address1" type="text" value="' . esc_attr( $values['address1'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_address1', null, $applyform ) . '</td>
4686 + </tr>
4687 + <tr id="states_row">
4688 + <th scope="row">' . usces_get_essential_mark( 'states', $data ) . __( 'State', 'usces' ) . '</th>
4689 + <td colspan="2">' . usces_pref_select( $type, $values ) . apply_filters( 'usces_filter_after_states', null, $applyform ) . '</td>
4690 + </tr>';
4691 + if ( 1 < $target_market_count ) {
4692 + $formtag .= '<tr id="country_row">
4693 + <th scope="row">' . usces_get_essential_mark( 'country', $data ) . __( 'Country', 'usces' ) . '</th>
4694 + <td colspan="2">' . uesces_get_target_market_form( $type, $values['country'] ) . apply_filters( 'usces_filter_after_country', null, $applyform ) . '</td>
4695 + </tr>';
4696 + } else {
4697 + $formtag .= '<input type="hidden" name="' . $type . '[country]" id="' . $type . '_country" value="' . esc_attr( $options['system']['target_market'][0] ) . '">';
4698 + }
4699 + $formtag .= '<tr id="zipcode_row">
4700 + <th scope="row">' . usces_get_essential_mark( 'zipcode', $data ) . __( 'Zip', 'usces' ) . '</th>
4701 + <td colspan="2"><input name="' . $type . '[zipcode]" id="zipcode" type="text" value="' . esc_attr( $values['zipcode'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_zipcode', null, $applyform ) . '</td>
4702 + </tr>
4703 + <tr id="tel_row">
4704 + <th scope="row">' . usces_get_essential_mark( 'tel', $data ) . __( 'Phone number', 'usces' ) . '</th>
4705 + <td colspan="2"><input name="' . $type . '[tel]" id="tel" type="text" value="' . esc_attr( $values['tel'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_tel', null, $applyform ) . '</td>
4706 + </tr>
4707 + <tr id="fax_row">
4708 + <th scope="row">' . usces_get_essential_mark( 'fax', $data ) . __( 'FAX number', 'usces' ) . '</th>
4709 + <td colspan="2"><input name="' . $type . '[fax]" id="fax" type="text" value="' . esc_attr( $values['fax'] ) . '" onKeyDown="if (event.keyCode == 13) {return false;}" />' . apply_filters( 'usces_filter_after_fax', null, $applyform ) . '</td>
4710 + </tr>';
4711 + $formtag .= usces_custom_field_input( $data, $type, 'fax_after', 'return' );
4712 + break;
3231 4713 }
3232 - $res = apply_filters('usces_filter_apply_addressform', $formtag, $type, $data);
3233 -
4714 + $res = apply_filters( 'usces_filter_apply_addressform', $formtag, $type, $data );
3234 4715 }
3235 4716
3236 - if($out == 'return') {
4717 + if ( 'return' === $out ) {
3237 4718 return $res;
3238 4719 } else {
3239 - echo $res;
4720 + echo $res; // no escape due to filter.
3240 4721 }
3241 4722 }
3242 4723
3243 -function usces_item_option_fileds( $post_id, $sku, $label=1, $out='echo' ){
3244 - $options = usces_get_opts($post_id, 'sort');
3245 - if( 0 == count($options) )
4724 +/**
4725 + * Item option field
4726 + *
4727 + * @param int $post_id Post ID.
4728 + * @param string $sku SKU code.
4729 + * @param int $label Tabel.
4730 + * @param string $out Return value or echo.
4731 + * @return string|void
4732 + */
4733 +function usces_item_option_fileds( $post_id, $sku, $label = 1, $out = 'echo' ) {
4734 + $options = wel_get_opts( $post_id, 'sort' );
4735 + if ( ! $options || ! is_array( $options ) ) {
3246 4736 return false;
3247 -
3248 - $sku_enc = urlencode($sku);
3249 - $html ='';
3250 - foreach( $options as $opt ){
3251 - $name = $opt['name'];
3252 - $opt_code = urlencode($name);
3253 - $html .= "\n" . '<div class="opt_field" id="opt_' . $post_id . '_' . $sku_enc . '_' . $opt_code . '">';
3254 - if( $label ){
3255 - $html .= '<label for="itemOption[' . $post_id . '][' . $sku_enc . '][' . $opt_code . ']">' . esc_html($name) . '</label>';
4737 + }
4738 + if ( 0 === count( $options ) ) {
4739 + return false;
4740 + }
4741 + $sku_enc = urlencode( $sku );
4742 +
4743 + $html = '';
4744 + foreach ( $options as $opt ) {
4745 + $name = $opt['name'];
4746 + $opt_code = urlencode( $name );
4747 + $html .= '<div class="opt_field" id="opt_' . $post_id . '_' . $sku_enc . '_' . $opt_code . '">';
4748 + if ( $label ) {
4749 + $html .= '<label for="itemOption[' . $post_id . '][' . $sku_enc . '][' . $opt_code . ']">' . esc_html( $name ) . '</label>';
3256 4750 }
3257 - $html .= usces_get_itemopt_filed($post_id, $sku, $opt);
4751 + $html .= usces_get_itemopt_filed( $post_id, $sku, $opt );
3258 4752 $html .= '</div>';
3259 4753 }
3260 - if( $out == 'return' ){
3261 - return $html;
3262 - }else{
3263 - echo $html;
4754 + if ( 'return' === $out ) {
4755 + return wel_esc_script( $html );
4756 + } else {
4757 + wel_esc_script_e( $html );
3264 4758 }
3265 4759 }
3266 4760
3267 -function usces_facebook_like(){
4761 +/**
4762 + * Facebook
4763 + */
4764 +function usces_facebook_like() {
3268 4765 global $post, $usces;
3269 4766 $like = array(
3270 - 'url' => urlencode(get_permalink($post->ID)),
3271 - 'send' => 'false',
3272 - 'layout' => 'button_count', //standard, button_count, box_count
3273 - 'width' => '450',
3274 - 'height' => '35',
3275 - 'show_faces' => 'false',
3276 - 'action' => 'like', //like, recommend
4767 + 'url' => urlencode( get_permalink( $post->ID ) ),
4768 + 'send' => 'false',
4769 + 'layout' => 'button_count', /* standard, button_count, box_count */
4770 + 'width' => '450',
4771 + 'height' => '35',
4772 + 'show_faces' => 'false',
4773 + 'action' => 'like', /* like, recommend */
3277 4774 );
3278 4775 $like = apply_filters( 'usces_filter_facebook_like', $like, $post->ID );
3279 -?>
3280 -<iframe src="//www.facebook.com/plugins/like.php?href=<?php echo $like['url']; ?>&amp;send=<?php echo $like['send']; ?>&amp;layout=<?php echo $like['layout']; ?>&amp;width=<?php echo $like['width']; ?>&amp;show_faces=<?php echo $like['show_faces']; ?>&amp;action=<?php echo $like['action']; ?>&amp;colorscheme=light&amp;font=arial&amp;height=<?php echo $like['height']; ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:<?php echo $like['width']; ?>px; height:<?php echo $like['height']; ?>px;" allowTransparency="true"></iframe>
3281 -<?php
4776 + ?>
4777 +<iframe src="//www.facebook.com/plugins/like.php?href=<?php echo esc_url( $like['url'] ); ?>&amp;send=<?php echo esc_attr( $like['send'] ); ?>&amp;layout=<?php echo esc_attr( $like['layout'] ); ?>&amp;width=<?php echo esc_attr( $like['width'] ); ?>&amp;show_faces=<?php echo esc_attr( $like['show_faces'] ); ?>&amp;action=<?php echo esc_attr( $like['action'] ); ?>&amp;colorscheme=light&amp;font=arial&amp;height=<?php echo esc_attr( $like['height'] ); ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:<?php echo esc_attr( $like['width'] ); ?>px; height:<?php echo esc_attr( $like['height'] ); ?>px;" allowTransparency="true"></iframe>
4778 + <?php
3282 4779 }
3283 4780
3284 -function usces_action_confirm_page_point_inform_zeus() {
3285 - $html = usces_point_inform_zeus();
3286 - echo $html;
4781 +/**
4782 + * Checked
4783 + *
4784 + * @param string $chk Checked.
4785 + * @param string $key Key.
4786 + * @param string $out Return value or echo.
4787 + * @return string|void
4788 + */
4789 +function usces_checked( $chk, $key, $out = '' ) {
4790 + $checked = ( isset( $chk[ $key ] ) && 1 === (int) $chk[ $key ] );
4791 + if ( 'return' === $out ) {
4792 + return checked( $checked, true, false );
4793 + } else {
4794 + checked( $checked, true, true );
4795 + }
3287 4796 }
3288 4797
3289 -function usces_filter_confirm_point_inform_zeus( $html ) {
3290 - $html .= usces_point_inform_zeus();
3291 - return $html;
4798 +/**
4799 + * Custom field value
4800 + *
4801 + * @param string $field Field.
4802 + * @param string $key Key.
4803 + * @param string $id ID.
4804 + * @param string $out Return value or echo.
4805 + * @return string|void
4806 + */
4807 +function usces_get_custom_field_value( $field, $key, $id, $out = '' ) {
4808 + global $usces;
4809 +
4810 + $value = '';
4811 + switch ( $field ) {
4812 + case 'order':
4813 + $value = $usces->get_order_meta_value( 'csod_' . $key, $id );
4814 + break;
4815 + case 'customer':
4816 + $value = $usces->get_order_meta_value( 'cscs_' . $key, $id );
4817 + break;
4818 + case 'delivery':
4819 + $value = $usces->get_order_meta_value( 'csde_' . $key, $id );
4820 + break;
4821 + case 'member':
4822 + $value = $usces->get_member_meta_value( 'csmb_' . $key, $id );
4823 + break;
4824 + }
4825 +
4826 + if ( 'return' === $out ) {
4827 + return wel_esc_script( $value );
4828 + } else {
4829 + wel_esc_script_e( $value );
4830 + }
3292 4831 }
3293 4832
3294 -function usces_point_inform_zeus() {
3295 - global $usces, $usces_entries;
4833 +/**
4834 + * Address search button
4835 + *
4836 + * @param string $type Type.
4837 + * @param string $out Return value or echo.
4838 + * @return string|void
4839 + */
4840 +function usces_postal_code_address_search( $type, $out = 'return' ) {
4841 + global $usces;
4842 +
3296 4843 $html = '';
4844 + if ( isset( $usces->options['address_search'] ) && 'activate' === $usces->options['address_search'] ) {
4845 + $address_search_label = apply_filters( 'usces_filter_postal_code_address_search_label', '住所検索' );
4846 + $html = '<input type="button" id="search_zipcode" class="search-zipcode button" value="' . $address_search_label . '" onClick="AjaxZip3.zip2addr(\'' . esc_js( $type . '[zipcode]' ) . '\', \'\', \'' . esc_js( $type . '[pref]' ) . '\', \'' . esc_js( $type . '[address1]' ) . '\' );" >';
4847 + if ( 'delivery' === $type ) {
4848 + $entry = $usces->cart->get_entry();
4849 + $zipcode = ( isset( $entry['delivery']['zipcode'] ) ) ? $entry['delivery']['zipcode'] : '';
4850 + $html .= '<input type="hidden" id="search_zipcode_change" value="' . esc_attr( $zipcode ) . '">';
4851 + }
4852 + }
4853 + if ( 'return' === $out ) {
4854 + return wel_esc_script( $html );
4855 + } else {
4856 + wel_esc_script_e( $html );
4857 + }
4858 +}
3297 4859
3298 - $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
3299 - $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
4860 +/**
4861 + * Agreement Approval Field
4862 + *
4863 + * @param string $out Return value or echo.
4864 + * @return string|void
4865 + */
4866 +function usces_agree_member_field( $out = '' ) {
4867 + global $usces;
3300 4868
3301 - switch( $acting_flag ) {
3302 - case 'acting_zeus_card':
3303 - $html .= '<input type="hidden" name="cnum1" value="'.esc_attr($_POST['cnum1']).'">';
3304 - if( isset($_POST['securecode']) ) {
3305 - $html .= '<input type="hidden" name="securecode" value="'.esc_attr($_POST['securecode']).'">';
4869 + $html = '';
4870 + if ( usces_is_membersystem_state() ) {
4871 + $row = '';
4872 + if ( isset( $usces->options['agree_member'] ) && 'activate' === $usces->options['agree_member'] ) {
4873 + $row .= '<div class="agree_member_area">';
4874 + if ( isset( $usces->options['member_page_data']['agree_member_exp'] ) ) {
4875 + $row .= '<div class="at_exp_text">' . stripslashes( nl2br( $usces->options['member_page_data']['agree_member_exp'] ) ) . '</div>';
4876 + }
4877 + if ( isset( $usces->options['member_page_data']['agree_member_cont'] ) ) {
4878 + $row .= '<textarea name="at_cont_text" class="at_cont_text" readonly="readonly">' . $usces->options['member_page_data']['agree_member_cont'] . '</textarea>
4879 + <div class="at_check_area"><input name="agree_member_check" value="1" id="agree_member_check" class="at_check" type="checkbox"><label for="agree_member_check" style="cursor:pointer;"> ' . __( 'Accept the membership agreement', 'usces' ) . '</label></div>';
4880 + }
4881 + $row .= '</div>';
3306 4882 }
3307 - $html .= '<input type="hidden" name="expyy" value="'.esc_attr($_POST['expyy']).'">';
3308 - $html .= '<input type="hidden" name="expmm" value="'.esc_attr($_POST['expmm']).'">';
3309 - $html .= '<input type="hidden" name="username_card" value="'.esc_attr($_POST['username_card']).'">';
3310 - if( isset($usces_entries['order']['howpay']) ) {
3311 - $html .= '<input type="hidden" name="offer[howpay]" value="'.esc_attr($usces_entries['order']['howpay']).'">';
4883 + $html = apply_filters( 'usces_filter_agree_member_field', $row );
4884 + }
4885 +
4886 + if ( 'return' === $out ) {
4887 + return wel_esc_script( $html );
4888 + } else {
4889 + wel_esc_script_e( $html );
4890 + }
4891 +}
4892 +
4893 +/**
4894 + * No image
4895 + *
4896 + * @param array $size Size.
4897 + * @param string $alt Alt.
4898 + * @return string
4899 + */
4900 +function usces_get_attachment_noimage( $size = array( 60, 60 ), $alt = '' ) {
4901 + $size_class = join( 'x', $size );
4902 + return '<img width="' . $size[0] . '" height="' . $size[1] . '" src="' . USCES_PLUGIN_URL . '/images/default.png" class="attachment-' . $size_class . ' size-' . $size_class . '" alt="' . $alt . '">';
4903 +}
4904 +
4905 +/**
4906 + * Tax rate
4907 + *
4908 + * @param string $out Return value or echo.
4909 + * @return string|void
4910 + */
4911 +function usces_the_taxrate( $out = '' ) {
4912 + global $usces;
4913 +
4914 + if ( isset( $usces->itemsku['taxrate'] ) ) {
4915 + $taxrate = ( 'reduced' === $usces->itemsku['taxrate'] ) ? $usces->options['tax_rate_reduced'] : $usces->options['tax_rate'];
4916 + } else {
4917 + $taxrate = $usces->options['tax_rate'];
4918 + }
4919 + $the_taxrate = '<em class="tax">' . sprintf( __( "Tax Rate %s%%", 'usces' ), $taxrate ) . '</em>';
4920 + $the_taxrate = apply_filters( 'usces_filter_the_taxrate', $the_taxrate, $usces->itemsku, $out );
4921 +
4922 + if ( 'return' === $out ) {
4923 + return wel_esc_script( $the_taxrate );
4924 + } else {
4925 + wel_esc_script_e( $the_taxrate );
4926 + }
4927 +}
4928 +
4929 +/**
4930 + * Tax amount
4931 + *
4932 + * @param string $out Return value or echo.
4933 + * @return string|void
4934 + */
4935 +function usces_cart_tax( $out = '' ) {
4936 + global $usces;
4937 +
4938 + $total_items_price = $usces->get_total_price();
4939 + $materials = array(
4940 + 'total_items_price' => $total_items_price,
4941 + 'discount' => 0,
4942 + 'shipping_charge' => 0,
4943 + 'cod_fee' => 0,
4944 + 'use_point' => 0,
4945 + );
4946 + $tax = $usces->getTax( $total_items_price, $materials );
4947 +
4948 + if ( 'return' === $out ) {
4949 + return wel_esc_script( $tax );
4950 + } else {
4951 + wel_esc_script_e( $tax );
4952 + }
4953 +}
4954 +
4955 +/**
4956 + * Total tax amount
4957 + *
4958 + * @param string $out Return value or echo.
4959 + * @return string|void
4960 + */
4961 +function usces_confirm_tax( $out = '' ) {
4962 + global $usces;
4963 +
4964 + if ( $usces->is_reduced_taxrate() ) {
4965 + if ( 'include' === $usces->options['tax_mode'] ) {
4966 + $po = '( ';
4967 + $pc = ' )';
4968 + } else {
4969 + $po = '';
4970 + $pc = '';
3312 4971 }
3313 - if( isset($usces_entries['order']['cbrand']) ) {
3314 - $html .= '<input type="hidden" name="offer[cbrand]" value="'.esc_attr($usces_entries['order']['cbrand']).'">';
3315 - $html .= '<input type="hidden" name="offer[div_1]" value="'.esc_attr($usces_entries['order']['div_1']).'">';
3316 - $html .= '<input type="hidden" name="offer[div_2]" value="'.esc_attr($usces_entries['order']['div_2']).'">';
3317 - $html .= '<input type="hidden" name="offer[div_3]" value="'.esc_attr($usces_entries['order']['div_3']).'">';
4972 + $usces_tax = Welcart_Tax::get_instance();
4973 + $entry = wel_get_entry();
4974 + $shipping_charge = isset( $entry['order']['shipping_charge'] ) ? $entry['order']['shipping_charge'] : 0;
4975 + $cod_fee = isset( $entry['order']['cod_fee'] ) ? $entry['order']['cod_fee'] : 0;
4976 + $materials = compact( 'shipping_charge', 'cod_fee');
4977 + $usces_tax->get_order_tax( $materials );
4978 + $tax = sprintf( __( "Applies to %s%%", 'usces' ), $usces->options['tax_rate'] ) . '&nbsp;&nbsp;' . usces_crform( $usces_tax->subtotal_standard + $usces_tax->discount_standard, true, false, 'return' ) . '&nbsp;&nbsp;';
4979 + $tax .= sprintf( __( "%s%% consumption tax", 'usces' ), $usces->options['tax_rate'] ) . '&nbsp;&nbsp;' . $po . usces_crform( $usces_tax->tax_standard, true, false, 'return' ) . $pc . '<br />';
4980 + if ( 0 < $usces_tax->tax_rate_reduced ) {
4981 + $tax .= sprintf( __( "Applies to %s%%", 'usces' ), $usces->options['tax_rate_reduced'] ) . '&nbsp;&nbsp;' . usces_crform( $usces_tax->subtotal_reduced + $usces_tax->discount_reduced, true, false, 'return' ) . '&nbsp;&nbsp;';
4982 + $tax .= sprintf( __( "%s%% consumption tax", 'usces' ), $usces->options['tax_rate_reduced'] ) . '&nbsp;&nbsp;' . $po . usces_crform( $usces_tax->tax_reduced, true, false, 'return' ) . $pc;
3318 4983 }
3319 - break;
4984 + } else {
4985 + $tax = '';
4986 + }
3320 4987
3321 - case 'acting_zeus_conv':
3322 - if( isset($_POST['pay_cvs']) ) {
3323 - $html .= '<input type="hidden" name="offer[pay_cvs]" value="'.esc_attr($usces_entries['order']['pay_cvs']).'">';
3324 - $html .= '<input type="hidden" name="username_conv" value="'.esc_attr($_POST['username_conv']).'">';
4988 + $tax = apply_filters( 'usces_filter_confirm_tax', $tax, $out );
4989 +
4990 + if ( 'return' === $out ) {
4991 + return wel_esc_script( $tax );
4992 + } else {
4993 + wel_esc_script_e( $tax );
4994 + }
4995 +}
4996 +
4997 +/**
4998 + * Tax-included amount
4999 + *
5000 + * @param string $out Return value or echo.
5001 + * @return string|void
5002 + */
5003 +function usces_the_itemPrice_taxincluded( $out = '' ) {
5004 + global $post, $usces;
5005 + $usces_tax = Welcart_Tax::get_instance();
5006 +
5007 + if ( empty( $usces->itemsku['code'] ) ) {
5008 + $skus = $usces->get_skus( $post->ID );
5009 + $skucode = $skus[0]['code'];
5010 + $skuprice = $skus[0]['price'];
5011 + } else {
5012 + $skucode = $usces->itemsku['code'];
5013 + $skuprice = $usces->itemsku['price'];
5014 + }
5015 + $tax_rate = $usces_tax->get_sku_tax_rate( $post->ID, $skucode );
5016 + $tax = (float) sprintf( '%.3f', (float) $skuprice * (float) $tax_rate / 100 );
5017 + $tax = usces_tax_rounding_off( $tax );
5018 + $price = $skuprice + $tax;
5019 +
5020 + if ( 'return' === $out ) {
5021 + return $price;
5022 + } else {
5023 + echo number_format( $price );
5024 + }
5025 +}
5026 +
5027 +/**
5028 + * Tax-included normal amount
5029 + *
5030 + * @param string $out Return value or echo.
5031 + * @return string|void
5032 + */
5033 +function usces_the_itemCprice_taxincluded( $out = '' ) {
5034 + global $post, $usces;
5035 + $usces_tax = Welcart_Tax::get_instance();
5036 +
5037 + if ( empty( $usces->itemsku['code'] ) ) {
5038 + $skus = $usces->get_skus( $post->ID );
5039 + $skucode = $skus[0]['code'];
5040 + $skucprice = $skus[0]['cprice'];
5041 + } else {
5042 + $skucode = $usces->itemsku['code'];
5043 + $skucprice = $usces->itemsku['cprice'];
5044 + }
5045 + $tax_rate = $usces_tax->get_sku_tax_rate( $post->ID, $skucode );
5046 + $tax = (float) sprintf( '%.3f', (float) $skucprice * (float) $tax_rate / 100 );
5047 + $tax = usces_tax_rounding_off( $tax );
5048 + $price = $skucprice + $tax;
5049 + if ( 'return' === $out ) {
5050 + return $price;
5051 + } else {
5052 + echo number_format( $price );
5053 + }
5054 +}
5055 +
5056 +/**
5057 + * Formatted tax included amount
5058 + *
5059 + * @param string $out Return value or echo.
5060 + * @return string|void
5061 + */
5062 +function usces_the_itemPriceCr_taxincluded( $out = '' ) {
5063 + global $usces;
5064 + $usces_tax = Welcart_Tax::get_instance();
5065 +
5066 + $price_taxincluded = usces_the_itemPrice_taxincluded( 'return' );
5067 + $price = $usces->get_currency( $price_taxincluded, true, false );
5068 + $price = apply_filters( 'usces_filter_the_item_price_cr_taxincluded', $price, $price_taxincluded, $out );
5069 + if ( 'return' === $out ) {
5070 + return $price;
5071 + } else {
5072 + echo esc_html( $price );
5073 + }
5074 +}
5075 +
5076 +/**
5077 + * Formatted tax included normal amount
5078 + *
5079 + * @param string $out Return value or echo.
5080 + * @return string|void
5081 + */
5082 +function usces_the_itemCpriceCr_taxincluded( $out = '' ) {
5083 + global $usces;
5084 + $usces_tax = Welcart_Tax::get_instance();
5085 +
5086 + $price_taxincluded = usces_the_itemCprice_taxincluded( 'return' );
5087 + $price = $usces->get_currency( $price_taxincluded, true, false );
5088 + $price = apply_filters( 'usces_filter_the_item_cprice_cr_taxincluded', $price, $price_taxincluded, $out );
5089 + if ( 'return' === $out ) {
5090 + return $price;
5091 + } else {
5092 + echo esc_html( $price );
5093 + }
5094 +}
5095 +
5096 +/**
5097 + * Password policy
5098 + *
5099 + * @param string $out Return value or echo.
5100 + * @return string|void
5101 + */
5102 +function usces_password_policy_message( $out = '' ) {
5103 +
5104 + $usces_options = get_option( 'usces', array() );
5105 + $rules = array();
5106 + $sep = '';
5107 +
5108 + if ( ! empty( $usces_options['system']['member_pass_rule_max'] ) ) {
5109 + if ( $usces_options['system']['member_pass_rule_max'] === $usces_options['system']['member_pass_rule_min'] ) {
5110 + $rules[] = sprintf( __( '%s characters long', 'usces' ), $usces_options['system']['member_pass_rule_min'] );
5111 + } else {
5112 + $rules[] = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $usces_options['system']['member_pass_rule_min'], $usces_options['system']['member_pass_rule_max'] );
5113 + $sep = __( 'use', 'usces' );
3325 5114 }
3326 - break;
5115 + } else {
5116 + $rules[] = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $usces_options['system']['member_pass_rule_min'], '30' );
5117 + $sep = __( 'use', 'usces' );
3327 5118 }
3328 - return $html;
5119 +
5120 + $and = __( 'and', 'usces' );
5121 +
5122 + if ( ! empty( $usces_options['system']['member_pass_rule_digit'] ) ) {
5123 + $rules[] = __( 'numeric character', 'usces' );
5124 + }
5125 +
5126 + if ( ! empty( $usces_options['system']['member_pass_rule_lowercase'] ) ) {
5127 + $rules[] = __( 'lower-case alphabetics', 'usces' );
5128 + }
5129 +
5130 + if ( ! empty( $usces_options['system']['member_pass_rule_upercase'] ) ) {
5131 + $rules[] = __( 'upper-case alphabetics', 'usces' );
5132 + }
5133 +
5134 + if ( ! empty( $usces_options['system']['member_pass_rule_symbol'] ) ) {
5135 + $rules[] = __( 'symbolic character', 'usces' );
5136 + }
5137 +
5138 + $first = array_shift( $rules );
5139 + $ret = '';
5140 + if ( 0 === count( $rules ) ) {
5141 + $ret = sprintf( __( 'Password must be at least %s.', 'usces' ), $first );
5142 + } elseif ( 1 === count( $rules ) ) {
5143 + $rule1 = sprintf( __( ' and include one or more %s', 'usces' ), $rules[0] );
5144 + $ret = sprintf( __( 'Password must be at least %1$s%2$s.', 'usces' ), $first, $rule1 );
5145 + } else {
5146 + $rule2 = '';
5147 + foreach ( $rules as $rule ) {
5148 + if ( '' !== $rule2 ) {
5149 + $rule2 .= __( ',', 'usces' );
5150 + }
5151 + $rule2 .= $rule;
5152 + }
5153 + $rule1 = sprintf( __( ' and include one or more %s', 'usces' ), $rule2 );
5154 + $ret = sprintf( __( 'Password must be at least %1$s%2$s.', 'usces' ), $first, $rule1 );
5155 + }
5156 +
5157 + $ret = apply_filters( 'usces_filter_password_policy_message', $ret );
5158 + if ( 'return' === $out ) {
5159 + return $ret;
5160 + }
5161 +
5162 + echo '<p class="password_policy">' . esc_html( $ret ) . '</p>';
3329 5163 }
3330 5164
3331 -function usces_checked( $chk, $key, $out = '' ) {
3332 - $checked = ( isset($chk[$key]) and $chk[$key] == 1 ) ? ' checked' : '';
3333 - if( $out == 'return' ) {
3334 - return $checked;
5165 +/**
5166 + * Formatted tax included amount
5167 + *
5168 + * @param bool $label_pre Forward label.
5169 + * @param string $label Label.
5170 + * @param string $start_tag Start tag.
5171 + * @param string $end_tag End tag.
5172 + * @param bool $symbol_pre Forward symbol.
5173 + * @param bool $symbol_post Backward symbol.
5174 + * @param bool $seperator_flag Seperator.
5175 + * @param string $out Return value or echo.
5176 + * @return string|void
5177 + */
5178 +function usces_crform_the_itemPriceCr_taxincluded( $label_pre = true, $label = '', $start_tag = '', $end_tag = '', $symbol_pre = true, $symbol_post = false, $seperator_flag = true, $out = '' ) {
5179 + global $usces;
5180 +
5181 + if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
5182 + $res = '';
3335 5183 } else {
3336 - echo $checked;
5184 + $price_taxincluded = usces_the_itemPrice_taxincluded( 'return' );
5185 + $price = esc_html( $usces->get_currency( $price_taxincluded, $symbol_pre, $symbol_post, $seperator_flag ) );
5186 + if ( empty( $label ) ) {
5187 + $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
5188 + } else {
5189 + $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
5190 + }
5191 + if ( empty( $start_tag ) ) {
5192 + $start_tag = '<p class="tax_inc_block">( ';
5193 + }
5194 + if ( $label_pre ) {
5195 + $start_tag = $start_tag . $label_tag;
5196 + }
5197 + if ( empty( $end_tag ) ) {
5198 + $end_tag = ' )</p>';
5199 + }
5200 + if ( true !== $label_pre ) {
5201 + $end_tag = $label_tag . $end_tag;
5202 + }
5203 + $res = apply_filters( 'usces_filter_crform_the_itemPriceCr_taxincluded', $start_tag . $price . $end_tag, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
3337 5204 }
5205 + if ( 'return' === $out ) {
5206 + return wel_esc_script( $res );
5207 + } else {
5208 + wel_esc_script_e( $res );
5209 + }
3338 5210 }
3339 5211
3340 -function usces_get_custom_field_value( $field, $key, $id, $out = '' ) {
5212 +/**
5213 + * Tax-included amount
5214 + *
5215 + * @param int $post_id Post ID.
5216 + * @return float
5217 + */
5218 +function usces_itemPrice_taxincluded( $post_id = null ) {
3341 5219 global $usces;
3342 5220
3343 - $value = '';
3344 - switch( $field ) {
3345 - case 'order':
3346 - $value = $usces->get_order_meta_value( 'csod_'.$key, $id );
3347 - break;
3348 - case 'customer':
3349 - $value = $usces->get_order_meta_value( 'cscs_'.$key, $id );
3350 - break;
3351 - case 'delivery':
3352 - $value = $usces->get_order_meta_value( 'csde_'.$key, $id );
3353 - break;
3354 - case 'member':
3355 - $value = $usces->get_member_meta_value( 'csmb_'.$key, $id );
3356 - break;
5221 + if ( null === $post_id ) {
5222 + global $post;
5223 + $post_id = $post->ID;
3357 5224 }
5225 + $usces_tax = Welcart_Tax::get_instance();
3358 5226
3359 - if( $out == 'return' ) {
3360 - return $value;
5227 + $skus = $usces->get_skus( $post_id );
5228 + $skucode = $skus[0]['code'];
5229 + $skuprice = $skus[0]['price'];
5230 + $tax_rate = $usces_tax->get_sku_tax_rate( $post_id, $skucode );
5231 + $tax = (float) sprintf( '%.3f', (float) $skuprice * (float) $tax_rate / 100 );
5232 + $tax = usces_tax_rounding_off( $tax );
5233 + $price = $skuprice + $tax;
5234 + return $price;
5235 +}
5236 +
5237 +/**
5238 + * Tax-included normal amount
5239 + *
5240 + * @param int $post_id Post ID.
5241 + * @param bool $label_pre Forward label.
5242 + * @param string $label Label.
5243 + * @param string $start_tag Start tag.
5244 + * @param string $end_tag End tag.
5245 + * @param bool $symbol_pre Forward symbol.
5246 + * @param bool $symbol_post Backward symbol.
5247 + * @param bool $seperator_flag Seperator.
5248 + * @return string
5249 + */
5250 +function usces_crform_itemPriceCr_taxincluded( $post_id = null, $label_pre = true, $label = '', $start_tag = '', $end_tag = '', $symbol_pre = true, $symbol_post = false, $seperator_flag = true ) {
5251 + global $usces;
5252 +
5253 + if ( ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) || ( isset( $usces->options['tax_mode'] ) && 'include' === $usces->options['tax_mode'] ) ) {
5254 + $res = '';
3361 5255 } else {
3362 - echo $value;
5256 + $price_taxincluded = usces_itemPrice_taxincluded( $post_id );
5257 + $price = esc_html( $usces->get_currency( $price_taxincluded, $symbol_pre, $symbol_post, $seperator_flag ) );
5258 + if ( empty( $label ) ) {
5259 + $label_tag = '<em class="tax tax_inc_label">' . __( 'tax-included', 'usces' ) . '</em>';
5260 + } else {
5261 + $label_tag = '<em class="tax tax_inc_label">' . $label . '</em>';
5262 + }
5263 + if ( empty( $start_tag ) ) {
5264 + $start_tag = '<p class="tax_inc_block">( ';
5265 + }
5266 + if ( $label_pre ) {
5267 + $start_tag = $start_tag . $label_tag;
5268 + }
5269 + if ( empty( $end_tag ) ) {
5270 + $end_tag = ' )</p>';
5271 + }
5272 + if ( true !== $label_pre ) {
5273 + $end_tag = $label_tag . $end_tag;
5274 + }
5275 + $res = apply_filters( 'usces_filter_crform_itemPriceCr_taxincluded', $start_tag . $price . $end_tag, $post_id, $label_pre, $label, $symbol_pre, $symbol_post, $seperator_flag );
3363 5276 }
5277 + return $res;
3364 5278 }
3365 5279
5280 +/**
5281 + * Cart Totals
5282 + *
5283 + * @param string $out Return value or echo.
5284 + * @return string|void
5285 + */
5286 +function usces_get_cart_total_rows( $out = '' ) {
5287 + global $usces;
3366 5288
3367 -?>
5289 + $res = '';
5290 + if ( isset( $usces->options['tax_display'] ) && 'deactivate' !== $usces->options['tax_display'] ) {
5291 + if ( isset( $usces->options['tax_mode'] ) && 'include' !== $usces->options['tax_mode'] ) {
5292 + $total = usces_total_price( 'return' );
5293 + $tax = usces_cart_tax( 'return' );
5294 + $res .= ' <tr>
5295 + <th class="num"></th>
5296 + <th class="thumbnail"></th>
5297 + <th colspan="3" scope="row" class="aright">' . __( 'Total', 'usces' ) . '</th>
5298 + <th class="aright amount">' . usces_crform( $total, true, false, true ) . '</th>
5299 + <th class="stock"></th>
5300 + <th class="action"></th>
5301 + </tr>' . "\n";
5302 + $res .= ' <tr class="tax">
5303 + <th class="num"></th>
5304 + <th class="thumbnail"></th>
5305 + <th colspan="3" scope="row" class="aright tax">' . __( 'Tax', 'usces' ) . '</th>
5306 + <th class="aright amount tax">' . usces_crform( usces_cart_tax( 'return' ), true, false, true ) . '</th>
5307 + <th class="stock"></th>
5308 + <th class="action"></th>
5309 + </tr>' . "\n";
5310 + $res .= ' <tr>
5311 + <th class="num"></th>
5312 + <th class="thumbnail"></th>
5313 + <th colspan="3" scope="row" class="aright">' . __( 'total items', 'usces' ) . '</th>
5314 + <th class="aright amount">' . usces_crform( $total + $tax, true, false, true ) . '</th>
5315 + <th class="stock"></th>
5316 + <th class="action"></th>
5317 + </tr>' . "\n";
5318 + } else {
5319 + $total = usces_total_price( 'return' );
5320 + $tax = usces_internal_tax( array( 'total_items_price' => $total ), 'return' );
5321 + $res .= ' <tr class="tax">
5322 + <th class="num"></th>
5323 + <th class="thumbnail"></th>
5324 + <th colspan="3" scope="row" class="aright tax">' . __( 'Internal tax', 'usces' ) . '</th>
5325 + <th class="aright amount tax">( ' . usces_crform( $tax, true, false, true ) . ' )</th>
5326 + <th class="stock"></th>
5327 + <th class="action"></th>
5328 + </tr>' . "\n";
5329 + $res .= ' <tr>
5330 + <th class="num"></th>
5331 + <th class="thumbnail"></th>
5332 + <th colspan="3" scope="row" class="aright">' . __( 'total items', 'usces' ) . '</th>
5333 + <th class="aright amount">' . usces_crform( $total, true, false, true ) . '</th>
5334 + <th class="stock"></th>
5335 + <th class="action"></th>
5336 + </tr>' . "\n";
5337 + }
5338 + }
5339 + if ( 'return' === $out ) {
5340 + return wel_esc_script( $res );
5341 + } else {
5342 + wel_esc_script_e( $res );
5343 + }
5344 +}
5345 +
5346 +if ( ! function_exists( 'welcart_assistance_excerpt_length' ) ) {
5347 + /**
5348 + * Assistance excerpt length
5349 + *
5350 + * @param int $length Length.
5351 + * @return int
5352 + */
5353 + function welcart_assistance_excerpt_length( $length ) {
5354 + return 10;
5355 + }
5356 +}
5357 +
5358 +if ( ! function_exists( 'welcart_assistance_excerpt_mblength' ) ) {
5359 + /**
5360 + * Assistance excerpt mobile length
5361 + *
5362 + * @param int $length Length.
5363 + * @return int
5364 + */
5365 + function welcart_assistance_excerpt_mblength( $length ) {
5366 + return 40;
5367 + }
5368 +}