PluginProbe
Welcart e-Commerce / 2.11.34
Welcart e-Commerce v2.11.34
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / functions / filters.php

filters.php in Welcart e-Commerce 2.11.34, at functions/filters.php

2,682 lines 81.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Welcart functions
4 *
5 * Hooking the main functions.
6 *
7 * @package Welcart
8 */
9
10 // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL
11 // phpcs:disable WordPress.PHP.DevelopmentFunctions, WordPress.PHP.NoSilencedErrors
12
13 /**
14 * Get postmeta.
15 *
16 * @param string $null Null value.
17 * @param int $object_id Post ID.
18 * @param string $meta_key Meta key.
19 * @param bool $single Text or Array.
20 * @return mixed
21 */
22 function usces_filter_get_post_metadata( $null, $object_id, $meta_key, $single ) {
23 global $wpdb;
24
25 $query = $wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $object_id, $meta_key );
26 $metas = $wpdb->get_col( $query );
27 if ( ! empty( $metas ) ) {
28 return array_map( 'maybe_unserialize', $metas );
29 }
30
31 if ( $single ) {
32 return '';
33 } else {
34 return array();
35 }
36 }
37
38 /**
39 * Save decorated order id.
40 * usces_action_reg_orderdata
41 *
42 * @param array $args {
43 * The array of order-related data.
44 * @type array $cart Cart data.
45 * @type array $entry Entry data.
46 * @type int $order_id Order ID.
47 * @type int $member_id Member ID.
48 * @type array $payments Payment Method.
49 * @type array $charging_type Charge type.
50 * @type array $results Settlement result data.
51 * }
52 */
53 function usces_action_reg_orderdata( $args ) {
54 global $usces;
55 extract( $args );
56
57 $options = get_option( 'usces', array() );
58 $prefix = $options['system']['dec_orderID_prefix'] ?? '';
59 $prefix = apply_filters( 'usces_filter_dec_order_id_prefix', $prefix, $args );
60
61 $dec_order_id = usces_make_deco_order_id( $order_id );
62 $dec_order_id = apply_filters( 'usces_filter_dec_order_id', $dec_order_id, $args );
63 $dec_order_id = $prefix . $dec_order_id;
64
65 $usces->set_order_meta_value( 'dec_order_id', $dec_order_id, $order_id );
66 }
67
68 /**
69 * Inventory (stock) adjustment.
70 * usces_action_reg_orderdata
71 *
72 * @param array $args {
73 * The array of order-related data.
74 * @type array $cart Cart data.
75 * @type array $entry Entry data.
76 * @type int $order_id Order ID.
77 * @type int $member_id Member ID.
78 * @type array $payments Payment Method.
79 * @type array $charging_type Charge type.
80 * @type array $results Settlement result data.
81 * }
82 */
83 function usces_action_reg_orderdata_stocks( $args ) {
84 global $usces;
85 extract( $args );
86
87 foreach ( $cart as $cartrow ) {
88
89 $item_order_acceptable = (int) $usces->getItemOrderAcceptable( $cartrow['post_id'], false );
90 $sku = urldecode( $cartrow['sku'] );
91 $zaikonum = $usces->getItemZaikoNum( $cartrow['post_id'], $sku, false );
92 if ( WCUtils::is_blank( $zaikonum ) ) {
93 continue;
94 }
95 $zaikonum = (int) $zaikonum - (int) $cartrow['quantity'];
96 if ( 1 !== $item_order_acceptable ) {
97 if ( $zaikonum < 0 ) {
98 $zaikonum = 0;
99 }
100 }
101
102 $usces->updateItemZaikoNum( $cartrow['post_id'], $sku, $zaikonum );
103
104 if ( 1 !== $item_order_acceptable ) {
105 if ( $zaikonum <= 0 ) {
106 $default_empty_status = apply_filters( 'usces_filter_default_empty_status', 2 );
107 $usces->updateItemZaiko( $cartrow['post_id'], $sku, $default_empty_status );
108 do_action( 'usces_action_outofstock', $cartrow['post_id'], $sku, $cartrow, $args );
109 }
110 }
111 }
112 }
113
114 /**
115 * Add security headers (member, cart).
116 * send_headers
117 *
118 * @return void
119 */
120 function usces_add_security_headers() {
121 global $usces;
122 if ( is_customize_preview() ) {
123 return;
124 }
125 $request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) );
126 if ( $usces->is_member_page( $request_uri ) || $usces->is_cart_page( $request_uri ) ) {
127 header( 'X-Frame-Options: DENY' );
128 header( "Content-Security-Policy: frame-ancestors 'none'" );
129 }
130 }
131
132 /**
133 * OGP meta.
134 * wp_head
135 */
136 function usces_action_ogp_meta() {
137 global $usces, $post;
138
139 if ( empty( $post ) || ! $usces->is_item( $post ) || ! is_single() ) {
140 return;
141 }
142
143 $item = wel_get_product( $post->ID );
144 $pictid = $usces->get_mainpictid( $item['itemCode'] );
145 $image_info = wp_get_attachment_image_src( $pictid, 'thumbnail' );
146
147 $ogs['title'] = $item['itemName'];
148 $ogs['type'] = 'product';
149 $ogs['description'] = strip_tags( get_the_title( $post->ID ) );
150 $ogs['url'] = get_permalink( $post->ID );
151 $ogs['image'] = ( isset( $image_info[0] ) ) ? $image_info[0] : '';
152 $ogs['site_name'] = get_option( 'blogname' );
153
154 $ogs = apply_filters( 'usces_filter_ogp_meta', $ogs, $post->ID );
155
156 foreach ( $ogs as $key => $value ) {
157 echo "\n" . '<meta property="og:' . esc_attr( $key ) . '" content="' . ( ( 'url' === $key || 'image' === $key ) ? esc_url( $value ) : esc_attr( $value ) ) . '">';
158 }
159 }
160
161 /**
162 * 構造化データのJSON出力.
163 * wp_head
164 */
165 function usces_action_structured_data_json() {
166 global $post, $usces;
167
168 if ( 0 === USCES_STRUCTURED_DATA_PRODUCT::$opts['status'] || empty( $post ) ) {
169 return;
170 }
171
172 global $post, $usces;
173 if ( empty( $post ) || ! $usces->is_item( $post ) ) {
174 return;
175 }
176
177 $product = wel_get_product( $post->ID );
178 if ( is_admin() || ! is_single() || ! $product['itemCode'] ) {
179 return;
180 }
181
182 $itemname = $product['itemName'];
183 $skus = $product['_sku'];
184 $target_sku = null;
185 $structuredDataSkuCode = $product['structuredDataSku'];
186 $patch_skus = array();
187
188 foreach ( $skus as $sku ) {
189 // 廃盤は削除.
190 if ( 4 === (int) $usces->getItemZaikoStatusId( $post->ID, $sku['code'] ) ) {
191 continue;
192 }
193 // 特定のSKUがあればそれを対象とする.
194 if ( $structuredDataSkuCode === $sku['code'] ) {
195 $target_sku = $sku;
196 }
197 $patch_skus[] = $sku;
198 }
199 if ( null === $target_sku ) {
200 foreach ( $patch_skus as $sku ) {
201 // 1番目のSKU.
202 if ( 'first' === USCES_STRUCTURED_DATA_PRODUCT::$opts['default_price'] ) {
203 $target_sku = $sku;
204 break;
205 }
206 // 1番安価のSKU.
207 if ( 'minimum' === USCES_STRUCTURED_DATA_PRODUCT::$opts['default_price'] ) {
208 if ( $target_sku && (int) $target_sku['price'] <= (int) $sku['price'] ) {
209 continue;
210 }
211 $target_sku = $sku;
212 } else {
213 if ( $target_sku && (int) $target_sku['price'] >= (int) $sku['price'] ) { // 1番高価のSKU.
214 continue;
215 }
216 $target_sku = $sku;
217 }
218 }
219 }
220 if ( empty( $target_sku ) ) {
221 return;
222 }
223 $target_sku['availability'] = $usces->is_item_zaiko( $post->ID, $sku['code'] ) ? 'https://schema.org/InStock' : 'https://schema.org/SoldOut';
224
225 $url = get_the_permalink();
226 $image = usces_the_itemImageURL( 0, 'return' );
227 $description = function_exists( 'get_field' ) ? get_field( 'field_rich_result_product_description' ) : '';
228 $stock = usces_have_zaiko_anyone( $post->ID ) ? 'https://schema.org/InStock' : 'https://schema.org/SoldOut';
229 $cr = $usces->options['system']['currency'];
230 if ( isset( $usces_settings['currency'][ $cr ] ) ) {
231 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
232 } else {
233 $code = 'JPY';
234 }
235 $data = array(
236 '@context' => 'https://schema.org/',
237 '@type' => 'Product',
238 'name' => $itemname,
239 'image' => $image,
240 'description' => $description,
241 'productID' => $product['itemCode'],
242 'offers' => [
243 '@type' => 'Offer',
244 'sku' => $product['itemCode'] . '-' . $target_sku['code'],
245 'priceCurrency' => $code,
246 'price' => $target_sku['price'],
247 'availability' => $target_sku['availability'],
248 ],
249 );
250 $script = json_encode( apply_filters( 'usces_filter_structured_data', $data, $post ) );
251
252 echo "\n" . '<script type="application/ld+json">' . $script . '</script>';
253 }
254
255 /**
256 * 特定のSKUデータを構造化データのに利用するためのフォーム.
257 * usces_item_master_first_section
258 *
259 * @param string $html First section area.
260 * @param int $post_ID Post Id.
261 */
262 function usces_item_master_structured_data( $html, $post_ID ) {
263 if ( 1 === USCES_STRUCTURED_DATA_PRODUCT::$opts['status'] ) {
264 $product = wel_get_product( $post_ID );
265 $structuredDataSku = ( isset( $product['structuredDataSku'] ) ) ? $product['structuredDataSku'] : '';
266 ?>
267 <tr>
268 <th><?php esc_html_e( 'SKUs Code used for structured data', 'usces' ); ?></th>
269 <td>
270 <input type="text" name="structuredDataSku" id="structuredDataSku" class="structuredDataSku" value="<?php echo esc_attr( $structuredDataSku ); ?>" />
271 <input type="hidden" name="structuredDataSku_nonce" id="structuredDataSku_nonce" value="<?php echo wp_create_nonce( 'structuredDataSku_nonce' ); ?>" />
272 </td>
273 </tr>
274 <?php
275 }
276 }
277
278 /**
279 * Make Directory.
280 */
281 function wc_mkdir() {
282 global $usces;
283 if ( is_admin() && ! WCUtils::is_blank( $usces->options['logs_path'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) ) {
284 $welcart_file_dir = $usces->options['logs_path'] . '/welcart';
285 $logs_dir = $welcart_file_dir . '/logs';
286 if ( ! file_exists( $welcart_file_dir ) ) {
287 $res = @mkdir( $welcart_file_dir, 0700 );
288 if ( ! $res ) {
289 $msg = '<div class="error"><p>下記のディレクトリーを、所有�
290 ' . get_current_user() . '、パーミッション:700 で作成してください。 <br />' . $welcart_file_dir . '</p></div>';
291 add_action(
292 'admin_notices',
293 function() {
294 echo addcslashes( $msg, '"' );
295 }
296 );
297 }
298 }
299 $stat = stat( $welcart_file_dir );
300 print_r( $stat );
301 }
302 }
303
304 /**
305 * Save the oreder cart data.
306 * usces_action_reg_orderdata
307 *
308 * @param array $args {
309 * The array of order-related data.
310 * @type array $cart Cart data.
311 * @type array $entry Entry data.
312 * @type int $order_id Order ID.
313 * @type int $member_id Member ID.
314 * @type array $payments Payment Method.
315 * @type array $charging_type Charge type.
316 * @type array $results Settlement result data.
317 * }
318 */
319 function usces_reg_ordercartdata( $args ) {
320 global $usces, $wpdb, $usces_settings;
321 extract( $args );
322
323 if ( ! $order_id ) {
324 return;
325 }
326 $cart_table = $wpdb->prefix . 'usces_ordercart';
327 $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
328
329 foreach ( $cart as $row_index => $value ) {
330 $post_id = (int) $value['post_id'];
331 $product = wel_get_product( $post_id, false );
332 $item_code = $product['itemCode'];
333 $item_name = $product['itemName'];
334 $skus = $usces->get_skus( $value['post_id'], 'code', false );
335 $sku_encoded = $value['sku'];
336 $skucode = urldecode( $value['sku'] );
337 $sku = $skus[ $skucode ];
338 $tax = 0;
339 $wpdb->query(
340 $wpdb->prepare(
341 "INSERT INTO {$cart_table}
342 (order_id, row_index, post_id, item_code, item_name, sku_code, sku_name, cprice, price, quantity,
343 unit, tax, destination_id, cart_serial )
344 VALUES (%d, %d, %d, %s, %s, %s, %s, %f, %f, %f, %s, %d, %d, %s)",
345 $order_id,
346 $row_index,
347 $post_id,
348 $item_code,
349 $item_name,
350 $skucode,
351 $sku['name'],
352 $sku['cprice'],
353 $value['price'],
354 $value['quantity'],
355 $sku['unit'],
356 $tax,
357 null,
358 $value['serial']
359 )
360 );
361
362 $cart_id = $wpdb->insert_id;
363 $opt_fields = wel_get_opts( $post_id, 'sort', false );
364
365 if ( $value['options'] ) {
366
367 foreach ( (array) $opt_fields as $okey => $val ) {
368
369 $enc_key = urlencode( $val['name'] );
370 $means = $opt_fields[ $okey ]['means'];
371
372 if ( 3 === (int) $means ) {
373
374 if ( '' == $value['options'][ $enc_key ] ) {
375 $ovalue = $value['options'][ $enc_key ];
376 } else {
377 $ovalue = urldecode( $value['options'][ $enc_key ] );
378 }
379 } elseif ( 4 === (int) $means ) {
380
381 if ( is_array( $value['options'][ $enc_key ] ) ) {
382
383 $temp = array();
384 foreach ( $value['options'][ $enc_key ] as $v ) {
385 $temp[] = urldecode( $v );
386 }
387 $ovalue = serialize( $temp );
388 } elseif ( '' == $value['options'][ $enc_key ] ) {
389
390 $ovalue = $value['options'][ $enc_key ];
391 } else {
392
393 $ovalue = urldecode( $value['options'][ $enc_key ] );
394 }
395 } else {
396
397 if ( is_array( $value['options'][ $enc_key ] ) ) {
398 $temp = array();
399 foreach ( $value['options'][ $enc_key ] as $k => $v ) {
400 $temp[ $k ] = urldecode( $v );
401 }
402 $ovalue = serialize( $temp );
403 } else {
404 $ovalue = urldecode( $value['options'][ $enc_key ] );
405 }
406 }
407 $ovalue = wel_safe_text_serialize( $ovalue );
408 $wpdb->query(
409 $wpdb->prepare(
410 "INSERT INTO {$cart_meta_table}
411 ( cart_id, meta_type, meta_key, meta_value ) VALUES (%d, %s, %s, %s)",
412 $cart_id,
413 'option',
414 $val['name'],
415 $ovalue
416 )
417 );
418 }
419 }
420
421 if ( $value['advance'] ) {
422
423 foreach ( (array) $value['advance'] as $akey => $avalue ) {
424 $advance = $usces->cart->wc_unserialize( $avalue );
425
426 if ( is_array( $advance ) ) {
427
428 if ( isset( $advance[ $post_id ][ $sku_encoded ] ) && is_array( $advance[ $post_id ][ $sku_encoded ] ) ) {
429 $akeys = array_keys( $advance[ $post_id ][ $sku_encoded ] );
430
431 foreach ( (array) $akeys as $akey ) {
432 if ( is_array( $advance[ $post_id ][ $sku_encoded ][ $akey ] ) ) {
433 $avalue = serialize( $advance[ $post_id ][ $sku_encoded ][ $akey ] );
434 } else {
435 $avalue = $advance[ $post_id ][ $sku_encoded ][ $akey ];
436 }
437 $wpdb->query(
438 $wpdb->prepare(
439 "INSERT INTO {$cart_meta_table}
440 ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, 'advance', %s, %s )",
441 $cart_id,
442 $akey,
443 $avalue
444 )
445 );
446 }
447 } else {
448 $akeys = array_keys( $advance );
449 $akey = empty( $akeys[0] ) ? 'advance' : $akeys[0];
450 $avalue = serialize( $advance );
451 $wpdb->query(
452 $wpdb->prepare(
453 "INSERT INTO {$cart_meta_table}
454 ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, 'advance', %s, %s )",
455 $cart_id,
456 $akey,
457 $avalue
458 )
459 );
460 }
461 } else {
462 $avalue = urldecode( $avalue );
463 $wpdb->query(
464 $wpdb->prepare(
465 "INSERT INTO {$cart_meta_table}
466 ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, 'advance', %s, %s )",
467 $cart_id,
468 $akey,
469 $avalue
470 )
471 );
472 }
473 }
474 }
475
476 if ( $usces->is_reduced_taxrate() ) {
477 if ( isset( $sku['taxrate'] ) && 'reduced' == $sku['taxrate'] ) {
478 $tkey = 'reduced';
479 $tvalue = $usces->options['tax_rate_reduced'];
480 } else {
481 $tkey = 'standard';
482 $tvalue = $usces->options['tax_rate'];
483 }
484 $wpdb->query(
485 $wpdb->prepare(
486 "INSERT INTO {$cart_meta_table}
487 ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, 'taxrate', %s, %s )",
488 $cart_id,
489 $tkey,
490 $tvalue
491 )
492 );
493 }
494
495 do_action( 'usces_action_reg_ordercart_row', $cart_id, $row_index, $value, $args );
496 }
497 }
498
499 /**
500 * Document title.
501 * pre_get_document_title
502 * wp_title
503 * alias fiter_mainTitle()
504 *
505 * @param string $title Document title.
506 * @param string $sep Separator.
507 * @return string
508 */
509 function filter_mainTitle( $title, $sep = '' ) {
510 return fiter_mainTitle( $title, $sep );
511 }
512
513 /**
514 * Document title.
515 *
516 * @param string $title Document title.
517 * @param string $sep Separator.
518 * @return string
519 */
520 function fiter_mainTitle( $title, $sep = '' ) {
521 global $usces;
522
523 if ( empty( $sep ) ) {
524 $sep = apply_filters( 'document_title_separator', '|' );
525 }
526
527 switch ( $usces->page ) {
528 case 'cart':
529 $newtitle = apply_filters( 'usces_filter_title_cart', __( 'In the cart', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
530 break;
531
532 case 'customer':
533 $newtitle = apply_filters( 'usces_filter_title_customer', __( 'Customer Information', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
534 break;
535
536 case 'delivery':
537 $newtitle = apply_filters( 'usces_filter_title_delivery', __( 'Shipping / Payment options', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
538 break;
539
540 case 'confirm':
541 $newtitle = apply_filters( 'usces_filter_title_confirm', __( 'Confirmation', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
542 break;
543
544 case 'ordercompletion':
545 $newtitle = apply_filters( 'usces_filter_title_ordercompletion', __( 'Order Complete', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
546 break;
547
548 case 'error':
549 $newtitle = apply_filters( 'usces_filter_title_error', __( 'Error', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' ); // new fitler name.
550 break;
551
552 case 'search_item':
553 $newtitle = apply_filters( 'usces_filter_title_search_item', __( "'AND' search by categories", 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
554 break;
555
556 case 'maintenance':
557 $newtitle = apply_filters( 'usces_filter_title_maintenance', __( 'Under Maintenance', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
558 break;
559
560 case 'login':
561 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
562 break;
563
564 case 'member':
565 $newtitle = apply_filters( 'usces_filter_title_member', __( 'Membership information', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
566 break;
567
568 case 'newmemberform':
569 $newtitle = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
570 break;
571
572 case 'newcompletion':
573 $newtitle = apply_filters( 'usces_filter_title_newcompletion', __( 'New enrollment complete', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' ); // new fitler name.
574 break;
575
576 case 'editmemberform':
577 $newtitle = apply_filters( 'usces_filter_title_editmemberform', __( 'Member information editing', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' ); // new fitler name.
578 break;
579
580 case 'editcompletion':
581 $newtitle = apply_filters( 'usces_filter_title_editcompletion', __( 'Membership information change is completed', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' ); // new fitler name.
582 break;
583
584 case 'lostmemberpassword':
585 $newtitle = apply_filters( 'usces_filter_title_lostmemberpassword', __( 'The new password acquisition', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
586 break;
587
588 case 'lostcompletion':
589 $newtitle = apply_filters( 'usces_filter_title_lostcompletion', __( 'New password procedures for obtaining complete', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' ); // new fitler name.
590 break;
591
592 case 'changepassword':
593 $newtitle = apply_filters( 'usces_filter_title_changepassword', __( 'Change password', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
594 break;
595
596 case 'changepasscompletion':
597 $newtitle = apply_filters( 'usces_filter_title_changepasscompletion', __( 'Password change is completed', 'usces' ) ) . ' ' . $sep . ' ' . get_bloginfo( 'name' );
598 break;
599
600 default:
601 $newtitle = $title;
602 }
603 return $newtitle;
604 }
605
606 /**
607 * Separator
608 * document_title_separator
609 *
610 * @param string $sep Separator.
611 * @return string
612 */
613 function usces_document_title_separator( $sep ) {
614 $sep = '|';
615 return $sep;
616 }
617
618 /**
619 * Univarsal Analytics( Dashboard )
620 *
621 * @return array
622 */
623 function usces_Universal_trackPageview() {
624 global $usces;
625
626 $push = array();
627
628 switch ( $usces->page ) {
629 case 'cart':
630 $push[] = "'page' : '/wc_cart'";
631 break;
632
633 case 'customer':
634 $push[] = "'page' : '/wc_customer'";
635 break;
636
637 case 'delivery':
638 $push[] = "'page' : '/wc_delivery'";
639 break;
640
641 case 'confirm':
642 $push[] = "'page' : '/wc_confirm'";
643 break;
644
645 case 'ordercompletion':
646 $push[] = "'page' : '/wc_ordercompletion'";
647 $sesdata = $usces->cart->get_entry();
648 if ( isset( $sesdata['order']['ID'] ) && ! empty( $sesdata['order']['ID'] ) ) {
649 $order_id = $sesdata['order']['ID'];
650 $data = $usces->get_order_data( $order_id, 'direct' );
651 $cart = unserialize( $data['order_cart'] );
652 $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
653 if ( $total_price < 0 ) {
654 $total_price = 0;
655 }
656
657 $push[] = "'require', 'ecommerce', 'ecommerce.js'";
658 $push[] = "'ecommerce:addTransaction', {
659 id: '" . $order_id . "',
660 affiliation: '" . esc_js( get_option( 'blogname' ) ) . "',
661 revenue: '" . $total_price . "',
662 shipping: '" . $data['order_shipping_charge'] . "',
663 tax: '" . $data['order_tax'] . "' }";
664 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
665 for ( $i = 0; $i < $cart_count; $i++ ) {
666 $cart_row = $cart[ $i ];
667 $post_id = $cart_row['post_id'];
668 $sku = urldecode( $cart_row['sku'] );
669 $quantity = $cart_row['quantity'];
670 $itemname = $usces->getItemName( $post_id );
671 $skuprice = $cart_row['price'];
672 $cats = $usces->get_item_cat_genre_ids( $post_id );
673 if ( is_array( $cats ) ) {
674 sort( $cats );
675 }
676 $category = ( isset( $cats[0] ) ) ? get_cat_name( $cats[0] ) : '';
677
678 $push[] = "'ecommerce:addItem', {
679 id: '" . $order_id . "',
680 sku: '" . esc_js( $sku ) . "',
681 name: '" . esc_js( $itemname ) . "',
682 category: '" . esc_js( $category ) . "',
683 price: '" . $skuprice . "',
684 quantity: '" . $quantity . "' }";
685 }
686 $push[] = "'ecommerce:send'";
687 }
688 break;
689
690 case 'error':
691 $push[] = "'page' : '/wc_error'";
692 break;
693
694 case 'search_item':
695 $push[] = "'page' : '/wc_search_item'";
696 break;
697
698 case 'maintenance':
699 $push[] = "'page' : '/wc_maintenance'";
700 break;
701
702 case 'login':
703 $push[] = "'page' : '/wc_login'";
704 break;
705
706 case 'member':
707 $push[] = "'page' : '/wc_member'";
708 break;
709
710 case 'newmemberform':
711 $push[] = "'page' : '/wc_newmemberform'";
712 break;
713
714 case 'newcompletion':
715 $push[] = "'page' : '/wc_newcompletion'";
716 break;
717
718 case 'editmemberform':
719 $push[] = "'page' : '/wc_editmemberform'";
720 break;
721
722 case 'editcompletion':
723 $push[] = "'page' : '/wc_editcompletion'";
724 break;
725
726 case 'lostmemberpassword':
727 $push[] = "'page' : '/wc_lostmemberpassword'";
728 break;
729
730 case 'lostcompletion':
731 $push[] = "'page' : '/wc_lostcompletion'";
732 break;
733
734 case 'changepassword':
735 $push[] = "'page' : '/wc_changepassword'";
736 break;
737
738 case 'changepasscompletion':
739 $push[] = "'page' : '/wc_changepasscompletion'";
740 break;
741
742 default:
743 break;
744 }
745 return $push;
746 }
747
748 /**
749 * Classic Analytics ( Dashboard )
750 *
751 * @return array
752 */
753 function usces_Classic_trackPageview() {
754 global $usces;
755
756 $push = array();
757
758 switch ( $usces->page ) {
759 case 'cart':
760 $push = usces_trackPageview_cart( $push );
761 break;
762
763 case 'customer':
764 $push = usces_trackPageview_customer( $push );
765 break;
766
767 case 'delivery':
768 $push = usces_trackPageview_delivery( $push );
769 break;
770
771 case 'confirm':
772 $push = usces_trackPageview_confirm( $push );
773 break;
774
775 case 'ordercompletion':
776 $push = usces_trackPageview_ordercompletion( $push );
777 break;
778
779 case 'error':
780 $push = usces_trackPageview_error( $push );
781 break;
782
783 case 'login':
784 $push = usces_trackPageview_login( $push );
785 break;
786
787 case 'member':
788 $push = usces_trackPageview_member( $push );
789 break;
790
791 case 'newmemberform':
792 $push = usces_trackPageview_newmemberform( $push );
793 break;
794
795 case 'newcompletion':
796 $push = usces_trackPageview_newcompletion( $push );
797 break;
798
799 case 'editmemberform':
800 $push = usces_trackPageview_editmemberform( $push );
801 break;
802
803 case 'search_item':
804 $push = usces_trackPageview_search_item( $push );
805 break;
806
807 case 'maintenance':
808 case 'editcompletion':
809 case 'lostmemberpassword':
810 case 'lostcompletion':
811 case 'changepassword':
812 case 'changepasscompletion':
813 default:
814 break;
815 }
816 return $push;
817 }
818
819 /**
820 * Univarsal Analytics( Yoast )
821 * monsterinsights_frontend_tracking_options_analytics_end
822 * yoast-ga-push-array-universal
823 *
824 * @param array $push Push array.
825 * @return array
826 */
827 function usces_Universal_trackPageview_by_Yoast( $push ) {
828 global $usces;
829
830 foreach ( $push as $p_key => $p_val ) {
831 $pos1 = strpos( (string) $p_val, "'send'" );
832 $pos2 = strpos( (string) $p_val, "'pageview'" );
833 if ( false !== $pos1 && false !== $pos2 ) {
834 unset( $push[ $p_key ] );
835 }
836 }
837
838 switch ( $usces->page ) {
839 case 'cart':
840 $push[] = "'send', 'pageview', {'page' : '/wc_cart'}";
841 break;
842
843 case 'customer':
844 $push[] = "'send', 'pageview', {'page' : '/wc_customer'}";
845 break;
846
847 case 'delivery':
848 $push[] = "'send', 'pageview', {'page' : '/wc_delivery'}";
849 break;
850
851 case 'confirm':
852 $push[] = "'send', 'pageview', {'page' : '/wc_confirm'}";
853 break;
854
855 case 'ordercompletion':
856 $push[] = "'send', 'pageview', {'page' : '/wc_ordercompletion'}";
857 $sesdata = $usces->cart->get_entry();
858 if ( isset( $sesdata['order']['ID'] ) && ! empty( $sesdata['order']['ID'] ) ) {
859 $order_id = $sesdata['order']['ID'];
860 $data = $usces->get_order_data( $order_id, 'direct' );
861 $cart = unserialize( $data['order_cart'] );
862 $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
863 if ( $total_price < 0 ) {
864 $total_price = 0;
865 }
866
867 $push[] = "'require', 'ecommerce', 'ecommerce.js'";
868 $push[] = "'ecommerce:addTransaction', {
869 id: '" . $order_id . "',
870 affiliation: '" . esc_js( get_option( 'blogname' ) ) . "',
871 revenue: '" . $total_price . "',
872 shipping: '" . $data['order_shipping_charge'] . "',
873 tax: '" . $data['order_tax'] . "'
874 }";
875 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
876 for ( $i = 0; $i < $cart_count; $i++ ) {
877 $cart_row = $cart[ $i ];
878 $post_id = $cart_row['post_id'];
879 $sku = urldecode( $cart_row['sku'] );
880 $quantity = $cart_row['quantity'];
881 $itemname = $usces->getItemName( $post_id );
882 $skuprice = $cart_row['price'];
883 $cats = $usces->get_item_cat_genre_ids( $post_id );
884 if ( is_array( $cats ) ) {
885 sort( $cats );
886 }
887 $category = ( isset( $cats[0] ) ) ? get_cat_name( $cats[0] ) : '';
888
889 $push[] = "'ecommerce:addItem', {
890 id: '" . $order_id . "',
891 sku: '" . esc_js( $sku ) . "',
892 name: '" . esc_js( $itemname ) . "',
893 category: '" . esc_js( $category ) . "',
894 price: '" . $skuprice . "',
895 quantity: '" . $quantity . "'
896 }";
897 }
898 $push[] = "'ecommerce:send'";
899 }
900 break;
901
902 case 'error':
903 $push[] = "'send', 'pageview', {'page' : '/wc_error'}";
904 break;
905
906 case 'search_item':
907 $push[] = "'send', 'pageview', {'page' : '/wc_search_item'}";
908 break;
909
910 case 'maintenance':
911 $push[] = "'send', 'pageview', {'page' : '/wc_maintenance'}";
912 break;
913
914 case 'login':
915 $push[] = "'send', 'pageview', {'page' : '/wc_login'}";
916 break;
917
918 case 'member':
919 $push[] = "'send', 'pageview', {'page' : '/wc_member'}";
920 break;
921
922 case 'newmemberform':
923 $push[] = "'send', 'pageview', {'page' : '/wc_newmemberform'}";
924 break;
925
926 case 'newcompletion':
927 $push[] = "'send', 'pageview', {'page' : '/wc_newcompletion'}";
928 break;
929
930 case 'editmemberform':
931 $push[] = "'send', 'pageview', {'page' : '/wc_editmemberform'}";
932 break;
933
934 case 'editcompletion':
935 $push[] = "'send', 'pageview', {'page' : '/wc_editcompletion'}";
936 break;
937
938 case 'lostmemberpassword':
939 $push[] = "'send', 'pageview', {'page' : '/wc_lostmemberpassword'}";
940 break;
941
942 case 'lostcompletion':
943 $push[] = "'send', 'pageview', {'page' : '/wc_lostcompletion'}";
944 break;
945
946 case 'changepassword':
947 $push[] = "'send', 'pageview', {'page' : '/wc_changepassword'}";
948 break;
949
950 case 'changepasscompletion':
951 $push[] = "'send', 'pageview', {'page' : '/wc_changepasscompletion'}";
952 break;
953
954 default:
955 $push[] = "'send', 'pageview'";
956 break;
957 }
958 return $push;
959 }
960
961 /**
962 * Order completion tracking.
963 * wp_enqueue_scripts
964 * monsterinsights_frontend_tracking_gtag_after_pageview
965 */
966 function usces_ecommerce_reporting() {
967 global $usces;
968
969 if ( 'ordercompletion' !== $usces->page ) {
970 return;
971 }
972
973 $sesdata = $usces->cart->get_entry();
974 if ( isset( $sesdata['order']['ID'] ) && ! empty( $sesdata['order']['ID'] ) ) {
975 $order_id = $sesdata['order']['ID'];
976 $data = $usces->get_order_data( $order_id, 'direct' );
977 $cart = unserialize( $data['order_cart'] );
978 $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
979 if ( $total_price < 0 ) {
980 $total_price = 0;
981 }
982 $ecommerce_reporting = "__gtagTracker('event', 'purchase', {
983 transaction_id: '" . $order_id . "',
984 affiliation: '" . esc_js( get_option( 'blogname' ) ) . "',
985 value: '" . $total_price . "',
986 currency: '" . $usces->get_currency_code() . "',
987 tax: '" . $data['order_tax'] . "',
988 shipping: '" . $data['order_shipping_charge'] . "',
989 items: [";
990
991 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
992 for ( $i = 0; $i < $cart_count; $i++ ) {
993 $cart_row = $cart[ $i ];
994 $post_id = $cart_row['post_id'];
995 $sku = urldecode( $cart_row['sku'] );
996 $quantity = $cart_row['quantity'];
997 $itemname = $usces->getItemName( $post_id );
998 $skuprice = $cart_row['price'];
999 $cats = $usces->get_item_cat_genre_ids( $post_id );
1000 if ( is_array( $cats ) ) {
1001 sort( $cats );
1002 }
1003 $category = ( isset( $cats[0] ) ) ? get_cat_name( $cats[0] ) : '';
1004
1005 $ecommerce_reporting .= "{
1006 id: '" . $post_id . "',
1007 sku: '" . esc_js( $sku ) . "',
1008 name: '" . esc_js( $itemname ) . "',
1009 category: '" . esc_js( $category ) . "',
1010 price: '" . $skuprice . "',
1011 quantity: '" . $quantity . "'
1012 },";
1013 }
1014 $ecommerce_reporting .= "]});";
1015
1016 $monsterinsights_current_version = usces_MonsterInsights_get_version();
1017 if ( version_compare( $monsterinsights_current_version, '8.0.0', '>=' ) ) {
1018 wp_register_script( 'after-monsterinsights-frontend-script', '', array( 'monsterinsights-frontend-script' ) );
1019 wp_enqueue_script( 'after-monsterinsights-frontend-script' );
1020 wp_add_inline_script( 'after-monsterinsights-frontend-script', $ecommerce_reporting );
1021 } else {
1022 wel_esc_script_e( $ecommerce_reporting );
1023 }
1024 }
1025 }
1026
1027 /**
1028 * Universal trackPageview by monsterInsight.
1029 * monsterinsights_frontend_tracking_options_gtag_end
1030 *
1031 * @param array $push Push array.
1032 * @return array
1033 */
1034 function usces_Universal_trackPageview_by_monsterInsight( $push ) {
1035 global $usces;
1036
1037 $monsterinsights_current_version = usces_MonsterInsights_get_version();
1038 if ( version_compare( $monsterinsights_current_version, '8.0.0', '>=' ) ) {
1039 switch ( $usces->page ) {
1040 case 'cart':
1041 $push['page_path'] = 'wc_cart';
1042 break;
1043
1044 case 'customer':
1045 $push['page_path'] = 'wc_customer';
1046 break;
1047
1048 case 'delivery':
1049 $push['page_path'] = 'wc_delivery';
1050 break;
1051
1052 case 'confirm':
1053 $push['page_path'] = 'wc_confirm';
1054 break;
1055
1056 case 'ordercompletion':
1057 $push['page_path'] = 'wc_ordercompletion';
1058 break;
1059
1060 case 'error':
1061 $push['page_path'] = 'wc_error';
1062 break;
1063
1064 case 'search_item':
1065 $push['page_path'] = 'wc_search_item';
1066 break;
1067
1068 case 'maintenance':
1069 $push['page_path'] = 'wc_maintenance';
1070 break;
1071
1072 case 'login':
1073 $push['page_path'] = 'wc_login';
1074 break;
1075
1076 case 'member':
1077 $push['page_path'] = 'wc_member';
1078 break;
1079
1080 case 'newmemberform':
1081 $push['page_path'] = 'wc_newmemberform';
1082 break;
1083
1084 case 'newcompletion':
1085 $push['page_path'] = 'wc_newcompletion';
1086 break;
1087
1088 case 'editmemberform':
1089 $push['page_path'] = 'wc_editmemberform';
1090 break;
1091
1092 case 'editcompletion':
1093 $push['page_path'] = 'wc_editcompletion';
1094 break;
1095
1096 case 'lostmemberpassword':
1097 $push['page_path'] = 'wc_lostmemberpassword';
1098 break;
1099
1100 case 'lostcompletion':
1101 $push['page_path'] = 'wc_lostcompletion';
1102 break;
1103
1104 case 'changepassword':
1105 $push['page_path'] = 'wc_changepassword';
1106 break;
1107
1108 case 'changepasscompletion':
1109 $push['page_path'] = 'wc_changepasscompletion';
1110 break;
1111
1112 default: // keep origin page path.
1113 break;
1114 }
1115 } else {
1116 switch ( $usces->page ) {
1117 case 'cart':
1118 $push['page_path'] = "'/wc_cart'";
1119 break;
1120
1121 case 'customer':
1122 $push['page_path'] = "'/wc_customer'";
1123 break;
1124
1125 case 'delivery':
1126 $push['page_path'] = "'/wc_delivery'";
1127 break;
1128
1129 case 'confirm':
1130 $push['page_path'] = "'/wc_confirm'";
1131 break;
1132
1133 case 'ordercompletion':
1134 $push['page_path'] = "'/wc_ordercompletion'";
1135 break;
1136
1137 case 'error':
1138 $push['page_path'] = "'/wc_error'";
1139 break;
1140
1141 case 'search_item':
1142 $push['page_path'] = "'/wc_search_item'";
1143 break;
1144
1145 case 'maintenance':
1146 $push['page_path'] = "'/wc_maintenance'";
1147 break;
1148
1149 case 'login':
1150 $push['page_path'] = "'/wc_login'";
1151 break;
1152
1153 case 'member':
1154 $push['page_path'] = "'/wc_member'";
1155 break;
1156
1157 case 'newmemberform':
1158 $push['page_path'] = "'/wc_newmemberform'";
1159 break;
1160
1161 case 'newcompletion':
1162 $push['page_path'] = "'/wc_newcompletion'";
1163 break;
1164
1165 case 'editmemberform':
1166 $push['page_path'] = "'/wc_editmemberform'";
1167 break;
1168
1169 case 'editcompletion':
1170 $push['page_path'] = "'/wc_editcompletion'";
1171 break;
1172
1173 case 'lostmemberpassword':
1174 $push['page_path'] = "'/wc_lostmemberpassword'";
1175 break;
1176
1177 case 'lostcompletion':
1178 $push['page_path'] = "'/wc_lostcompletion'";
1179 break;
1180
1181 case 'changepassword':
1182 $push['page_path'] = "'/wc_changepassword'";
1183 break;
1184
1185 case 'changepasscompletion':
1186 $push['page_path'] = "'/wc_changepasscompletion'";
1187 break;
1188
1189 default: // keep origin page path.
1190 break;
1191 }
1192 }
1193 return $push;
1194 }
1195
1196 /**
1197 * Classic Analytics ( Yoast )
1198 * yoast-ga-push-array-ga-js
1199 *
1200 * @param array $push Push array.
1201 * @return array
1202 */
1203 function usces_Classic_trackPageview_by_Yoast( $push ) {
1204 global $usces;
1205
1206 foreach ( $push as $p_key => $p_val ) {
1207 $pos1 = strpos( (string) $p_val, "'_trackPageview" );
1208 if ( false !== $pos1 ) {
1209 unset( $push[ $p_key ] );
1210 }
1211 }
1212 switch ( $usces->page ) {
1213 case 'cart':
1214 $push[] = "'_trackPageview', '/wc_cart'";
1215 break;
1216
1217 case 'customer':
1218 $push[] = "'_trackPageview', '/wc_customer'";
1219 break;
1220
1221 case 'delivery':
1222 $push[] = "'_trackPageview', '/wc_delivery'";
1223 break;
1224
1225 case 'confirm':
1226 $push[] = "'_trackPageview', '/wc_confirm'";
1227 break;
1228
1229 case 'ordercompletion':
1230 global $usces;
1231
1232 $push[] = "'_trackPageview','/wc_ordercompletion'";
1233 $sesdata = $usces->cart->get_entry();
1234 if ( isset( $sesdata['order']['ID'] ) && ! empty( $sesdata['order']['ID'] ) ) {
1235 $order_id = $sesdata['order']['ID'];
1236 $data = $usces->get_order_data( $order_id, 'direct' );
1237 $cart = unserialize( $data['order_cart'] );
1238 $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
1239 if ( $total_price < 0 ) {
1240 $total_price = 0;
1241 }
1242
1243 $push[] = "'_addTrans', '" . $order_id . "', '" . esc_js( get_option( 'blogname' ) ) . "', '" . $total_price . "', '" . $data['order_tax'] . "', '" . $data['order_shipping_charge'] . "', '" . esc_js( $data['order_address1'] . $data['order_address2'] ) . "', '" . esc_js( $data['order_pref'] ) . "', '" . get_locale() . "'";
1244 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
1245 for ( $i = 0; $i < $cart_count; $i++ ) {
1246 $cart_row = $cart[ $i ];
1247 $post_id = $cart_row['post_id'];
1248 $sku = urldecode( $cart_row['sku'] );
1249 $quantity = $cart_row['quantity'];
1250 $itemname = $usces->getItemName( $post_id );
1251 $skuprice = $cart_row['price'];
1252 $cats = $usces->get_item_cat_genre_ids( $post_id );
1253 if ( is_array( $cats ) ) {
1254 sort( $cats );
1255 }
1256 $category = ( isset( $cats[0] ) ) ? get_cat_name( $cats[0] ) : '';
1257 $push[] = "'_addItem', '" . $order_id . "', '" . esc_js( $sku ) . "', '" . esc_js( $itemname ) . "', '" . esc_js( $category ) . "', '" . $skuprice . "', '" . $quantity . "'";
1258 }
1259 $push[] = "'_trackTrans'";
1260 }
1261 break;
1262
1263 case 'error':
1264 $push[] = "'_trackPageview', '/wc_error'";
1265 break;
1266
1267 case 'login':
1268 $push[] = "'_trackPageview', '/wc_login'";
1269 break;
1270
1271 case 'member':
1272 $push[] = "'_trackPageview', '/wc_member'";
1273 break;
1274
1275 case 'newmemberform':
1276 $push[] = "'_trackPageview', '/wc_newmemberform'";
1277 break;
1278
1279 case 'newcompletion':
1280 $push[] = "'_trackPageview', '/wc_newcompletion'";
1281 break;
1282
1283 case 'editmemberform':
1284 $push[] = "'_trackPageview', '/wc_editmemberform'";
1285 break;
1286
1287 case 'search_item':
1288 $push[] = "'_trackPageview', '/wc_search_item'";
1289 break;
1290
1291 case 'maintenance':
1292 $push[] = "'_trackPageview', '/wc_maintenance'";
1293 break;
1294
1295 case 'editcompletion':
1296 $push[] = "'_trackPageview', '/wc_editcompletion'";
1297 break;
1298
1299 case 'lostmemberpassword':
1300 $push[] = "'_trackPageview', '/wc_lostmemberpassword'";
1301 break;
1302
1303 case 'lostcompletion':
1304 $push[] = "'_trackPageview', '/wc_lostcompletion'";
1305 break;
1306
1307 case 'changepassword':
1308 $push[] = "'_trackPageview', '/wc_changepassword'";
1309 break;
1310
1311 case 'changepasscompletion':
1312 $push[] = "'_trackPageview', '/wc_changepasscompletion'";
1313 break;
1314
1315 default:
1316 $push[] = "'_trackPageview'";
1317 break;
1318 }
1319 return $push;
1320 }
1321
1322 /**
1323 * Using MonsterInsights.
1324 * plugins_loaded
1325 */
1326 function usces_monsterinsights() {
1327 $monsterinsights_current_version = usces_MonsterInsights_get_version();
1328 if ( null !== $monsterinsights_current_version && version_compare( $monsterinsights_current_version, '6.0.11', '>' ) ) {
1329 add_filter( 'monsterinsights_frontend_tracking_options_analytics_end', 'usces_Universal_trackPageview_by_Yoast' );
1330 add_filter( 'monsterinsights_frontend_tracking_options_gtag_end', 'usces_Universal_trackPageview_by_monsterInsight' );
1331 if ( version_compare( $monsterinsights_current_version, '8.0.0', '>=' ) ) {
1332 add_action( 'wp_enqueue_scripts', 'usces_ecommerce_reporting', 10 );
1333 } else {
1334 add_action( 'monsterinsights_frontend_tracking_gtag_after_pageview', 'usces_ecommerce_reporting' );
1335 }
1336 } else {
1337 add_filter( 'yoast-ga-push-array-universal', 'usces_Universal_trackPageview_by_Yoast' );
1338 add_filter( 'yoast-ga-push-array-ga-js', 'usces_Classic_trackPageview_by_Yoast' );
1339 }
1340 }
1341
1342 /**
1343 * Get version of MonsterInsights.
1344 *
1345 * @return string
1346 */
1347 function usces_monsterinsights_get_version() {
1348 if ( ! function_exists( 'MonsterInsights_Pro' ) && ! function_exists( 'MonsterInsights_Lite' ) ) {
1349 return;
1350 }
1351 $instance = class_exists( 'MonsterInsights' ) ? MonsterInsights_Pro() : MonsterInsights_Lite();
1352 return $instance->version;
1353 }
1354
1355 /**
1356 * Order memo area.
1357 * usces_action_order_edit_form_detail_top
1358 *
1359 * @param array $data Order data.
1360 * @param array $csod_meta Custom order data.
1361 */
1362 function usces_order_memo_form_detail_top( $data, $csod_meta ) {
1363 global $usces;
1364
1365 $order_memo = '';
1366 if ( ! empty( $data['ID'] ) ) {
1367 $order_memo = $usces->get_order_meta_value( 'order_memo', $data['ID'] );
1368 }
1369 $res = '<tr>
1370 <td class="label border">' . __( 'Administrator Note', 'usces' ) . '</td>
1371 <td colspan="5" class="col1 border memo">
1372 <textarea name="order_memo" class="order_memo">' . esc_html( $order_memo ) . '</textarea>
1373 </td>
1374 </tr>';
1375 wel_esc_script_e( $res );
1376 }
1377
1378 /**
1379 * Update order memo.
1380 * usces_action_update_orderdata
1381 *
1382 * @param object $new_orderdata New order data.
1383 */
1384 function usces_update_order_memo( $new_orderdata ) {
1385 global $usces;
1386
1387 if ( isset( $_POST['order_memo'] ) ) {
1388 $usces->set_order_meta_value( 'order_memo', $_POST['order_memo'], $new_orderdata->ID );
1389 }
1390 }
1391
1392 /**
1393 * Save order memo.
1394 * usces_action_reg_orderdata
1395 *
1396 * @param array $args {
1397 * The array of order-related data.
1398 * @type array $cart Cart data.
1399 * @type array $entry Entry data.
1400 * @type int $order_id Order ID.
1401 * @type int $member_id Member ID.
1402 * @type array $payments Payment Method.
1403 * @type array $charging_type Charge type.
1404 * @type array $results Settlement result data.
1405 * }
1406 */
1407 function usces_register_order_memo( $args ) {
1408 global $usces;
1409 extract( $args );
1410
1411 if ( isset( $_POST['order_memo'] ) && $order_id ) {
1412 $usces->set_order_meta_value( 'order_memo', $_POST['order_memo'], $order_id );
1413 }
1414 }
1415
1416 /**
1417 * Tracking number field area.
1418 * usces_action_order_edit_form_delivery_block
1419 *
1420 * @param array $data Order data.
1421 * @param array $cscs_meta Custom customer data.
1422 * @param array $action_args Order action.
1423 * @return void
1424 */
1425 function usces_add_tracking_number_field( $data, $cscs_meta, $action_args ) {
1426 global $usces;
1427 $locale = get_locale();
1428
1429 $deli_comps = array( 'クロネコヤマト', 'ヤマト運輸', '佐川急便', '日本通運', 'ゆうパック', '日本郵便', '郵便書留', '西濃運輸', '福山通運', '名鉄運輸', '新潟運輸', 'トナミ運輸', '第一貨物', '飛騨倉庫運輸', '西武運輸', 'クリックポスト', 'トールエクスプレス', 'セイノーエクスプレス', '信州名鉄運輸', '大川�
1430 �送サービス', 'その他' );
1431 $deli_comps = apply_filters( 'usces_filter_deli_comps', $deli_comps, $data );
1432
1433 $tracking_number = '';
1434 if ( ! empty( $data['ID'] ) ) {
1435 $tracking_number = $usces->get_order_meta_value( apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' ), $data['ID'] );
1436 $delivery_company = $usces->get_order_meta_value( 'delivery_company', $data['ID'] );
1437 } else {
1438 $tracking_number = '';
1439 $delivery_company = '';
1440 }
1441 $res = '';
1442 $res .= '
1443 <tr>
1444 <td class="label">' . __( 'Delivery company', 'usces' ) . '</td>
1445 <td class="col1">';
1446 if ( 'ja' === $locale ) {
1447 $res .= ' <select name="delivery_company" style="width:100%;" >' . "\n";
1448 $res .= '<option value="">' . __( '-- Select --', 'usces' ) . '</option>' . "\n";
1449 foreach ( $deli_comps as $comp ) {
1450 $res .= '<option value="' . esc_attr( $comp ) . '"' . selected( $comp, $delivery_company, false ) . '>' . esc_html( $comp ) . '</option>' . "\n";
1451 }
1452 $res .= ' </select>' . "\n";
1453 } else {
1454 $res .= ' <input name="delivery_company" type="text" style="width:100%;" value="' . esc_attr( $delivery_company ) . '">';
1455 }
1456 $res .= ' </td>
1457 </tr>';
1458 $res .= '<tr>
1459 <td class="label">' . __( 'Tracking number', 'usces' ) . '</td>
1460 <td class="col1">
1461 <input name="tracking_number" type="text" style="width:100%;" value="' . esc_attr( $tracking_number ) . '">
1462 </td>
1463 </tr>' . "\n";
1464 wel_esc_script_e( $res );
1465 }
1466
1467 /**
1468 * Update tracking number.
1469 * usces_action_update_orderdata
1470 *
1471 * @param object $new_orderdata New order data.
1472 */
1473 function usces_update_tracking_number( $new_orderdata ) {
1474 global $usces;
1475
1476 if ( isset( $_POST['tracking_number'] ) ) {
1477 $usces->set_order_meta_value( apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' ), wp_unslash( $_POST['tracking_number'] ), $new_orderdata->ID );
1478 }
1479
1480 if ( isset( $_POST['delivery_company'] ) ) {
1481 $usces->set_order_meta_value( 'delivery_company', wp_unslash( $_POST['delivery_company'] ), $new_orderdata->ID );
1482 }
1483 }
1484
1485 /**
1486 * Admin scripts.
1487 * admin_enqueue_scripts
1488 *
1489 * @param string $hook_suffix The current admin page.
1490 */
1491 function usces_admin_enqueue_scripts( $hook_suffix ) {
1492 global $wp_scripts;
1493 if ( false !== strpos( $hook_suffix, 'usc-e-shop' )
1494 || false !== strpos( $hook_suffix, 'welcart' )
1495 || false !== strpos( $hook_suffix, 'usces' )
1496 ) {
1497 $ui = $wp_scripts->query( 'jquery-ui-core' );
1498 $ui_themes = apply_filters( 'usces_filter_jquery_ui_themes_welcart', 'smoothness' );
1499 wp_enqueue_style( 'jquery-ui-welcart', "//code.jquery.com/ui/{$ui->ver}/themes/{$ui_themes}/jquery-ui.css" );
1500 }
1501 if ( 'welcart-management_page_usces_memberlist' == $hook_suffix
1502 || 'toplevel_page_usces_orderlist' == $hook_suffix
1503 ) {
1504 $path = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
1505 wp_enqueue_script( 'usces_member_cookie', $path, array( 'jquery' ), USCES_VERSION, true );
1506 }
1507 }
1508
1509 /**
1510 * Cron schedules.
1511 * cron_schedules
1512 *
1513 * @param array $schedules An array of non-default cron schedule arrays.
1514 * @return array
1515 */
1516 function usces_schedules_intervals( $schedules ) {
1517 $schedules['weekly'] = array(
1518 'interval' => 604800,
1519 'display' => 'Weekly',
1520 );
1521 return $schedules;
1522 }
1523
1524 /**
1525 * Welcart activate.
1526 * plugins_loaded
1527 */
1528 function usces_responce_wcsite() {
1529 $my_wcid = get_option( 'usces_wcid' );
1530
1531 if ( isset( $_POST['sname'] ) && isset( $_POST['wcid'] ) && '54.64.221.23' == $_SERVER['REMOTE_ADDR'] ) {
1532 $data['usces'] = get_option( 'usces', array() );
1533 $data['usces_settlement_selected'] = get_option( 'usces_settlement_selected', array() );
1534 $res = json_encode( $data );
1535 header( 'Content-Type: application/json' );
1536 wel_esc_script_e( $res );
1537 exit;
1538 }
1539 }
1540
1541 /**
1542 * Welcart activate.
1543 */
1544 function usces_wcsite_activate() {
1545 $usces = get_option( 'usces', array() );
1546 $circulating = wel_get_circulating_amount();
1547 $sku_num = wel_get_sku_total_num();
1548 $cat_num = wel_get_cat_total_num();
1549
1550 $metas['usces_company_name'] = $usces['company_name'];
1551 $metas['usces_company_tel'] = $usces['tel_number'];
1552 $metas['usces_company_number'] = $usces['business_registration_number'];
1553 $metas['usces_company_zip'] = $usces['zip_code'];
1554 $metas['usces_company_location'] = $usces['address1'] . ' ' . $usces['address2'];
1555 $metas['usces_inquiry_mail'] = $usces['inquiry_mail'];
1556 $metas['usces_base_country'] = $usces['system']['base_country'];
1557 $metas['usces_circulating_amount'] = $circulating['amount'];
1558 $metas['usces_circulating_count'] = $circulating['count'];
1559 $metas['usces_categories'] = wel_get_categories();
1560 $metas['usces_cat_num'] = $cat_num;
1561 $metas['usces_sku_num'] = $sku_num;
1562 $metas['usces_themes'] = wel_get_themes();
1563 $metas['usces_plugins'] = wel_get_plugins();
1564 $metas['usces_used_sett'] = wel_get_activ_pay_methd();
1565
1566 $base_metas = array(
1567 'wcid' => get_option( 'usces_wcid' ),
1568 'wchost' => $_SERVER['SERVER_NAME'],
1569 'refer' => get_option( 'home' ),
1570 'act' => 1,
1571 );
1572 $params = array_merge( $base_metas, $metas );
1573 usces_wcsite_connection( $params );
1574 }
1575
1576 /**
1577 * Welcart deactivate.
1578 */
1579 function usces_wcsite_deactivate() {
1580 $params = array(
1581 'wcid' => get_option( 'usces_wcid' ),
1582 'wchost' => $_SERVER['SERVER_NAME'],
1583 'refer' => get_option( 'home' ),
1584 'act' => 0,
1585 );
1586 usces_wcsite_connection( $params );
1587 }
1588
1589 /**
1590 * Session cache limiter.
1591 * usces_action_session_start
1592 */
1593 function usces_session_cache_limiter() {
1594 global $usces;
1595
1596 if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && isset( $_REQUEST['usces_page'] ) && 'search_item' == $_REQUEST['usces_page'] ) {
1597 session_cache_limiter( 'private_no_expire' );
1598 }
1599 }
1600
1601 /**
1602 * Disused function
1603 * usces_action_login_page_footer
1604 */
1605 function usces_action_login_page_liwpp() {
1606 }
1607
1608 /**
1609 * Disused function
1610 * usces_filter_login_page_footer
1611 *
1612 * @param string $html Template form.
1613 * @return string
1614 */
1615 function usces_filter_login_page_liwpp( $html ) {
1616 return $html;
1617 }
1618
1619 /**
1620 * Disused function
1621 * usces_action_customer_page_member_inform
1622 */
1623 function usces_action_customer_page_liwpp() {
1624 }
1625
1626 /**
1627 * Disused function
1628 * usces_filter_customer_page_member_inform
1629 *
1630 * @param string $html Template form.
1631 * @return string
1632 */
1633 function usces_filter_customer_page_liwpp( $html ) {
1634 return $html;
1635 }
1636
1637 /**
1638 * Disused function
1639 * usces_filter_login_widget
1640 *
1641 * @param string $html Template form.
1642 * @return string
1643 */
1644 function usces_filter_login_widget_liwpp( $html ) {
1645 return $html;
1646 }
1647
1648 /**
1649 * Disused function
1650 * wp
1651 */
1652 function usces_login_width_paypal() {
1653 }
1654
1655 /**
1656 * Atobarai each availability area.
1657 *
1658 * @param string $second_section Second section area.
1659 * @param int $post_id Post ID.
1660 * @return string
1661 */
1662 function usces_atobarai_each_availability( $second_section, $post_id ) {
1663
1664 $product = wel_get_product( $post_id );
1665
1666 $deferred_payment_propriety = (int) $product['atobarai_propriety'];
1667
1668 $second_section .= '
1669 <tr>
1670 <th>' . __( 'Atobarai Propriety', 'usces' ) . '</th>
1671 <td>
1672 <label for="deferred_payment_propriety0"><input name="deferred_payment_propriety" id="deferred_payment_propriety0" type="radio" value="0"' . ( ! $deferred_payment_propriety ? ' checked="checked"' : '' ) . '>' . __( 'available', 'usces' ) . '</label>
1673 <label for="deferred_payment_propriety1"><input name="deferred_payment_propriety" id="deferred_payment_propriety1" type="radio" value="1"' . ( $deferred_payment_propriety ? ' checked="checked"' : '' ) . '>' . __( 'not available', 'usces' ) . '</label>
1674 </td>
1675 </tr>';
1676 return $second_section;
1677 }
1678
1679 /**
1680 * Disused function
1681 *
1682 * @param int $post_id Post ID.
1683 * @param object $post Post data.
1684 */
1685 function usces_atobarai_update_each_availability( $post_id, $post ) {
1686 // This process has moved to item_post.php 1568.
1687 }
1688
1689 /**
1690 * Setup of settlement.
1691 * plugins_loaded
1692 */
1693 function usces_instance_settlement() {
1694 global $usces;
1695
1696 $usces->settlement->setup();
1697 }
1698
1699 /**
1700 * Setup of extensions.
1701 * plugins_loaded
1702 */
1703 function usces_instance_extentions() {
1704 global $ganbare_tencho, $order_stock_linkage, $data_list_upgrade, $verify_members_email, $data_google_recaptcha, $brute_force;
1705
1706 require_once USCES_EXTENSIONS_DIR . '/GanbareTencho/GanbareTencho.class.php';
1707 $ganbare_tencho = new USCES_GANBARE_TENCHO();
1708
1709 require_once USCES_EXTENSIONS_DIR . '/OrderStockLinkage/order_stock_linkage.php';
1710 $order_stock_linkage = new USCES_STOCK_LINKAGE();
1711
1712 require_once USCES_EXTENSIONS_DIR . '/DataListUpgrade/data_list_upgrade.php';
1713 $data_list_upgrade = new USCES_DATALIST_UPGRADE();
1714
1715 require_once USCES_EXTENSIONS_DIR . '/VerifyMembersEmail/verify_members_email.php';
1716 $verify_members_email = new USCES_VERIFY_MEMBERS_EMAIL();
1717
1718 require_once USCES_EXTENSIONS_DIR . '/GoogleRecaptcha/google_recaptcha.php';
1719 $data_google_recaptcha = new USCES_GOOGLE_RECAPTCHA();
1720
1721 require_once USCES_EXTENSIONS_DIR . '/BruteForceCountermeasures/brute_force_countermeasures.php';
1722 $brute_force = new USCES_BRUTE_FORCE_COUNTER_MEASURES();
1723
1724 require_once USCES_EXTENSIONS_DIR . '/StructuredDataProduct/structured_data_product.php';
1725 $structured_data_product = new USCES_STRUCTURED_DATA_PRODUCT();
1726
1727 require_once USCES_EXTENSIONS_DIR . '/NewProductImageRegister/class-new-product-image-register.php';
1728 $new_product_image_register = new NEW_PRODUCT_IMAGE_REGISTER();
1729
1730 require_once USCES_EXTENSIONS_DIR . '/OperationLog/class-operation-log.php';
1731 $operation_log = new OPERATION_LOG();
1732
1733 require_once USCES_EXTENSIONS_DIR . '/CreditCardSecurity/class-creditcard-security.php';
1734 $card_security = new USCES_CREDITCARD_SECURITY();
1735 }
1736
1737 /**
1738 * Get list of attachment image attributes.
1739 * wp_get_attachment_image_attributes
1740 *
1741 * @param array $attr Array of attribute values for the image markup, keyed by attribute name.
1742 * @param WP_Post $attachment Image attachment post.
1743 * @param string|int $size Requested image size.
1744 * @return array
1745 */
1746 function usces_get_attachment_image_attributes( $attr, $attachment, $size ) {
1747 global $usces;
1748
1749 if ( $usces->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $usces->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
1750 if ( $usces->use_ssl && isset( $attr['srcset'] ) ) {
1751 $srcset = $attr['srcset'];
1752 $attr['srcset'] = str_replace( get_option( 'siteurl' ), USCES_SSL_URL_ADMIN, $srcset );
1753 }
1754 }
1755 return $attr;
1756 }
1757
1758 /**
1759 * SSL charm
1760 * init
1761 *
1762 * @return void
1763 */
1764 function usces_ssl_charm() {
1765 global $usces;
1766 if ( $usces->use_ssl && ( $usces->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $usces->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
1767 if ( function_exists( 'usces_ob_callback' ) ) {
1768 ob_start( 'usces_ob_callback' );
1769 } else {
1770 ob_start( 'usces_ob_rewrite' );
1771 }
1772 }
1773 }
1774
1775 /**
1776 * Output buffer rewrite
1777 *
1778 * @param array $buffer Rewrite buffer.
1779 * @return array
1780 */
1781 function usces_ob_rewrite( $buffer ) {
1782 $pattern = array(
1783 '|(<[^<]*)href=\"' . get_option( 'siteurl' ) . '([^>]*)\.css([^>]*>)|',
1784 '|(<[^<]*)src=\"' . get_option( 'siteurl' ) . '([^>]*>)|',
1785 );
1786 $replacement = array(
1787 '${1}href="' . USCES_SSL_URL_ADMIN . '${2}.css${3}',
1788 '${1}src="' . USCES_SSL_URL_ADMIN . '${2}',
1789 );
1790 $buffer = preg_replace( $pattern, $replacement, $buffer );
1791 return $buffer;
1792 }
1793
1794 /**
1795 * Enqueue scripts.
1796 * wp_enqueue_scripts
1797 */
1798 function usces_wp_enqueue_scripts() {
1799 global $usces;
1800
1801 $no_cart_css = isset( $usces->options['system']['no_cart_css'] ) ? $usces->options['system']['no_cart_css'] : 0;
1802
1803 wp_enqueue_style( 'usces_default_css', USCES_FRONT_PLUGIN_URL . '/css/usces_default.css', array(), USCES_VERSION );
1804 wp_enqueue_style( 'dashicons' );
1805
1806 if ( ! $no_cart_css ) {
1807 wp_enqueue_style( 'usces_cart_css', USCES_FRONT_PLUGIN_URL . '/css/usces_cart.css', array( 'usces_default_css' ), USCES_VERSION );
1808 }
1809
1810 $theme_version = defined( 'USCES_THEME_VERSION' ) ? USCES_THEME_VERSION : USCES_VERSION;
1811 if ( file_exists( get_stylesheet_directory() . '/usces_cart.css' ) ) {
1812 wp_enqueue_style( 'theme_cart_css', get_stylesheet_directory_uri() . '/usces_cart.css', array( 'usces_default_css' ), $theme_version );
1813 }
1814
1815 if ( $usces->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) ) {
1816
1817 if ( isset( $usces->options['address_search'] ) && 'activate' == $usces->options['address_search'] ) {
1818 wp_enqueue_script( 'usces_ajaxzip3', 'https://ajaxzip3.github.io/ajaxzip3.js', array(), current_time( 'timestamp' ), false );
1819 }
1820
1821 if ( isset( $usces->page ) && 'confirm' === $usces->page ) {
1822 $cart_comfirm = USCES_FRONT_PLUGIN_URL . '/js/cart_confirm.js';
1823 wp_enqueue_script( 'usces_cart_comfirm', $cart_comfirm, array( 'jquery' ), current_time( 'timestamp' ), false );
1824 }
1825
1826 if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
1827 $member_common_js = USCES_FRONT_PLUGIN_URL . '/js/member_common.js';
1828 wp_enqueue_script( 'usces_member_page_js', $member_common_js, array( 'jquery' ), current_time( 'timestamp' ), true );
1829 }
1830 }
1831 }
1832
1833 /**
1834 * Check confirm.
1835 * wp_ajax_welcart_confirm_check
1836 */
1837 function welcart_confirm_check_ajax() {
1838 global $usces;
1839
1840 $nonce = filter_input( INPUT_POST, 'wc_nonce', FILTER_SANITIZE_SPECIAL_CHARS );
1841 $ajax = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_SPECIAL_CHARS );
1842 $uscesid = filter_input( INPUT_POST, 'uscesid', FILTER_SANITIZE_SPECIAL_CHARS );
1843 $condition = filter_input( INPUT_POST, 'wc_condition' );
1844
1845 if ( 'welcart_confirm_check' !== $ajax ) {
1846 $res = 'not permitted1';
1847 wp_send_json_error( $res );
1848 }
1849
1850 if ( ! wp_verify_nonce( $nonce, 'wc_confirm' ) ) {
1851 $res = 'not permitted2';
1852 wp_send_json_error( $res );
1853 }
1854 if ( PHP_SESSION_NONE === session_status() && $uscesid ) {
1855 $sessid = $usces->uscesdc( $uscesid );
1856 session_id( $sessid );
1857 @session_start(); // phpcs:ignore
1858 }
1859
1860 $current['entry'] = $usces->cart->get_entry();
1861 $current['cart'] = $usces->cart->get_cart();
1862 session_write_close();
1863
1864 $condition = json_decode( urldecode( $condition ), true );
1865
1866 if ( $condition == $current ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1867 $res = 'same';
1868 } elseif ( empty( $current['cart'] ) ) {
1869 $res = 'timeover';
1870 } elseif ( $current['cart'] == $condition['cart'] && $current['entry'] != $condition['entry'] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1871 $res = 'entrydiff';
1872 } else {
1873 $res = 'different';
1874 }
1875 wp_send_json_success( $res );
1876 }
1877
1878 /**
1879 * Parameter uscesL10n
1880 * usces_filter_uscesL10n
1881 *
1882 * @param string $nouse Unused.
1883 * @param int $post_id Post ID.
1884 * @return string
1885 */
1886 function usces_confirm_uscesL10n( $nouse, $post_id ) {
1887 global $usces;
1888
1889 if ( 'confirm' === $usces->page ) {
1890 $condition['entry'] = $usces->cart->get_entry();
1891 $condition['cart'] = $usces->cart->get_cart();
1892
1893 $js = '';
1894 $js .= "'condition': '" . urlencode( wp_json_encode( $condition ) ) . "',\n";
1895 $js .= "'cart_url': '" . USCES_CART_URL . "',\n";
1896 $js .= "'check_mes': '" . __( 'Purchase information has been updated. Please repeat the procedure.\n\nPlease do not open and work more than one tab (window).\n', 'usces' ) . "',\n";
1897 return $js;
1898 }
1899 }
1900
1901 /**
1902 * Search zipcode
1903 * usces_filter_states_form_js
1904 *
1905 * @param string $js Script.
1906 * @return string
1907 */
1908 function usces_search_zipcode_check( $js ) {
1909 global $usces;
1910
1911 $option = get_option( 'usces', array() );
1912 if ( ! isset( $option['address_search'] ) || 'activate' != $option['address_search'] ) {
1913 return $js;
1914 }
1915
1916 if ( ( ( $usces->use_js && ( is_page( USCES_MEMBER_NUMBER ) || $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) )
1917 && ( ( true === $usces->is_member_logged_in() && WCUtils::is_blank( $usces->page ) ) || 'member' == $usces->page || 'editmemberform' == $usces->page || 'newmemberform' == $usces->page ) )
1918 ||
1919 ( ( $usces->use_js && ( is_page( USCES_CART_NUMBER ) || $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) ) )
1920 && ( 'customer' == $usces->page || 'delivery' == $usces->page ) ) ) {
1921
1922 $zip_id = ( isset( $_REQUEST['usces_page'] ) && 'msa_setting' == $_REQUEST['usces_page'] ) ? 'msa_zip' : 'zipcode';
1923 $js .= '
1924 <script type="text/javascript">
1925 (function($) {
1926 $("#search_zipcode").click(function () {
1927 var str = $("#' . $zip_id . '").val();
1928 if( !str.match(/^\d{7}$|^\d{3}-\d{4}$/) ){
1929 alert("' . __( 'Please enter the zip code correctly.', 'usces' ) . '");
1930 $("#' . $zip_id . '").focus();
1931 }
1932 });
1933 })(jQuery);
1934 </script>';
1935 }
1936 return $js;
1937 }
1938
1939 /**
1940 * Admin member list page.
1941 * load-welcart-management_page_usces_memberlist
1942 */
1943 function usces_admin_member_list_hook() {
1944
1945 if ( ! isset( $_POST['member_list_options_apply'] ) ) {
1946 return;
1947 }
1948
1949 $list_option = get_option( 'usces_memberlist_option', array() );
1950 foreach ( (array) $list_option['view_column'] as $key => $value ) {
1951 if ( isset( $_POST['hide'][ $key ] ) ) {
1952 $list_option['view_column'][ $key ] = 1;
1953 } else {
1954 $list_option['view_column'][ $key ] = 0;
1955 }
1956 }
1957 $list_option['max_row'] = (int) $_POST['member_list_per_page'];
1958
1959 update_option( 'usces_memberlist_option', $list_option );
1960 }
1961
1962 /**
1963 * Admin order list page.
1964 * load-toplevel_page_usces_orderlist
1965 *
1966 * @param string $hook The current admin page.
1967 * @return void
1968 */
1969 function usces_admin_order_list_hook( $hook ) {
1970 if ( ! isset( $_POST['order_list_options_apply'] ) ) {
1971 return;
1972 }
1973
1974 $list_option = get_option( 'usces_orderlist_option', array() );
1975 foreach ( (array) $list_option['view_column'] as $key => $value ) {
1976 if ( isset( $_POST['hide'][ $key ] ) ) {
1977 $list_option['view_column'][ $key ] = 1;
1978 } else {
1979 $list_option['view_column'][ $key ] = 0;
1980 }
1981 }
1982 $list_option['max_row'] = (int) $_POST['order_list_per_page'];
1983
1984 update_option( 'usces_orderlist_option', $list_option );
1985 }
1986
1987 /**
1988 * Admin member list screen settings
1989 * screen_settings
1990 *
1991 * @param string $screen_settings Screen settings.
1992 * @param object $screen WP_Screen object.
1993 * @return string
1994 */
1995 function usces_memberlist_screen_settings( $screen_settings, $screen ) {
1996 if ( 'welcart-management_page_usces_memberlist' != $screen->id
1997 || ( isset( $_REQUEST['member_action'] ) && 'edit' == $_REQUEST['member_action'] ) ) {
1998 return $screen_settings;
1999 }
2000
2001 require_once USCES_PLUGIN_DIR . '/classes/memberList.class.php';
2002 $memberlist = new WlcMemberList();
2003 $arr_column = $memberlist->get_column();
2004 $list_option = get_option( 'usces_memberlist_option', array() );
2005 $init_view = array( 'ID', 'name1', 'name2', 'pref', 'address1', 'tel', 'email', 'entrydate', 'rank', 'point' );
2006
2007 $screen_settings = '
2008 <fieldset class="metabox-prefs">
2009 <legend>' . __( 'Columns' ) . '</legend>';
2010 foreach ( $arr_column as $key => $value ) {
2011 if ( 'ID' == $key || 'csod_' == substr( $key, 0, 5 ) ) {
2012 continue;
2013 }
2014
2015 if ( ! isset( $list_option['view_column'][ $key ] ) && in_array( $key, $init_view ) ) {
2016 $list_option['view_column'][ $key ] = 1;
2017 } elseif ( ! isset( $list_option['view_column'][ $key ] ) ) {
2018 $list_option['view_column'][ $key ] = 0;
2019 }
2020
2021 $checked = $list_option['view_column'][ $key ] ? ' checked="checked"' : '';
2022 $screen_settings .= '<label><input class="hide-column-tog" name="hide[' . $key . ']" type="checkbox" id="' . $key . '-hide" value="' . esc_attr( $value ) . '"' . $checked . ' />' . esc_html( $value ) . '</label>' . "\n";
2023 }
2024 $screen_settings .= '</fieldset>';
2025
2026 if ( ! isset( $list_option['max_row'] ) ) {
2027 $list_option['max_row'] = 50;
2028 }
2029
2030 $screen_settings .= '<fieldset class="screen-options">
2031 <legend>' . __( 'Pagination' ) . '</legend>
2032 <label for="edit_post_per_page">' . __( 'Number of items per page:' ) . '</label>
2033 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="member_list_per_page" id="member_list_per_page" maxlength="3" value="' . (int) $list_option['max_row'] . '" />
2034 </fieldset>
2035 <p class="submit"><input type="submit" name="member_list_options_apply" id="screen-options-apply" class="button button-primary" value="' . __( 'Apply' ) . '" /></p>';
2036
2037 update_option( 'usces_memberlist_option', $list_option );
2038 return $screen_settings;
2039 }
2040
2041 /**
2042 * Admin order list screen settings
2043 * screen_settings
2044 *
2045 * @param string $screen_settings Screen settings.
2046 * @param object $screen WP_Screen object.
2047 * @return string
2048 */
2049 function usces_orderlist_screen_settings( $screen_settings, $screen ) {
2050 if ( 'toplevel_page_usces_orderlist' != $screen->id
2051 || ( isset( $_REQUEST['order_action'] ) && 'edit' == $_REQUEST['order_action'] ) ) {
2052 return $screen_settings;
2053 }
2054
2055 require_once USCES_PLUGIN_DIR . '/classes/orderList2.class.php';
2056 $orderlist = new WlcOrderList();
2057 $arr_column = $orderlist->get_all_column();
2058 $list_option = get_option( 'usces_orderlist_option', array() );
2059 $init_view = array( 'deco_id', 'order_date', 'process_status', 'payment_name', 'receipt_status', 'total_price', 'deli_method', 'mem_id', 'name1', 'name2', 'pref' );
2060 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
2061 $init_view[] = 'reg_id';
2062 }
2063 $init_view = apply_filters( 'usces_filter_orderlist_column_init_view', $init_view );
2064
2065 $screen_settings = '
2066 <fieldset class="metabox-prefs">
2067 <legend>' . __( 'Columns' ) . '</legend>';
2068 foreach ( $arr_column as $key => $value ) {
2069
2070 if ( ! isset( $list_option['view_column'][ $key ] ) && in_array( $key, $init_view ) ) {
2071 $list_option['view_column'][ $key ] = 1;
2072 } elseif ( ! isset( $list_option['view_column'][ $key ] ) ) {
2073 $list_option['view_column'][ $key ] = 0;
2074 }
2075
2076 $checked = ( isset( $list_option['view_column'][ $key ] ) && $list_option['view_column'][ $key ] ) ? ' checked="checked"' : '';
2077 $screen_settings .= '<label><input class="hide-column-tog" name="hide[' . $key . ']" type="checkbox" id="' . $key . '-hide" value="' . $key . '"' . $checked . ' />' . esc_html( $value ) . '</label>' . "\n";
2078 }
2079 $screen_settings .= '</fieldset>';
2080
2081 if ( ! isset( $list_option['max_row'] ) ) {
2082 $list_option['max_row'] = 50;
2083 }
2084
2085 $screen_settings .= '<fieldset class="screen-options">
2086 <legend>' . __( 'Pagination' ) . '</legend>
2087 <label for="edit_post_per_page">' . __( 'Number of items per page:' ) . '</label>
2088 <input type="order" step="1" min="1" max="999" class="screen-per-page" name="order_list_per_page" id="order_list_per_page" maxlength="3" value="' . (int) $list_option['max_row'] . '" />
2089 </fieldset>
2090 <p class="submit"><input type="submit" name="order_list_options_apply" id="screen-options-apply" class="button button-primary" value="' . __( 'Apply' ) . '" /></p>';
2091
2092 update_option( 'usces_orderlist_option', $list_option );
2093 return $screen_settings;
2094 }
2095
2096 /**
2097 * New member registration anti-spam.
2098 * usces_filter_member_check
2099 *
2100 * @param string $mes Message.
2101 * @return string
2102 */
2103 function usces_memberreg_spamcheck( $mes ) {
2104
2105 if ( ! WCUtils::is_blank( $_POST['member']['name1'] ) && trim( $_POST['member']['name1'] ) == trim( $_POST['member']['name2'] ) ) {
2106 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
2107 }
2108
2109 if ( ! WCUtils::is_blank( $_POST['member']['address1'] ) && trim( $_POST['member']['address1'] ) == trim( $_POST['member']['address2'] ) ) {
2110 $mes .= __( 'Address is not correct', 'usces' ) . '<br />';
2111 }
2112
2113 if ( $mes ) {
2114 usces_log( 'memberreg_spamcheck : ' . $mes, 'acting_transaction.log' );
2115 }
2116
2117 return $mes;
2118 }
2119
2120 /**
2121 * New member registration anti-spam.
2122 * usces_filter_member_check_fromcart
2123 *
2124 * @param string $mes Message.
2125 * @return string
2126 */
2127 function usces_fromcart_memberreg_spamcheck( $mes ) {
2128
2129 if ( ! WCUtils::is_blank( $_POST['customer']['name1'] ) && trim( $_POST['customer']['name1'] ) == trim( $_POST['customer']['name2'] ) ) {
2130 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
2131 }
2132
2133 if ( ! WCUtils::is_blank( $_POST['customer']['address1'] ) && trim( $_POST['customer']['address1'] ) == trim( $_POST['customer']['address2'] ) ) {
2134 $mes .= __( 'Address is not correct', 'usces' ) . '<br />';
2135 }
2136
2137 if ( $mes ) {
2138 usces_log( 'fromcart_memberreg_spamcheck : ' . $mes, 'acting_transaction.log' );
2139 }
2140
2141 return $mes;
2142 }
2143
2144 /**
2145 * Welcart priority
2146 * pre_update_option_active_plugins
2147 *
2148 * @param mixed $active_plugins The new, unserialized option value.
2149 * @param mixed $old_value The old option value.
2150 * @return array
2151 */
2152 function usces_priority_active_plugins( $active_plugins, $old_value ) {
2153 foreach ( $active_plugins as $no => $path ) {
2154 if ( USCES_PLUGIN_BASENAME == $path ) {
2155 unset( $active_plugins[ $no ] );
2156 array_unshift( $active_plugins, USCES_PLUGIN_BASENAME );
2157 break;
2158 }
2159 }
2160 return $active_plugins;
2161 }
2162
2163 /**
2164 * Password change e-mail.
2165 * usces_action_changepass_page_inform
2166 */
2167 function usces_action_lostmail_inform() {
2168 $mem_mail = wp_unslash( $_REQUEST['mem'] );
2169 $lostkey = wp_unslash( $_REQUEST['key'] );
2170 $html = '
2171 <input type="hidden" name="mem" value="' . esc_attr( $mem_mail ) . '" />
2172 <input type="hidden" name="key" value="' . esc_attr( $lostkey ) . '" />' . "\n";
2173 wel_esc_script_e( $html );
2174 }
2175
2176 /**
2177 * Password change e-mail.
2178 * usces_filter_changepassword_inform
2179 *
2180 * @param string $html Form.
2181 * @return string
2182 */
2183 function usces_filter_lostmail_inform( $html ) {
2184 $mem_mail = wp_unslash( $_REQUEST['mem'] );
2185 $lostkey = wp_unslash( $_REQUEST['key'] );
2186 $html .= '
2187 <input type="hidden" name="mem" value="' . esc_attr( $mem_mail ) . '" />
2188 <input type="hidden" name="key" value="' . esc_attr( $lostkey ) . '" />' . "\n";
2189 return $html;
2190 }
2191
2192 /**
2193 * Purchase template form.
2194 * usces_filter_confirm_inform
2195 *
2196 * @param string $html Purchase template form.
2197 * @param array $payments Payment data.
2198 * @param string $acting_flag Payment method.
2199 * @param string $rand Settlement link key.
2200 * @param string $purchase_disabled Disabled tag.
2201 * @return string
2202 */
2203 function wc_purchase_nonce( $html, $payments, $acting_flag, $rand, $purchase_disabled ) {
2204 global $usces;
2205
2206 $nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $usces->nonacting_settlements );
2207 if ( strpos( $html, '_purchase_nonce' ) || in_array( $payments['settlement'], $nonacting_settlements ) ) {
2208 return $html;
2209 }
2210
2211 $noncekey = 'wc_purchase_nonce' . $usces->get_uscesid( false );
2212 $html .= wp_nonce_field( $noncekey, '_purchase_nonce', false, false ) . "\n";
2213 return $html;
2214 }
2215
2216 /**
2217 * Purchase check
2218 * usces_purchase_check
2219 */
2220 function wc_purchase_nonce_check() {
2221 global $usces;
2222
2223 $entry = $usces->cart->get_entry();
2224 if ( ! isset( $entry['order']['payment_name'] ) || empty( $entry['order']['payment_name'] ) ) {
2225 wp_redirect( home_url() );
2226 exit;
2227 }
2228
2229 $nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $usces->nonacting_settlements );
2230 $payments = usces_get_payments_by_name( $entry['order']['payment_name'] );
2231 if ( in_array( $payments['settlement'], $nonacting_settlements ) ) {
2232 return true;
2233 }
2234
2235 $nonce = isset( $_REQUEST['_purchase_nonce'] ) ? $_REQUEST['_purchase_nonce'] : '';
2236 $noncekey = 'wc_purchase_nonce' . $usces->get_uscesid( false );
2237 if ( empty( $nonce ) || wp_verify_nonce( $nonce, $noncekey ) ) {
2238 return true;
2239 }
2240
2241 wp_redirect( home_url() );
2242 exit;
2243 }
2244
2245 /**
2246 * Checking in $usces->use_point()
2247 * usces_action_confirm_page_point_inform
2248 */
2249 function usces_use_point_nonce() {
2250 global $usces;
2251
2252 $noncekey = 'use_point' . $usces->get_uscesid( false );
2253 wp_nonce_field( $noncekey, 'wc_nonce' );
2254 }
2255
2256 /**
2257 * Check post member page
2258 * usces_action_newmember_page_inform
2259 * usces_action_memberinfo_page_inform
2260 * usces_action_newpass_page_inform
2261 * usces_action_changepass_page_inform
2262 * usces_action_customer_page_inform
2263 */
2264 function usces_post_member_nonce() {
2265 global $usces;
2266
2267 $noncekey = 'post_member' . $usces->get_uscesid( false );
2268 wp_nonce_field( $noncekey, 'wc_nonce' );
2269 }
2270
2271 /**
2272 * Check post member login page
2273 * usces_action_login_page_inform
2274 * usces_action_customer_page_member_inform
2275 */
2276 function usces_member_login_nonce() {
2277 global $usces;
2278
2279 $noncekey = 'post_member' . $usces->get_uscesid( false );
2280 wp_nonce_field( $noncekey, 'wel_nonce' );
2281 }
2282
2283 /**
2284 * Order edit form additional information
2285 * usces_action_order_edit_form_detail_bottom
2286 *
2287 * @param array $data Order data.
2288 * @param array $cscs_meta Custom customer data.
2289 * @param array $action_args Order action.
2290 * @return void
2291 */
2292 function wel_order_edit_customer_additional_information( $data, $cscs_meta, $action_args ) {
2293 global $usces;
2294
2295 $order_id = isset( $data['ID'] ) ? (int) $data['ID'] : 0;
2296 if ( ! $order_id ) {
2297 return;
2298 }
2299
2300 $value = $usces->get_order_meta_value( 'extra_info', $order_id );
2301 if ( ! $value ) {
2302 return;
2303 }
2304
2305 $infos = unserialize( $value );
2306 $html = '<tr>
2307 <td colspan="2" class="label cus_note_label">' . __( 'Others', 'usces' ) . '</td>
2308 <td colspan="4" class="cus_note_label">' . "\n";
2309 $html .= '<table border="0" cellspacing="0" class="extra_info cus_info">' . "\n";
2310 foreach ( $infos as $key => $info ) {
2311 $key = str_replace( 'USER_AGANT', 'USER_AGENT', $key );
2312 $html .= '<tr><td class="label cus_note_label">' . esc_html( $key ) . '</td><td class="cus_note_label">' . esc_html( $info ) . '</td></tr>' . "\n";
2313 }
2314 $html .= '</table>' . "\n";
2315 $html .= '</td></tr>' . "\n";
2316
2317 wel_esc_script_e( $html );
2318 }
2319
2320 /**
2321 * Save additional information.
2322 * usces_post_reg_orderdata
2323 *
2324 * @param int $order_id Order ID.
2325 * @param array $results Settlement result data.
2326 * @return void
2327 */
2328 function wel_save_extra_info_to_ordermeta( $order_id, $results ) {
2329 global $usces;
2330
2331 if ( ! $order_id ) {
2332 return;
2333 }
2334
2335 $info = array(
2336 'IP' => ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '',
2337 'USER_AGENT' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '',
2338 );
2339
2340 $usces->set_order_meta_value( 'extra_info', serialize( $info ), $order_id );
2341 }
2342
2343 /**
2344 * Navigation menu arguments.
2345 * wp_nav_menu_args
2346 *
2347 * @param array $args An array containing wp_nav_menu() arguments.
2348 * @return array
2349 */
2350 function usces_wp_nav_menu_args( $args ) {
2351
2352 usces_remove_filter();
2353
2354 return $args;
2355 }
2356
2357 /**
2358 * Navigation menu.
2359 * wp_nav_menu
2360 *
2361 * @param string $nav_menu The HTML content for the navigation menu.
2362 * @param stdClass $args An object containing wp_nav_menu() arguments.
2363 * @return string
2364 */
2365 function usces_wp_nav_menu( $nav_menu, $args ) {
2366
2367 usces_reset_filter();
2368
2369 return $nav_menu;
2370 }
2371
2372 /**
2373 * Session write close.
2374 * admin_init
2375 */
2376 function usces_close_session() {
2377 if ( session_status() == PHP_SESSION_ACTIVE ) {
2378 session_write_close();
2379 }
2380 }
2381
2382 /**
2383 * Handles OPTIONS requests for the server.
2384 *
2385 * This is handled outside of the server code, as it doesn't obey normal route
2386 * mapping.
2387 *
2388 * @since 4.4.0
2389 *
2390 * @param mixed $response Current reponse, either response or `null` to indicate pass-through.
2391 * @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
2392 * @param WP_REST_Request $request The request that was used to make current response.
2393 * @return WP_REST_Response Modified response, either response or `null` to indicate pass-through.
2394 */
2395 function usces_close_session_loopback( $response, $handler, $request ) {
2396 $router = $request->get_route();
2397 if ( ! empty( $router ) && '/wp-site-health/v1/tests/loopback-requests' == $router ) {
2398 usces_close_session();
2399 }
2400 return $response;
2401 }
2402
2403 /**
2404 * Google recaptcha script.
2405 * wp_print_footer_scripts
2406 */
2407 function usces_add_google_recaptcha_v3_script() {
2408 global $usces, $usces_entries, $usces_carts;
2409
2410 if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) && 'newmemberform' === $usces->page ) {
2411 print_google_recaptcha_response( 'create_new_member', 'memberpages' );
2412 }
2413
2414 if ( ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'customer' === $usces->page ) ) {
2415 print_google_recaptcha_response( 'customer_order_page', 'customer-info', 'customer_form' );
2416 }
2417 if ( ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'delivery' === $usces->page ) ) {
2418 print_google_recaptcha_response( 'delivery_order_page', 'delivery-info', '' );
2419 }
2420 }
2421
2422 /**
2423 * Google recaptcha badge display.
2424 *
2425 * @param string $action Page action.
2426 * @param string $parent_element_id Parent page.
2427 * @param string $form_name Page name.
2428 * @return void
2429 */
2430 function print_google_recaptcha_response( $action, $parent_element_id, $form_name = '' ) {
2431 $option = get_option( 'usces_ex', array() );
2432 if ( isset( $option['system']['google_recaptcha']['status'] ) && $option['system']['google_recaptcha']['status'] && ! ( empty( $option['system']['google_recaptcha']['site_key'] ) ) && ! ( empty( $option['system']['google_recaptcha']['secret_key'] ) ) ) {
2433 $site_key = isset( $option['system']['google_recaptcha']['site_key'] ) ? $option['system']['google_recaptcha']['site_key'] : '';
2434 echo '<script src="https://www.google.com/recaptcha/api.js?render=' . esc_js( $site_key ) . '"></script>';
2435 echo '<script>';
2436 echo 'grecaptcha.ready(function() {';
2437 echo ' grecaptcha.execute(\'' . esc_js( $site_key ) . '\', {action: "' . esc_js( $action ) . '"}).then(function(token) {';
2438 echo ' jQuery("form").append(\'<input type="hidden" id="elm_recaptcha_response" name="recaptcha_response" value="\'+ token +\'">\');';
2439 echo ' if(!jQuery("input[type=hidden]").is("[name=recaptcha_response]")) { jQuery("input[name=member_regmode]").after(\'<input type="hidden" id="elm_recaptcha_response" name="recaptcha_response" value="\'+ token +\'">\'); }';
2440 echo ' });';
2441 echo '});';
2442 echo '</script>';
2443
2444 // run time reload google captcha token v3 key after 1 minutes.
2445 echo '<script>';
2446 echo 'var max_google_reload_times = 10;';
2447 echo 'var google_reload_times = 1;';
2448 echo 'var function_token_reload = setInterval(function(){';
2449 echo ' if (google_reload_times > max_google_reload_times) {';
2450 echo ' clearInterval(function_token_reload);';
2451 echo ' } else { ';
2452 echo ' google_reload_times = google_reload_times + 1;';
2453 echo ' grecaptcha.ready(function() {';
2454 echo ' grecaptcha.execute(\'' . esc_js( $site_key ) . '\', {action: "' . esc_js( $action ) . '"}).then(function(token) {';
2455 echo ' jQuery("form #elm_recaptcha_response").val(token);';
2456 echo ' });';
2457 echo ' });';
2458 echo ' }';
2459 echo '}, 1000*60);';
2460 echo '</script>';
2461 }
2462 }
2463
2464 /**
2465 * Upload CSV.
2466 * wp_ajax_wel_item_upload_ajax
2467 *
2468 * @return void
2469 */
2470 function wel_item_upload_ajax() {
2471 check_ajax_referer();
2472 $_REQUEST['action'] = 'upload_register';
2473 usces_item_uploadcsv();
2474 }
2475
2476 /**
2477 * Check progress.
2478 * wp_ajax_wel_item_progress_check_ajax
2479 *
2480 * @since 2.7.7
2481 * @return void
2482 */
2483 function wel_item_progress_check_ajax() {
2484 require_once USCES_PLUGIN_DIR . '/functions/progress-check.php';
2485 usces_item_progress_check();
2486 }
2487
2488 /**
2489 * Completed.
2490 * wp_ajax_wel_item_progress_completed_ajax
2491 *
2492 * @since 2.8.5
2493 * @return void
2494 */
2495 function wel_item_progress_completed_ajax() {
2496 check_ajax_referer( 'wel_progress_check_ajax', 'nonce' );
2497
2498 if ( 4 > usces_get_admin_user_level() ) {
2499 die( 'user_level' );
2500 }
2501
2502 $logfile = wp_unslash( filter_input( INPUT_POST, 'logfile', FILTER_DEFAULT ) );
2503 $logfile = WP_CONTENT_DIR . USCES_UPLOAD_TEMP . DIRECTORY_SEPARATOR . $logfile;
2504 // Make sure the file is exist.
2505 if ( usces_is_reserved_file( $logfile ) ) {
2506 // Get the content and echo it.
2507 $text = file_get_contents( $logfile );
2508 echo( $text );
2509 }
2510 exit;
2511 }
2512
2513 /**
2514 * Implementation of hook usces_filter_admin_custom_field_input_value()
2515 * Append new options from the instance of the order custom field.
2516 *
2517 * @since 2.5.3
2518 * @see usces_admin_custom_field_input()
2519 * @param string $value List of options.
2520 * @param string $key The custom field key.
2521 * @param string $entry The instance of the custom field.
2522 * @param string $custom_field The type of the custom field. Ex: order, delivery, customer, member...
2523 * @return string $value List of options appended new options from the instance.
2524 */
2525 function usces_filter_admin_custom_field_input_value( $value, $key, $entry, $custom_field ) {
2526 if ( 'order' === $custom_field ) {
2527 $means = $entry['means'];
2528 $is_choice_field_type = '0' === $means || '3' === $means || '4' === $means;
2529 if ( $is_choice_field_type ) {
2530 $options = explode( "\n", $value );
2531
2532 if ( is_array( $entry['data'] ) ) {
2533 $data = $entry['data'];
2534 } else {
2535 $data = ( ! empty( $entry['data'] ) && '#NONE#' !== $entry['data'] ) ? array( $entry['data'] ) : array();
2536 }
2537
2538 $diff_values = array_diff( $data, $options );
2539
2540 if ( ! empty( $diff_values ) ) {
2541 $options = array_merge( $options, $diff_values );
2542 $value = implode( "\n", $options );
2543 }
2544 }
2545 }
2546
2547 return $value;
2548 }
2549
2550 /**
2551 * Create Post type for Welcart product.
2552 * init
2553 *
2554 * @since 2.5.5
2555 */
2556 function usces_create_product_type() {
2557 register_post_type(
2558 'product',
2559 array(
2560 'labels' => array(
2561 'name' => __( 'Items', 'usces' ),
2562 'singular_name' => 'product',
2563 ),
2564 'public' => false,
2565 'has_archive' => false,
2566 'menu_position' => 3,
2567 'show_in_rest' => false,
2568 )
2569 );
2570 }
2571
2572 /**
2573 * Executement release card update lock.
2574 * usces_action_member_list_page
2575 *
2576 * @since 2.5.8
2577 * @param string $member_action Action.
2578 */
2579 function wel_execute_release_card_update_lock( $member_action ) {
2580 if ( 'editpost' === $member_action ) {
2581 $flag = filter_input( INPUT_POST, 'release_card_update_lock', FILTER_DEFAULT );
2582 $member_id = filter_input( INPUT_POST, 'member_id', FILTER_VALIDATE_INT );
2583 if ( 'release' === $flag && ! empty( $member_id ) ) {
2584 wel_release_card_update_lock( $member_id );
2585 }
2586 }
2587 }
2588
2589 /**
2590 * Welcart auto update control.
2591 * auto_update_plugin
2592 *
2593 * @since 2.8
2594 * @param bool|null $update Whether to update.
2595 * @param object $item The update offer.
2596 * @return boolean $update
2597 */
2598 function usces_auto_update_welcart( $update, $item ) {
2599 $targets = array( 'usc-e-shop' );
2600 if ( in_array( $item->slug ?? '', $targets ) ) {
2601
2602 $available_updates = get_site_transient( 'update_plugins' );
2603 if ( ! isset( $available_updates->response['usc-e-shop/usc-e-shop.php'] ) ) {
2604 return true;
2605 }
2606
2607 $plugin_info = $available_updates->response['usc-e-shop/usc-e-shop.php'];
2608 $current_arr = explode( '.', USCES_VERSION, 3 );
2609 $current_major = (string) $current_arr[0] . '.' . (string) $current_arr[1];
2610 $new_arr = explode( '.', $plugin_info->new_version, 3 );
2611 $new_major = (string) $new_arr[0] . '.' . (string) $new_arr[1];
2612
2613 if ( $current_major === $new_major ) {
2614 return true;
2615 } else {
2616 return false;
2617 }
2618 } else {
2619 return $update;
2620 }
2621 }
2622
2623 /**
2624 * Check if the same item code does not exist.
2625 * wp_ajax_wel_item_code_exists_ajax
2626 *
2627 * @since 2.8
2628 * @param string $item_code Item code.
2629 * @return boolean $res true if present, false otherwise.
2630 */
2631 function wel_item_code_exists_ajax() {
2632
2633 $wc_nonce = filter_input( INPUT_POST, 'wc_nonce' );
2634 $item_code = filter_input( INPUT_POST, 'item_code' );
2635
2636 $res = array(
2637 'result' => null,
2638 'item_code' => $item_code,
2639 'message' => '',
2640 );
2641
2642 if ( ! wp_verify_nonce( $wc_nonce, 'check_item_code' ) ) {
2643 wp_send_json( $res );
2644 }
2645
2646 $post_id = wel_get_id_by_item_code( $item_code, false );
2647
2648 $res['result'] = $post_id;
2649 $res['message'] = esc_js( sprintf( __( 'Product code %s has already been registered.', 'usces' ), $item_code ) );
2650
2651 wp_send_json( $res );
2652 }
2653
2654 /**
2655 * All credit security unlocked.
2656 * wp_ajax_credit_security_unlock
2657 */
2658 function wel_credit_security_unlock() {
2659
2660 $wc_nonce = filter_input( INPUT_POST, 'wc_nonce' );
2661 $res = array();
2662
2663 if ( ! wp_verify_nonce( $wc_nonce, 'credit_security_unlock' ) ) {
2664 wp_send_json( $res );
2665 }
2666
2667 wel_all_unlock();
2668
2669 wp_send_json( $res );
2670 }
2671
2672 /**
2673 * Log member data delete.
2674 *
2675 * @param array $res Result.
2676 * @param int $mem_id Member ID.
2677 * @return void
2678 */
2679 function wel_member_data_delete_log( $res, $mem_id ) {
2680 usces_log( 'Res: ' . print_r( $res, true ) . ' $_POST: ' . print_r( $_POST, true ) . ' $_GET: ' . print_r( $_GET, true ), 'db', 'member_delete', $mem_id );
2681 }
2682