| 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 |
$condition = filter_input( INPUT_POST, 'wc_condition' ); |
| 1843 |
|
| 1844 |
if ( 'welcart_confirm_check' !== $ajax ) { |
| 1845 |
$res = 'not permitted1'; |
| 1846 |
wp_send_json_error( $res ); |
| 1847 |
} |
| 1848 |
|
| 1849 |
if ( ! wp_verify_nonce( $nonce, 'wc_confirm' ) ) { |
| 1850 |
$res = 'not permitted2'; |
| 1851 |
wp_send_json_error( $res ); |
| 1852 |
} |
| 1853 |
// Session fixation remediation (Layer 3 / uscesid removal, A2): reopen the shopper's shop |
| 1854 |
// session via its own same-origin session cookie instead of decoding a crafted `uscesid` |
| 1855 |
// through uscesdc()/session_id(). This AJAX runs under admin-ajax.php, where |
| 1856 |
// usces_close_session() (admin_init) has closed the bootstrap session, so session_status() |
| 1857 |
// is PHP_SESSION_NONE here and we (re)attach to the frontend shop session identified by its |
| 1858 |
// cookie. Verified on trunk: the confirm-page uscesid decodes to exactly this cookie's |
| 1859 |
// session id, so reading the cookie reaches the same cart (result unchanged). |
| 1860 |
// See .docs/welcart2.x/security-remediation_uscesid-session-fixation.md 4.3.A A2. |
| 1861 |
if ( PHP_SESSION_NONE === session_status() ) { |
| 1862 |
$usces_options = get_option( 'usces' ); |
| 1863 |
$sess_name = defined( 'USCES_KEY' ) ? USCES_KEY : ( isset( $usces_options['usces_key'] ) ? $usces_options['usces_key'] : '' ); |
| 1864 |
if ( '' !== $sess_name && ! empty( $_COOKIE[ $sess_name ] ) ) { |
| 1865 |
$sess_id = preg_replace( '/[^A-Za-z0-9,\-]/', '', wp_unslash( $_COOKIE[ $sess_name ] ) ); |
| 1866 |
session_id( $sess_id ); |
| 1867 |
@session_start(); // phpcs:ignore |
| 1868 |
} |
| 1869 |
} |
| 1870 |
|
| 1871 |
$current['entry'] = $usces->cart->get_entry(); |
| 1872 |
$current['cart'] = $usces->cart->get_cart(); |
| 1873 |
session_write_close(); |
| 1874 |
|
| 1875 |
$condition = json_decode( urldecode( $condition ), true ); |
| 1876 |
|
| 1877 |
if ( $condition == $current ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 1878 |
$res = 'same'; |
| 1879 |
} elseif ( empty( $current['cart'] ) ) { |
| 1880 |
$res = 'timeover'; |
| 1881 |
} elseif ( $current['cart'] == $condition['cart'] && $current['entry'] != $condition['entry'] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 1882 |
$res = 'entrydiff'; |
| 1883 |
} else { |
| 1884 |
$res = 'different'; |
| 1885 |
} |
| 1886 |
wp_send_json_success( $res ); |
| 1887 |
} |
| 1888 |
|
| 1889 |
/** |
| 1890 |
* Parameter uscesL10n |
| 1891 |
* usces_filter_uscesL10n |
| 1892 |
* |
| 1893 |
* @param string $nouse Unused. |
| 1894 |
* @param int $post_id Post ID. |
| 1895 |
* @return string |
| 1896 |
*/ |
| 1897 |
function usces_confirm_uscesL10n( $nouse, $post_id ) { |
| 1898 |
global $usces; |
| 1899 |
|
| 1900 |
if ( 'confirm' === $usces->page ) { |
| 1901 |
$condition['entry'] = $usces->cart->get_entry(); |
| 1902 |
$condition['cart'] = $usces->cart->get_cart(); |
| 1903 |
|
| 1904 |
$js = ''; |
| 1905 |
$js .= "'condition': '" . urlencode( wp_json_encode( $condition ) ) . "',\n"; |
| 1906 |
$js .= "'cart_url': '" . USCES_CART_URL . "',\n"; |
| 1907 |
$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"; |
| 1908 |
return $js; |
| 1909 |
} |
| 1910 |
} |
| 1911 |
|
| 1912 |
/** |
| 1913 |
* Search zipcode |
| 1914 |
* usces_filter_states_form_js |
| 1915 |
* |
| 1916 |
* @param string $js Script. |
| 1917 |
* @return string |
| 1918 |
*/ |
| 1919 |
function usces_search_zipcode_check( $js ) { |
| 1920 |
global $usces; |
| 1921 |
|
| 1922 |
$option = get_option( 'usces', array() ); |
| 1923 |
if ( ! isset( $option['address_search'] ) || 'activate' != $option['address_search'] ) { |
| 1924 |
return $js; |
| 1925 |
} |
| 1926 |
|
| 1927 |
if ( ( ( $usces->use_js && ( is_page( USCES_MEMBER_NUMBER ) || $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) ) |
| 1928 |
&& ( ( true === $usces->is_member_logged_in() && WCUtils::is_blank( $usces->page ) ) || 'member' == $usces->page || 'editmemberform' == $usces->page || 'newmemberform' == $usces->page ) ) |
| 1929 |
|| |
| 1930 |
( ( $usces->use_js && ( is_page( USCES_CART_NUMBER ) || $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) ) ) |
| 1931 |
&& ( 'customer' == $usces->page || 'delivery' == $usces->page ) ) ) { |
| 1932 |
|
| 1933 |
$zip_id = ( isset( $_REQUEST['usces_page'] ) && 'msa_setting' == $_REQUEST['usces_page'] ) ? 'msa_zip' : 'zipcode'; |
| 1934 |
$js .= ' |
| 1935 |
<script type="text/javascript"> |
| 1936 |
(function($) { |
| 1937 |
$("#search_zipcode").click(function () { |
| 1938 |
var str = $("#' . $zip_id . '").val(); |
| 1939 |
if( !str.match(/^\d{7}$|^\d{3}-\d{4}$/) ){ |
| 1940 |
alert("' . __( 'Please enter the zip code correctly.', 'usces' ) . '"); |
| 1941 |
$("#' . $zip_id . '").focus(); |
| 1942 |
} |
| 1943 |
}); |
| 1944 |
})(jQuery); |
| 1945 |
</script>'; |
| 1946 |
} |
| 1947 |
return $js; |
| 1948 |
} |
| 1949 |
|
| 1950 |
/** |
| 1951 |
* Admin member list page. |
| 1952 |
* load-welcart-management_page_usces_memberlist |
| 1953 |
*/ |
| 1954 |
function usces_admin_member_list_hook() { |
| 1955 |
|
| 1956 |
if ( ! isset( $_POST['member_list_options_apply'] ) ) { |
| 1957 |
return; |
| 1958 |
} |
| 1959 |
|
| 1960 |
$list_option = get_option( 'usces_memberlist_option', array() ); |
| 1961 |
foreach ( (array) $list_option['view_column'] as $key => $value ) { |
| 1962 |
if ( isset( $_POST['hide'][ $key ] ) ) { |
| 1963 |
$list_option['view_column'][ $key ] = 1; |
| 1964 |
} else { |
| 1965 |
$list_option['view_column'][ $key ] = 0; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
$list_option['max_row'] = (int) $_POST['member_list_per_page']; |
| 1969 |
|
| 1970 |
update_option( 'usces_memberlist_option', $list_option ); |
| 1971 |
} |
| 1972 |
|
| 1973 |
/** |
| 1974 |
* Admin order list page. |
| 1975 |
* load-toplevel_page_usces_orderlist |
| 1976 |
* |
| 1977 |
* @param string $hook The current admin page. |
| 1978 |
* @return void |
| 1979 |
*/ |
| 1980 |
function usces_admin_order_list_hook( $hook ) { |
| 1981 |
if ( ! isset( $_POST['order_list_options_apply'] ) ) { |
| 1982 |
return; |
| 1983 |
} |
| 1984 |
|
| 1985 |
$list_option = get_option( 'usces_orderlist_option', array() ); |
| 1986 |
foreach ( (array) $list_option['view_column'] as $key => $value ) { |
| 1987 |
if ( isset( $_POST['hide'][ $key ] ) ) { |
| 1988 |
$list_option['view_column'][ $key ] = 1; |
| 1989 |
} else { |
| 1990 |
$list_option['view_column'][ $key ] = 0; |
| 1991 |
} |
| 1992 |
} |
| 1993 |
$list_option['max_row'] = (int) $_POST['order_list_per_page']; |
| 1994 |
|
| 1995 |
update_option( 'usces_orderlist_option', $list_option ); |
| 1996 |
} |
| 1997 |
|
| 1998 |
/** |
| 1999 |
* Admin member list screen settings |
| 2000 |
* screen_settings |
| 2001 |
* |
| 2002 |
* @param string $screen_settings Screen settings. |
| 2003 |
* @param object $screen WP_Screen object. |
| 2004 |
* @return string |
| 2005 |
*/ |
| 2006 |
function usces_memberlist_screen_settings( $screen_settings, $screen ) { |
| 2007 |
if ( 'welcart-management_page_usces_memberlist' != $screen->id |
| 2008 |
|| ( isset( $_REQUEST['member_action'] ) && 'edit' == $_REQUEST['member_action'] ) ) { |
| 2009 |
return $screen_settings; |
| 2010 |
} |
| 2011 |
|
| 2012 |
require_once USCES_PLUGIN_DIR . '/classes/memberList.class.php'; |
| 2013 |
$memberlist = new WlcMemberList(); |
| 2014 |
$arr_column = $memberlist->get_column(); |
| 2015 |
$list_option = get_option( 'usces_memberlist_option', array() ); |
| 2016 |
$init_view = array( 'ID', 'name1', 'name2', 'pref', 'address1', 'tel', 'email', 'entrydate', 'rank', 'point' ); |
| 2017 |
|
| 2018 |
$screen_settings = ' |
| 2019 |
<fieldset class="metabox-prefs"> |
| 2020 |
<legend>' . __( 'Columns' ) . '</legend>'; |
| 2021 |
foreach ( $arr_column as $key => $value ) { |
| 2022 |
if ( 'ID' == $key || 'csod_' == substr( $key, 0, 5 ) ) { |
| 2023 |
continue; |
| 2024 |
} |
| 2025 |
|
| 2026 |
if ( ! isset( $list_option['view_column'][ $key ] ) && in_array( $key, $init_view ) ) { |
| 2027 |
$list_option['view_column'][ $key ] = 1; |
| 2028 |
} elseif ( ! isset( $list_option['view_column'][ $key ] ) ) { |
| 2029 |
$list_option['view_column'][ $key ] = 0; |
| 2030 |
} |
| 2031 |
|
| 2032 |
$checked = $list_option['view_column'][ $key ] ? ' checked="checked"' : ''; |
| 2033 |
$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"; |
| 2034 |
} |
| 2035 |
$screen_settings .= '</fieldset>'; |
| 2036 |
|
| 2037 |
if ( ! isset( $list_option['max_row'] ) ) { |
| 2038 |
$list_option['max_row'] = 50; |
| 2039 |
} |
| 2040 |
|
| 2041 |
$screen_settings .= '<fieldset class="screen-options"> |
| 2042 |
<legend>' . __( 'Pagination' ) . '</legend> |
| 2043 |
<label for="edit_post_per_page">' . __( 'Number of items per page:' ) . '</label> |
| 2044 |
<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'] . '" /> |
| 2045 |
</fieldset> |
| 2046 |
<p class="submit"><input type="submit" name="member_list_options_apply" id="screen-options-apply" class="button button-primary" value="' . __( 'Apply' ) . '" /></p>'; |
| 2047 |
|
| 2048 |
update_option( 'usces_memberlist_option', $list_option ); |
| 2049 |
return $screen_settings; |
| 2050 |
} |
| 2051 |
|
| 2052 |
/** |
| 2053 |
* Admin order list screen settings |
| 2054 |
* screen_settings |
| 2055 |
* |
| 2056 |
* @param string $screen_settings Screen settings. |
| 2057 |
* @param object $screen WP_Screen object. |
| 2058 |
* @return string |
| 2059 |
*/ |
| 2060 |
function usces_orderlist_screen_settings( $screen_settings, $screen ) { |
| 2061 |
if ( 'toplevel_page_usces_orderlist' != $screen->id |
| 2062 |
|| ( isset( $_REQUEST['order_action'] ) && 'edit' == $_REQUEST['order_action'] ) ) { |
| 2063 |
return $screen_settings; |
| 2064 |
} |
| 2065 |
|
| 2066 |
require_once USCES_PLUGIN_DIR . '/classes/orderList2.class.php'; |
| 2067 |
$orderlist = new WlcOrderList(); |
| 2068 |
$arr_column = $orderlist->get_all_column(); |
| 2069 |
$list_option = get_option( 'usces_orderlist_option', array() ); |
| 2070 |
$init_view = array( 'deco_id', 'order_date', 'process_status', 'payment_name', 'receipt_status', 'total_price', 'deli_method', 'mem_id', 'name1', 'name2', 'pref' ); |
| 2071 |
if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) { |
| 2072 |
$init_view[] = 'reg_id'; |
| 2073 |
} |
| 2074 |
$init_view = apply_filters( 'usces_filter_orderlist_column_init_view', $init_view ); |
| 2075 |
|
| 2076 |
$screen_settings = ' |
| 2077 |
<fieldset class="metabox-prefs"> |
| 2078 |
<legend>' . __( 'Columns' ) . '</legend>'; |
| 2079 |
foreach ( $arr_column as $key => $value ) { |
| 2080 |
|
| 2081 |
if ( ! isset( $list_option['view_column'][ $key ] ) && in_array( $key, $init_view ) ) { |
| 2082 |
$list_option['view_column'][ $key ] = 1; |
| 2083 |
} elseif ( ! isset( $list_option['view_column'][ $key ] ) ) { |
| 2084 |
$list_option['view_column'][ $key ] = 0; |
| 2085 |
} |
| 2086 |
|
| 2087 |
$checked = ( isset( $list_option['view_column'][ $key ] ) && $list_option['view_column'][ $key ] ) ? ' checked="checked"' : ''; |
| 2088 |
$screen_settings .= '<label><input class="hide-column-tog" name="hide[' . $key . ']" type="checkbox" id="' . $key . '-hide" value="' . $key . '"' . $checked . ' />' . esc_html( $value ) . '</label>' . "\n"; |
| 2089 |
} |
| 2090 |
$screen_settings .= '</fieldset>'; |
| 2091 |
|
| 2092 |
if ( ! isset( $list_option['max_row'] ) ) { |
| 2093 |
$list_option['max_row'] = 50; |
| 2094 |
} |
| 2095 |
|
| 2096 |
$screen_settings .= '<fieldset class="screen-options"> |
| 2097 |
<legend>' . __( 'Pagination' ) . '</legend> |
| 2098 |
<label for="edit_post_per_page">' . __( 'Number of items per page:' ) . '</label> |
| 2099 |
<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'] . '" /> |
| 2100 |
</fieldset> |
| 2101 |
<p class="submit"><input type="submit" name="order_list_options_apply" id="screen-options-apply" class="button button-primary" value="' . __( 'Apply' ) . '" /></p>'; |
| 2102 |
|
| 2103 |
update_option( 'usces_orderlist_option', $list_option ); |
| 2104 |
return $screen_settings; |
| 2105 |
} |
| 2106 |
|
| 2107 |
/** |
| 2108 |
* New member registration anti-spam. |
| 2109 |
* usces_filter_member_check |
| 2110 |
* |
| 2111 |
* @param string $mes Message. |
| 2112 |
* @return string |
| 2113 |
*/ |
| 2114 |
function usces_memberreg_spamcheck( $mes ) { |
| 2115 |
|
| 2116 |
if ( ! WCUtils::is_blank( $_POST['member']['name1'] ) && trim( $_POST['member']['name1'] ) == trim( $_POST['member']['name2'] ) ) { |
| 2117 |
$mes .= __( 'Name is not correct', 'usces' ) . '<br />'; |
| 2118 |
} |
| 2119 |
|
| 2120 |
if ( ! WCUtils::is_blank( $_POST['member']['address1'] ) && trim( $_POST['member']['address1'] ) == trim( $_POST['member']['address2'] ) ) { |
| 2121 |
$mes .= __( 'Address is not correct', 'usces' ) . '<br />'; |
| 2122 |
} |
| 2123 |
|
| 2124 |
if ( $mes ) { |
| 2125 |
usces_log( 'memberreg_spamcheck : ' . $mes, 'acting_transaction.log' ); |
| 2126 |
} |
| 2127 |
|
| 2128 |
return $mes; |
| 2129 |
} |
| 2130 |
|
| 2131 |
/** |
| 2132 |
* New member registration anti-spam. |
| 2133 |
* usces_filter_member_check_fromcart |
| 2134 |
* |
| 2135 |
* @param string $mes Message. |
| 2136 |
* @return string |
| 2137 |
*/ |
| 2138 |
function usces_fromcart_memberreg_spamcheck( $mes ) { |
| 2139 |
|
| 2140 |
if ( ! WCUtils::is_blank( $_POST['customer']['name1'] ) && trim( $_POST['customer']['name1'] ) == trim( $_POST['customer']['name2'] ) ) { |
| 2141 |
$mes .= __( 'Name is not correct', 'usces' ) . '<br />'; |
| 2142 |
} |
| 2143 |
|
| 2144 |
if ( ! WCUtils::is_blank( $_POST['customer']['address1'] ) && trim( $_POST['customer']['address1'] ) == trim( $_POST['customer']['address2'] ) ) { |
| 2145 |
$mes .= __( 'Address is not correct', 'usces' ) . '<br />'; |
| 2146 |
} |
| 2147 |
|
| 2148 |
if ( $mes ) { |
| 2149 |
usces_log( 'fromcart_memberreg_spamcheck : ' . $mes, 'acting_transaction.log' ); |
| 2150 |
} |
| 2151 |
|
| 2152 |
return $mes; |
| 2153 |
} |
| 2154 |
|
| 2155 |
/** |
| 2156 |
* Welcart priority |
| 2157 |
* pre_update_option_active_plugins |
| 2158 |
* |
| 2159 |
* @param mixed $active_plugins The new, unserialized option value. |
| 2160 |
* @param mixed $old_value The old option value. |
| 2161 |
* @return array |
| 2162 |
*/ |
| 2163 |
function usces_priority_active_plugins( $active_plugins, $old_value ) { |
| 2164 |
foreach ( $active_plugins as $no => $path ) { |
| 2165 |
if ( USCES_PLUGIN_BASENAME == $path ) { |
| 2166 |
unset( $active_plugins[ $no ] ); |
| 2167 |
array_unshift( $active_plugins, USCES_PLUGIN_BASENAME ); |
| 2168 |
break; |
| 2169 |
} |
| 2170 |
} |
| 2171 |
return $active_plugins; |
| 2172 |
} |
| 2173 |
|
| 2174 |
/** |
| 2175 |
* Password change e-mail. |
| 2176 |
* usces_action_changepass_page_inform |
| 2177 |
*/ |
| 2178 |
function usces_action_lostmail_inform() { |
| 2179 |
$mem_mail = wp_unslash( $_REQUEST['mem'] ); |
| 2180 |
$lostkey = wp_unslash( $_REQUEST['key'] ); |
| 2181 |
$html = ' |
| 2182 |
<input type="hidden" name="mem" value="' . esc_attr( $mem_mail ) . '" /> |
| 2183 |
<input type="hidden" name="key" value="' . esc_attr( $lostkey ) . '" />' . "\n"; |
| 2184 |
wel_esc_script_e( $html ); |
| 2185 |
} |
| 2186 |
|
| 2187 |
/** |
| 2188 |
* Password change e-mail. |
| 2189 |
* usces_filter_changepassword_inform |
| 2190 |
* |
| 2191 |
* @param string $html Form. |
| 2192 |
* @return string |
| 2193 |
*/ |
| 2194 |
function usces_filter_lostmail_inform( $html ) { |
| 2195 |
$mem_mail = wp_unslash( $_REQUEST['mem'] ); |
| 2196 |
$lostkey = wp_unslash( $_REQUEST['key'] ); |
| 2197 |
$html .= ' |
| 2198 |
<input type="hidden" name="mem" value="' . esc_attr( $mem_mail ) . '" /> |
| 2199 |
<input type="hidden" name="key" value="' . esc_attr( $lostkey ) . '" />' . "\n"; |
| 2200 |
return $html; |
| 2201 |
} |
| 2202 |
|
| 2203 |
/** |
| 2204 |
* Purchase template form. |
| 2205 |
* usces_filter_confirm_inform |
| 2206 |
* |
| 2207 |
* @param string $html Purchase template form. |
| 2208 |
* @param array $payments Payment data. |
| 2209 |
* @param string $acting_flag Payment method. |
| 2210 |
* @param string $rand Settlement link key. |
| 2211 |
* @param string $purchase_disabled Disabled tag. |
| 2212 |
* @return string |
| 2213 |
*/ |
| 2214 |
function wc_purchase_nonce( $html, $payments, $acting_flag, $rand, $purchase_disabled ) { |
| 2215 |
global $usces; |
| 2216 |
|
| 2217 |
$nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $usces->nonacting_settlements ); |
| 2218 |
if ( strpos( $html, '_purchase_nonce' ) || in_array( $payments['settlement'], $nonacting_settlements ) ) { |
| 2219 |
return $html; |
| 2220 |
} |
| 2221 |
|
| 2222 |
$noncekey = $usces->member_nonce_key( 'wc_purchase_nonce' ); |
| 2223 |
$html .= wp_nonce_field( $noncekey, '_purchase_nonce', false, false ) . "\n"; |
| 2224 |
return $html; |
| 2225 |
} |
| 2226 |
|
| 2227 |
/** |
| 2228 |
* Purchase check |
| 2229 |
* usces_purchase_check |
| 2230 |
*/ |
| 2231 |
function wc_purchase_nonce_check() { |
| 2232 |
global $usces; |
| 2233 |
|
| 2234 |
$entry = $usces->cart->get_entry(); |
| 2235 |
if ( ! isset( $entry['order']['payment_name'] ) || empty( $entry['order']['payment_name'] ) ) { |
| 2236 |
wp_redirect( home_url() ); |
| 2237 |
exit; |
| 2238 |
} |
| 2239 |
|
| 2240 |
$nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $usces->nonacting_settlements ); |
| 2241 |
$payments = usces_get_payments_by_name( $entry['order']['payment_name'] ); |
| 2242 |
if ( in_array( $payments['settlement'], $nonacting_settlements ) ) { |
| 2243 |
return true; |
| 2244 |
} |
| 2245 |
|
| 2246 |
$nonce = isset( $_REQUEST['_purchase_nonce'] ) ? $_REQUEST['_purchase_nonce'] : ''; |
| 2247 |
if ( empty( $nonce ) || $usces->verify_member_nonce( $nonce, 'wc_purchase_nonce' ) ) { |
| 2248 |
return true; |
| 2249 |
} |
| 2250 |
|
| 2251 |
wp_redirect( home_url() ); |
| 2252 |
exit; |
| 2253 |
} |
| 2254 |
|
| 2255 |
/** |
| 2256 |
* Checking in $usces->use_point() |
| 2257 |
* usces_action_confirm_page_point_inform |
| 2258 |
*/ |
| 2259 |
function usces_use_point_nonce() { |
| 2260 |
global $usces; |
| 2261 |
|
| 2262 |
$noncekey = $usces->member_nonce_key( 'use_point' ); |
| 2263 |
wp_nonce_field( $noncekey, 'wc_nonce' ); |
| 2264 |
} |
| 2265 |
|
| 2266 |
/** |
| 2267 |
* Check post member page |
| 2268 |
* usces_action_newmember_page_inform |
| 2269 |
* usces_action_memberinfo_page_inform |
| 2270 |
* usces_action_newpass_page_inform |
| 2271 |
* usces_action_changepass_page_inform |
| 2272 |
* usces_action_customer_page_inform |
| 2273 |
*/ |
| 2274 |
function usces_post_member_nonce() { |
| 2275 |
global $usces; |
| 2276 |
|
| 2277 |
$noncekey = $usces->member_nonce_key( 'post_member' ); |
| 2278 |
wp_nonce_field( $noncekey, 'wc_nonce' ); |
| 2279 |
} |
| 2280 |
|
| 2281 |
/** |
| 2282 |
* Check post member login page |
| 2283 |
* usces_action_login_page_inform |
| 2284 |
* usces_action_customer_page_member_inform |
| 2285 |
*/ |
| 2286 |
function usces_member_login_nonce() { |
| 2287 |
global $usces; |
| 2288 |
|
| 2289 |
$noncekey = $usces->member_nonce_key( 'post_member' ); |
| 2290 |
wp_nonce_field( $noncekey, 'wel_nonce' ); |
| 2291 |
} |
| 2292 |
|
| 2293 |
/** |
| 2294 |
* Order edit form additional information |
| 2295 |
* usces_action_order_edit_form_detail_bottom |
| 2296 |
* |
| 2297 |
* @param array $data Order data. |
| 2298 |
* @param array $cscs_meta Custom customer data. |
| 2299 |
* @param array $action_args Order action. |
| 2300 |
* @return void |
| 2301 |
*/ |
| 2302 |
function wel_order_edit_customer_additional_information( $data, $cscs_meta, $action_args ) { |
| 2303 |
global $usces; |
| 2304 |
|
| 2305 |
$order_id = isset( $data['ID'] ) ? (int) $data['ID'] : 0; |
| 2306 |
if ( ! $order_id ) { |
| 2307 |
return; |
| 2308 |
} |
| 2309 |
|
| 2310 |
$value = $usces->get_order_meta_value( 'extra_info', $order_id ); |
| 2311 |
if ( ! $value ) { |
| 2312 |
return; |
| 2313 |
} |
| 2314 |
|
| 2315 |
$infos = unserialize( $value ); |
| 2316 |
$html = '<tr> |
| 2317 |
<td colspan="2" class="label cus_note_label">' . __( 'Others', 'usces' ) . '</td> |
| 2318 |
<td colspan="4" class="cus_note_label">' . "\n"; |
| 2319 |
$html .= '<table border="0" cellspacing="0" class="extra_info cus_info">' . "\n"; |
| 2320 |
foreach ( $infos as $key => $info ) { |
| 2321 |
$key = str_replace( 'USER_AGANT', 'USER_AGENT', $key ); |
| 2322 |
$html .= '<tr><td class="label cus_note_label">' . esc_html( $key ) . '</td><td class="cus_note_label">' . esc_html( $info ) . '</td></tr>' . "\n"; |
| 2323 |
} |
| 2324 |
$html .= '</table>' . "\n"; |
| 2325 |
$html .= '</td></tr>' . "\n"; |
| 2326 |
|
| 2327 |
wel_esc_script_e( $html ); |
| 2328 |
} |
| 2329 |
|
| 2330 |
/** |
| 2331 |
* Save additional information. |
| 2332 |
* usces_post_reg_orderdata |
| 2333 |
* |
| 2334 |
* @param int $order_id Order ID. |
| 2335 |
* @param array $results Settlement result data. |
| 2336 |
* @return void |
| 2337 |
*/ |
| 2338 |
function wel_save_extra_info_to_ordermeta( $order_id, $results ) { |
| 2339 |
global $usces; |
| 2340 |
|
| 2341 |
if ( ! $order_id ) { |
| 2342 |
return; |
| 2343 |
} |
| 2344 |
|
| 2345 |
$info = array( |
| 2346 |
'IP' => ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : '', |
| 2347 |
'USER_AGENT' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '', |
| 2348 |
); |
| 2349 |
|
| 2350 |
$usces->set_order_meta_value( 'extra_info', serialize( $info ), $order_id ); |
| 2351 |
} |
| 2352 |
|
| 2353 |
/** |
| 2354 |
* Navigation menu arguments. |
| 2355 |
* wp_nav_menu_args |
| 2356 |
* |
| 2357 |
* @param array $args An array containing wp_nav_menu() arguments. |
| 2358 |
* @return array |
| 2359 |
*/ |
| 2360 |
function usces_wp_nav_menu_args( $args ) { |
| 2361 |
|
| 2362 |
usces_remove_filter(); |
| 2363 |
|
| 2364 |
return $args; |
| 2365 |
} |
| 2366 |
|
| 2367 |
/** |
| 2368 |
* Navigation menu. |
| 2369 |
* wp_nav_menu |
| 2370 |
* |
| 2371 |
* @param string $nav_menu The HTML content for the navigation menu. |
| 2372 |
* @param stdClass $args An object containing wp_nav_menu() arguments. |
| 2373 |
* @return string |
| 2374 |
*/ |
| 2375 |
function usces_wp_nav_menu( $nav_menu, $args ) { |
| 2376 |
|
| 2377 |
usces_reset_filter(); |
| 2378 |
|
| 2379 |
return $nav_menu; |
| 2380 |
} |
| 2381 |
|
| 2382 |
/** |
| 2383 |
* Session write close. |
| 2384 |
* admin_init |
| 2385 |
*/ |
| 2386 |
function usces_close_session() { |
| 2387 |
if ( session_status() == PHP_SESSION_ACTIVE ) { |
| 2388 |
session_write_close(); |
| 2389 |
} |
| 2390 |
} |
| 2391 |
|
| 2392 |
/** |
| 2393 |
* Regenerate the session ID on member login (session fixation countermeasure). |
| 2394 |
* usces_action_after_login |
| 2395 |
* |
| 2396 |
* Fires on every successful member login path (member_login() / member_just_login() |
| 2397 |
* and extension logins that trigger usces_action_after_login). The uscesid mechanism |
| 2398 |
* itself has been removed (A1/C) and set_cookie() now regenerates unconditionally, |
| 2399 |
* but not every login path calls set_cookie() (member_just_login() does not), so this |
| 2400 |
* hook is what guarantees regeneration on all of them. |
| 2401 |
*/ |
| 2402 |
function usces_regenerate_session_on_login() { |
| 2403 |
if ( session_status() == PHP_SESSION_ACTIVE && ! headers_sent() ) { |
| 2404 |
session_regenerate_id( true ); |
| 2405 |
} |
| 2406 |
} |
| 2407 |
|
| 2408 |
/** |
| 2409 |
* Handles OPTIONS requests for the server. |
| 2410 |
* |
| 2411 |
* This is handled outside of the server code, as it doesn't obey normal route |
| 2412 |
* mapping. |
| 2413 |
* |
| 2414 |
* @since 4.4.0 |
| 2415 |
* |
| 2416 |
* @param mixed $response Current reponse, either response or `null` to indicate pass-through. |
| 2417 |
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server). |
| 2418 |
* @param WP_REST_Request $request The request that was used to make current response. |
| 2419 |
* @return WP_REST_Response Modified response, either response or `null` to indicate pass-through. |
| 2420 |
*/ |
| 2421 |
function usces_close_session_loopback( $response, $handler, $request ) { |
| 2422 |
$router = $request->get_route(); |
| 2423 |
if ( ! empty( $router ) && '/wp-site-health/v1/tests/loopback-requests' == $router ) { |
| 2424 |
usces_close_session(); |
| 2425 |
} |
| 2426 |
return $response; |
| 2427 |
} |
| 2428 |
|
| 2429 |
/** |
| 2430 |
* Google recaptcha script. |
| 2431 |
* wp_print_footer_scripts |
| 2432 |
*/ |
| 2433 |
function usces_add_google_recaptcha_v3_script() { |
| 2434 |
global $usces, $usces_entries, $usces_carts; |
| 2435 |
|
| 2436 |
if ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) && 'newmemberform' === $usces->page ) { |
| 2437 |
print_google_recaptcha_response( 'create_new_member', 'memberpages' ); |
| 2438 |
} |
| 2439 |
|
| 2440 |
if ( ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'customer' === $usces->page ) ) { |
| 2441 |
print_google_recaptcha_response( 'customer_order_page', 'customer-info', 'customer_form' ); |
| 2442 |
} |
| 2443 |
if ( ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) && 'delivery' === $usces->page ) ) { |
| 2444 |
print_google_recaptcha_response( 'delivery_order_page', 'delivery-info', '' ); |
| 2445 |
} |
| 2446 |
} |
| 2447 |
|
| 2448 |
/** |
| 2449 |
* Google recaptcha badge display. |
| 2450 |
* |
| 2451 |
* @param string $action Page action. |
| 2452 |
* @param string $parent_element_id Parent page. |
| 2453 |
* @param string $form_name Page name. |
| 2454 |
* @return void |
| 2455 |
*/ |
| 2456 |
function print_google_recaptcha_response( $action, $parent_element_id, $form_name = '' ) { |
| 2457 |
$option = get_option( 'usces_ex', array() ); |
| 2458 |
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'] ) ) ) { |
| 2459 |
$site_key = isset( $option['system']['google_recaptcha']['site_key'] ) ? $option['system']['google_recaptcha']['site_key'] : ''; |
| 2460 |
echo '<script src="https://www.google.com/recaptcha/api.js?render=' . esc_js( $site_key ) . '"></script>'; |
| 2461 |
echo '<script>'; |
| 2462 |
echo 'grecaptcha.ready(function() {'; |
| 2463 |
echo ' grecaptcha.execute(\'' . esc_js( $site_key ) . '\', {action: "' . esc_js( $action ) . '"}).then(function(token) {'; |
| 2464 |
echo ' jQuery("form").append(\'<input type="hidden" id="elm_recaptcha_response" name="recaptcha_response" value="\'+ token +\'">\');'; |
| 2465 |
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 +\'">\'); }'; |
| 2466 |
echo ' });'; |
| 2467 |
echo '});'; |
| 2468 |
echo '</script>'; |
| 2469 |
|
| 2470 |
// run time reload google captcha token v3 key after 1 minutes. |
| 2471 |
echo '<script>'; |
| 2472 |
echo 'var max_google_reload_times = 10;'; |
| 2473 |
echo 'var google_reload_times = 1;'; |
| 2474 |
echo 'var function_token_reload = setInterval(function(){'; |
| 2475 |
echo ' if (google_reload_times > max_google_reload_times) {'; |
| 2476 |
echo ' clearInterval(function_token_reload);'; |
| 2477 |
echo ' } else { '; |
| 2478 |
echo ' google_reload_times = google_reload_times + 1;'; |
| 2479 |
echo ' grecaptcha.ready(function() {'; |
| 2480 |
echo ' grecaptcha.execute(\'' . esc_js( $site_key ) . '\', {action: "' . esc_js( $action ) . '"}).then(function(token) {'; |
| 2481 |
echo ' jQuery("form #elm_recaptcha_response").val(token);'; |
| 2482 |
echo ' });'; |
| 2483 |
echo ' });'; |
| 2484 |
echo ' }'; |
| 2485 |
echo '}, 1000*60);'; |
| 2486 |
echo '</script>'; |
| 2487 |
} |
| 2488 |
} |
| 2489 |
|
| 2490 |
/** |
| 2491 |
* Upload CSV. |
| 2492 |
* wp_ajax_wel_item_upload_ajax |
| 2493 |
* |
| 2494 |
* @return void |
| 2495 |
*/ |
| 2496 |
function wel_item_upload_ajax() { |
| 2497 |
check_ajax_referer(); |
| 2498 |
$_REQUEST['action'] = 'upload_register'; |
| 2499 |
usces_item_uploadcsv(); |
| 2500 |
} |
| 2501 |
|
| 2502 |
/** |
| 2503 |
* Check progress. |
| 2504 |
* wp_ajax_wel_item_progress_check_ajax |
| 2505 |
* |
| 2506 |
* @since 2.7.7 |
| 2507 |
* @return void |
| 2508 |
*/ |
| 2509 |
function wel_item_progress_check_ajax() { |
| 2510 |
require_once USCES_PLUGIN_DIR . '/functions/progress-check.php'; |
| 2511 |
usces_item_progress_check(); |
| 2512 |
} |
| 2513 |
|
| 2514 |
/** |
| 2515 |
* Completed. |
| 2516 |
* wp_ajax_wel_item_progress_completed_ajax |
| 2517 |
* |
| 2518 |
* @since 2.8.5 |
| 2519 |
* @return void |
| 2520 |
*/ |
| 2521 |
function wel_item_progress_completed_ajax() { |
| 2522 |
check_ajax_referer( 'wel_progress_check_ajax', 'nonce' ); |
| 2523 |
|
| 2524 |
if ( 4 > usces_get_admin_user_level() ) { |
| 2525 |
die( 'user_level' ); |
| 2526 |
} |
| 2527 |
|
| 2528 |
$logfile = wp_unslash( filter_input( INPUT_POST, 'logfile', FILTER_DEFAULT ) ); |
| 2529 |
$logfile = WP_CONTENT_DIR . USCES_UPLOAD_TEMP . DIRECTORY_SEPARATOR . $logfile; |
| 2530 |
// Make sure the file is exist. |
| 2531 |
if ( usces_is_reserved_file( $logfile ) ) { |
| 2532 |
// Get the content and echo it. |
| 2533 |
$text = file_get_contents( $logfile ); |
| 2534 |
echo( $text ); |
| 2535 |
} |
| 2536 |
exit; |
| 2537 |
} |
| 2538 |
|
| 2539 |
/** |
| 2540 |
* Implementation of hook usces_filter_admin_custom_field_input_value() |
| 2541 |
* Append new options from the instance of the order custom field. |
| 2542 |
* |
| 2543 |
* @since 2.5.3 |
| 2544 |
* @see usces_admin_custom_field_input() |
| 2545 |
* @param string $value List of options. |
| 2546 |
* @param string $key The custom field key. |
| 2547 |
* @param string $entry The instance of the custom field. |
| 2548 |
* @param string $custom_field The type of the custom field. Ex: order, delivery, customer, member... |
| 2549 |
* @return string $value List of options appended new options from the instance. |
| 2550 |
*/ |
| 2551 |
function usces_filter_admin_custom_field_input_value( $value, $key, $entry, $custom_field ) { |
| 2552 |
if ( 'order' === $custom_field ) { |
| 2553 |
$means = $entry['means']; |
| 2554 |
$is_choice_field_type = '0' === $means || '3' === $means || '4' === $means; |
| 2555 |
if ( $is_choice_field_type ) { |
| 2556 |
$options = explode( "\n", $value ); |
| 2557 |
|
| 2558 |
if ( is_array( $entry['data'] ) ) { |
| 2559 |
$data = $entry['data']; |
| 2560 |
} else { |
| 2561 |
$data = ( ! empty( $entry['data'] ) && '#NONE#' !== $entry['data'] ) ? array( $entry['data'] ) : array(); |
| 2562 |
} |
| 2563 |
|
| 2564 |
$diff_values = array_diff( $data, $options ); |
| 2565 |
|
| 2566 |
if ( ! empty( $diff_values ) ) { |
| 2567 |
$options = array_merge( $options, $diff_values ); |
| 2568 |
$value = implode( "\n", $options ); |
| 2569 |
} |
| 2570 |
} |
| 2571 |
} |
| 2572 |
|
| 2573 |
return $value; |
| 2574 |
} |
| 2575 |
|
| 2576 |
/** |
| 2577 |
* Create Post type for Welcart product. |
| 2578 |
* init |
| 2579 |
* |
| 2580 |
* @since 2.5.5 |
| 2581 |
*/ |
| 2582 |
function usces_create_product_type() { |
| 2583 |
register_post_type( |
| 2584 |
'product', |
| 2585 |
array( |
| 2586 |
'labels' => array( |
| 2587 |
'name' => __( 'Items', 'usces' ), |
| 2588 |
'singular_name' => 'product', |
| 2589 |
), |
| 2590 |
'public' => false, |
| 2591 |
'has_archive' => false, |
| 2592 |
'menu_position' => 3, |
| 2593 |
'show_in_rest' => false, |
| 2594 |
) |
| 2595 |
); |
| 2596 |
} |
| 2597 |
|
| 2598 |
/** |
| 2599 |
* Executement release card update lock. |
| 2600 |
* usces_action_member_list_page |
| 2601 |
* |
| 2602 |
* @since 2.5.8 |
| 2603 |
* @param string $member_action Action. |
| 2604 |
*/ |
| 2605 |
function wel_execute_release_card_update_lock( $member_action ) { |
| 2606 |
if ( 'editpost' === $member_action ) { |
| 2607 |
$flag = filter_input( INPUT_POST, 'release_card_update_lock', FILTER_DEFAULT ); |
| 2608 |
$member_id = filter_input( INPUT_POST, 'member_id', FILTER_VALIDATE_INT ); |
| 2609 |
if ( 'release' === $flag && ! empty( $member_id ) ) { |
| 2610 |
wel_release_card_update_lock( $member_id ); |
| 2611 |
} |
| 2612 |
} |
| 2613 |
} |
| 2614 |
|
| 2615 |
/** |
| 2616 |
* Welcart auto update control. |
| 2617 |
* auto_update_plugin |
| 2618 |
* |
| 2619 |
* @since 2.8 |
| 2620 |
* @param bool|null $update Whether to update. |
| 2621 |
* @param object $item The update offer. |
| 2622 |
* @return boolean $update |
| 2623 |
*/ |
| 2624 |
function usces_auto_update_welcart( $update, $item ) { |
| 2625 |
$targets = array( 'usc-e-shop' ); |
| 2626 |
if ( in_array( $item->slug ?? '', $targets ) ) { |
| 2627 |
|
| 2628 |
$available_updates = get_site_transient( 'update_plugins' ); |
| 2629 |
if ( ! isset( $available_updates->response['usc-e-shop/usc-e-shop.php'] ) ) { |
| 2630 |
return true; |
| 2631 |
} |
| 2632 |
|
| 2633 |
$plugin_info = $available_updates->response['usc-e-shop/usc-e-shop.php']; |
| 2634 |
$current_arr = explode( '.', USCES_VERSION, 3 ); |
| 2635 |
$current_major = (string) $current_arr[0] . '.' . (string) $current_arr[1]; |
| 2636 |
$new_arr = explode( '.', $plugin_info->new_version, 3 ); |
| 2637 |
$new_major = (string) $new_arr[0] . '.' . (string) $new_arr[1]; |
| 2638 |
|
| 2639 |
if ( $current_major === $new_major ) { |
| 2640 |
return true; |
| 2641 |
} else { |
| 2642 |
return false; |
| 2643 |
} |
| 2644 |
} else { |
| 2645 |
return $update; |
| 2646 |
} |
| 2647 |
} |
| 2648 |
|
| 2649 |
/** |
| 2650 |
* Check if the same item code does not exist. |
| 2651 |
* wp_ajax_wel_item_code_exists_ajax |
| 2652 |
* |
| 2653 |
* @since 2.8 |
| 2654 |
* @param string $item_code Item code. |
| 2655 |
* @return boolean $res true if present, false otherwise. |
| 2656 |
*/ |
| 2657 |
function wel_item_code_exists_ajax() { |
| 2658 |
|
| 2659 |
$wc_nonce = filter_input( INPUT_POST, 'wc_nonce' ); |
| 2660 |
$item_code = filter_input( INPUT_POST, 'item_code' ); |
| 2661 |
|
| 2662 |
$res = array( |
| 2663 |
'result' => null, |
| 2664 |
'item_code' => $item_code, |
| 2665 |
'message' => '', |
| 2666 |
); |
| 2667 |
|
| 2668 |
if ( ! wp_verify_nonce( $wc_nonce, 'check_item_code' ) ) { |
| 2669 |
wp_send_json( $res ); |
| 2670 |
} |
| 2671 |
|
| 2672 |
$post_id = wel_get_id_by_item_code( $item_code, false ); |
| 2673 |
|
| 2674 |
$res['result'] = $post_id; |
| 2675 |
$res['message'] = esc_js( sprintf( __( 'Product code %s has already been registered.', 'usces' ), $item_code ) ); |
| 2676 |
|
| 2677 |
wp_send_json( $res ); |
| 2678 |
} |
| 2679 |
|
| 2680 |
/** |
| 2681 |
* All credit security unlocked. |
| 2682 |
* wp_ajax_credit_security_unlock |
| 2683 |
*/ |
| 2684 |
function wel_credit_security_unlock() { |
| 2685 |
|
| 2686 |
$wc_nonce = filter_input( INPUT_POST, 'wc_nonce' ); |
| 2687 |
$res = array(); |
| 2688 |
|
| 2689 |
if ( ! wp_verify_nonce( $wc_nonce, 'credit_security_unlock' ) ) { |
| 2690 |
wp_send_json( $res ); |
| 2691 |
} |
| 2692 |
|
| 2693 |
wel_all_unlock(); |
| 2694 |
|
| 2695 |
wp_send_json( $res ); |
| 2696 |
} |
| 2697 |
|
| 2698 |
/** |
| 2699 |
* Log member data delete. |
| 2700 |
* |
| 2701 |
* @param array $res Result. |
| 2702 |
* @param int $mem_id Member ID. |
| 2703 |
* @return void |
| 2704 |
*/ |
| 2705 |
function wel_member_data_delete_log( $res, $mem_id ) { |
| 2706 |
usces_log( 'Res: ' . print_r( $res, true ) . ' $_POST: ' . print_r( $_POST, true ) . ' $_GET: ' . print_r( $_GET, true ), 'db', 'member_delete', $mem_id ); |
| 2707 |
} |
| 2708 |
|