| 1 |
<?php |
| 2 |
function usces_filter_get_post_metadata( $null, $object_id, $meta_key, $single){ |
| 3 |
global $wpdb; |
| 4 |
$query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $object_id, $meta_key); |
| 5 |
$metas = $wpdb->get_col($query); |
| 6 |
if ( !empty($metas) ) { |
| 7 |
return array_map('maybe_unserialize', $metas); |
| 8 |
} |
| 9 |
|
| 10 |
if ($single) |
| 11 |
return ''; |
| 12 |
else |
| 13 |
return array(); |
| 14 |
} |
| 15 |
|
| 16 |
function usces_action_reg_orderdata( $args ){ |
| 17 |
global $wpdb, $usces; |
| 18 |
$options = get_option('usces'); |
| 19 |
extract($args); |
| 20 |
|
| 21 |
/* Register decorated order id ***************************************************/ |
| 22 |
$olimit = 0; |
| 23 |
if( ! $options['system']['dec_orderID_flag'] ){ |
| 24 |
$dec_order_id = str_pad($order_id, $options['system']['dec_orderID_digit'], "0", STR_PAD_LEFT); |
| 25 |
}else{ |
| 26 |
$otable = $wpdb->prefix . 'usces_order_meta'; |
| 27 |
while( $ukey = usces_get_key( $options['system']['dec_orderID_digit'] ) ){ |
| 28 |
$ores = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $otable WHERE meta_key = %s AND meta_value = %s LIMIT 1", 'dec_order_id', $ukey)); |
| 29 |
if( !$ores || 100 < $olimit ) |
| 30 |
break; |
| 31 |
$olimit++; |
| 32 |
} |
| 33 |
$dec_order_id = $ukey; |
| 34 |
} |
| 35 |
$dec_order_id = apply_filters( 'usces_filter_dec_order_id_prefix', $options['system']['dec_orderID_prefix'], $args ) . apply_filters( 'usces_filter_dec_order_id', $dec_order_id, $args ); |
| 36 |
|
| 37 |
if( 100 < $olimit ){ |
| 38 |
$usces->set_order_meta_value('dec_order_id', uniqid(), $order_id); |
| 39 |
}else{ |
| 40 |
$usces->set_order_meta_value('dec_order_id', $dec_order_id, $order_id); |
| 41 |
} |
| 42 |
unset($dec_order_id, $otable, $olimit, $ukey, $ores); |
| 43 |
/***********************************************************************************/ |
| 44 |
} |
| 45 |
|
| 46 |
function usces_action_reg_orderdata_stocks($args){ |
| 47 |
global $usces; |
| 48 |
extract($args); |
| 49 |
|
| 50 |
foreach($cart as $cartrow){ |
| 51 |
$sku = urldecode($cartrow['sku']); |
| 52 |
$zaikonum = $usces->getItemZaikoNum( $cartrow['post_id'], $sku ); |
| 53 |
if($zaikonum == '') continue; |
| 54 |
$zaikonum = $zaikonum - $cartrow['quantity']; |
| 55 |
$usces->updateItemZaikoNum( $cartrow['post_id'], $sku, $zaikonum ); |
| 56 |
if($zaikonum <= 0) $usces->updateItemZaiko( $cartrow['post_id'], $sku, 2 ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
function usces_action_ogp_meta(){ |
| 61 |
global $usces, $post; |
| 62 |
if( empty($post) || !$usces->is_item($post) || !is_single() ) |
| 63 |
return; |
| 64 |
|
| 65 |
$item = $usces->get_item( $post->ID ); |
| 66 |
$pictid = $usces->get_mainpictid($item['itemCode']); |
| 67 |
$image_info = wp_get_attachment_image_src( $pictid, 'thumbnail' ); |
| 68 |
|
| 69 |
$ogs['title'] = $item['itemName']; |
| 70 |
$ogs['type'] = 'product'; |
| 71 |
$ogs['description'] = strip_tags( get_the_title($post->ID) ); |
| 72 |
$ogs['url'] = get_permalink($post->ID); |
| 73 |
$ogs['image'] = $image_info[0]; |
| 74 |
$ogs['site_name'] = get_option('blogname'); |
| 75 |
$ogs = apply_filters( 'usces_filter_ogp_meta', $ogs, $post->ID ); |
| 76 |
|
| 77 |
foreach( $ogs as $key => $value ){ |
| 78 |
echo "\n" . '<meta property="og:' . $key . '" content="' . $value . '">'; |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
function wc_purchase_nonce($html, $payments, $acting_flag, $rand, $purchase_disabled){ |
| 84 |
if( strpos($html, 'wc_nonce') || !in_array( $payments['settlement'], array('COD', 'installment', 'transferAdvance', 'transferDeferred', 'acting_zeus_card')) ) |
| 85 |
return $html; |
| 86 |
$wc_nonce = wp_create_nonce('wc_purchase_nonce'); |
| 87 |
$html .= wp_nonce_field( 'wc_purchase_nonce', 'wc_nonce', false, false )."\n"; |
| 88 |
return $html; |
| 89 |
} |
| 90 |
|
| 91 |
function wc_purchase_nonce_check(){ |
| 92 |
global $usces; |
| 93 |
$entry = $usces->cart->get_entry(); |
| 94 |
if( !isset($entry['order']['payment_name']) || empty($entry['order']['payment_name']) ){ |
| 95 |
wp_redirect( home_url() ); |
| 96 |
exit; |
| 97 |
} |
| 98 |
|
| 99 |
$payments = usces_get_payments_by_name($entry['order']['payment_name']); |
| 100 |
if( !in_array( $payments['settlement'], array('COD', 'installment', 'transferAdvance', 'transferDeferred' )) ) |
| 101 |
return true; |
| 102 |
|
| 103 |
$nonce = isset($_REQUEST['wc_nonce']) ? $_REQUEST['wc_nonce'] : ''; |
| 104 |
if( wp_verify_nonce($nonce, 'wc_purchase_nonce') ) |
| 105 |
return true; |
| 106 |
|
| 107 |
wp_redirect( home_url() ); |
| 108 |
exit; |
| 109 |
} |
| 110 |
|
| 111 |
function wc_mkdir(){ |
| 112 |
global $usces; |
| 113 |
if( is_admin() && !WCUtils::is_blank($usces->options['logs_path']) && false !== strpos($_SERVER['SERVER_SOFTWARE'],'Apache')){ |
| 114 |
$welcart_file_dir = $usces->options['logs_path'] . '/welcart'; |
| 115 |
$logs_dir = $welcart_file_dir . '/logs'; |
| 116 |
if( !file_exists($welcart_file_dir) ){ |
| 117 |
$res = @mkdir($welcart_file_dir, 0700); |
| 118 |
if(!$res){ |
| 119 |
$msg = '<div class="error"><p>下記のディレクトリーを、所有� |
| 120 |
:' . get_current_user() . '、パーミッション:700 で作成してください。 <br />' . $welcart_file_dir . '</p></div>'; |
| 121 |
add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg,'"') . '";')); |
| 122 |
} |
| 123 |
} |
| 124 |
$stat = stat($welcart_file_dir); |
| 125 |
print_r($stat); |
| 126 |
die(); |
| 127 |
if( is_writable($welcart_file_dir) ){ |
| 128 |
$res = @mkdir($logs_dir, 0700); |
| 129 |
if(!$res){ |
| 130 |
$msg = '<div class="error"><p>下記のディレクトリーを、所有� |
| 131 |
:' . get_current_user() . '、パーミッション:700 で作成してください。 <br />' . $welcart_file_dir . '</p></div>'; |
| 132 |
add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg,'"') . '";')); |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
function fiter_mainTitle($title, $sep){ |
| 139 |
global $usces; |
| 140 |
|
| 141 |
if( empty($title) ){ |
| 142 |
$newtitle = $title; |
| 143 |
}else{ |
| 144 |
$title = trim( str_replace( $sep, '', $title ) ); |
| 145 |
switch($usces->page){ |
| 146 |
case 'cart': |
| 147 |
$newtitle = apply_filters('usces_filter_title_cart', __('In the cart', 'usces')); |
| 148 |
break; |
| 149 |
|
| 150 |
case 'customer': |
| 151 |
$newtitle = apply_filters('usces_filter_title_customer', __('Customer Information', 'usces')); |
| 152 |
break; |
| 153 |
|
| 154 |
case 'delivery': |
| 155 |
$newtitle = apply_filters('usces_filter_title_delivery', __('Shipping / Payment options', 'usces')); |
| 156 |
break; |
| 157 |
|
| 158 |
case 'confirm': |
| 159 |
$newtitle = apply_filters('usces_filter_title_confirm', __('Confirmation', 'usces')); |
| 160 |
break; |
| 161 |
|
| 162 |
case 'ordercompletion': |
| 163 |
$newtitle = apply_filters('usces_filter_title_ordercompletion', __('Order Complete', 'usces')); |
| 164 |
break; |
| 165 |
|
| 166 |
case 'error': |
| 167 |
$newtitle = apply_filters('usces_filter_title_error', __('Error', 'usces')); //new fitler name |
| 168 |
break; |
| 169 |
|
| 170 |
case 'search_item': |
| 171 |
$newtitle = apply_filters('usces_filter_title_search_item', __("'AND' search by categories", 'usces')); |
| 172 |
break; |
| 173 |
|
| 174 |
case 'maintenance': |
| 175 |
$newtitle = apply_filters('usces_filter_title_maintenance', __('Under Maintenance', 'usces')); |
| 176 |
break; |
| 177 |
|
| 178 |
case 'login': |
| 179 |
$newtitle = apply_filters('usces_filter_title_login', __('Log-in for members', 'usces')); |
| 180 |
break; |
| 181 |
|
| 182 |
case 'member': |
| 183 |
$newtitle = apply_filters('usces_filter_title_member', __('Membership information', 'usces')); |
| 184 |
break; |
| 185 |
|
| 186 |
case 'newmemberform': |
| 187 |
$newtitle = apply_filters('usces_filter_title_newmemberform', __('New enrollment form', 'usces')); |
| 188 |
break; |
| 189 |
|
| 190 |
case 'newcompletion': |
| 191 |
$newtitle = apply_filters('usces_filter_title_newcompletion', __('New enrollment complete', 'usces'));//new fitler name |
| 192 |
break; |
| 193 |
|
| 194 |
case 'editmemberform': |
| 195 |
$newtitle = apply_filters('usces_filter_title_editmemberform', __('Member information editing', 'usces'));//new fitler name |
| 196 |
break; |
| 197 |
|
| 198 |
case 'editcompletion': |
| 199 |
$newtitle = apply_filters('usces_filter_title_editcompletion', __('Membership information change is completed', 'usces'));//new fitler name |
| 200 |
break; |
| 201 |
|
| 202 |
case 'lostmemberpassword': |
| 203 |
$newtitle = apply_filters('usces_filter_title_lostmemberpassword', __('The new password acquisition', 'usces')); |
| 204 |
break; |
| 205 |
|
| 206 |
case 'lostcompletion': |
| 207 |
$newtitle = apply_filters('usces_filter_title_lostcompletion', __('New password procedures for obtaining complete', 'usces'));//new fitler name |
| 208 |
break; |
| 209 |
|
| 210 |
case 'changepassword': |
| 211 |
$newtitle = apply_filters('usces_filter_title_changepassword', __('Change password', 'usces')); |
| 212 |
break; |
| 213 |
|
| 214 |
case 'changepasscompletion': |
| 215 |
$newtitle = apply_filters('usces_filter_title_changepasscompletion', __('Password change is completed', 'usces')); |
| 216 |
break; |
| 217 |
|
| 218 |
default: |
| 219 |
$newtitle = apply_filters('usces_filter_title_main_default', $title);//new fitler name |
| 220 |
} |
| 221 |
$newtitle = $newtitle .' '.$sep.' '; |
| 222 |
} |
| 223 |
return $newtitle; |
| 224 |
} |
| 225 |
|
| 226 |
//Univarsal Analytics |
| 227 |
function usces_Universal_trackPageview(){ |
| 228 |
global $usces; |
| 229 |
|
| 230 |
switch($usces->page){ |
| 231 |
case 'cart': |
| 232 |
$push = array(); |
| 233 |
$push[] = "'page' : '/wc_cart'"; |
| 234 |
break; |
| 235 |
|
| 236 |
case 'customer': |
| 237 |
$push = array(); |
| 238 |
$push[] = "'page' : '/wc_customer'"; |
| 239 |
break; |
| 240 |
|
| 241 |
case 'delivery': |
| 242 |
$push = array(); |
| 243 |
$push[] = "'page' : '/wc_delivery'"; |
| 244 |
break; |
| 245 |
|
| 246 |
case 'confirm': |
| 247 |
$push = array(); |
| 248 |
$push[] = "'page' : '/wc_confirm'"; |
| 249 |
break; |
| 250 |
|
| 251 |
case 'ordercompletion': |
| 252 |
$sesdata = $usces->cart->get_entry(); |
| 253 |
$order_id = $sesdata['order']['ID']; |
| 254 |
$data = $usces->get_order_data($order_id, 'direct'); |
| 255 |
$cart = unserialize($data['order_cart']); |
| 256 |
$total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint']; |
| 257 |
$push =array(); |
| 258 |
$push[] = "'page' : '/wc_ordercompletion'"; |
| 259 |
$push[] = "'require', 'ecommerce', 'ecommerce.js'"; |
| 260 |
$push[] = "'ecommerce:addTransaction', { |
| 261 |
id: '". $order_id ."', |
| 262 |
affiliation: '". get_option('blogname') ."', |
| 263 |
revenue: '". $total_price ."', |
| 264 |
shipping: '". $data['order_shipping_charge'] ."', |
| 265 |
tax: '". $data['order_tax'] ."' }"; |
| 266 |
for( $i=0; $i<count($cart); $i++ ){ |
| 267 |
$cart_row = $cart[$i]; |
| 268 |
$post_id = $cart_row['post_id']; |
| 269 |
$sku = urldecode($cart_row['sku']); |
| 270 |
$quantity = $cart_row['quantity']; |
| 271 |
$itemName = $usces->getItemName($post_id); |
| 272 |
$skuPrice = $cart_row['price']; |
| 273 |
$cats = $usces->get_item_cat_genre_ids( $post_id ); |
| 274 |
if( is_array($cats) ) |
| 275 |
sort($cats); |
| 276 |
$category = ( isset($cats[0]) ) ? get_cat_name($cats[0]): ''; |
| 277 |
|
| 278 |
$push[] = "'ecommerce:addItem', { |
| 279 |
id: '". $order_id ."', |
| 280 |
sku: '". $sku ."', |
| 281 |
name: '". $itemName."', |
| 282 |
category: '". $category."', |
| 283 |
price: '". $skuPrice."', |
| 284 |
quantity: '". $quantity."' }"; |
| 285 |
} |
| 286 |
$push[] = "'ecommerce:send'"; |
| 287 |
break; |
| 288 |
|
| 289 |
case 'error': |
| 290 |
$push = array(); |
| 291 |
$push[] = "'page' : '/wc_error'"; |
| 292 |
break; |
| 293 |
|
| 294 |
case 'search_item': |
| 295 |
$push = array(); |
| 296 |
$push[] = "'page' : '/wc_search_item'"; |
| 297 |
break; |
| 298 |
|
| 299 |
case 'maintenance': |
| 300 |
$push = array(); |
| 301 |
$push[] = "'page' : '/wc_maintenance'"; |
| 302 |
break; |
| 303 |
|
| 304 |
case 'login': |
| 305 |
$push = array(); |
| 306 |
$push[] = "'page' : '/wc_login'"; |
| 307 |
break; |
| 308 |
|
| 309 |
case 'member': |
| 310 |
$push = array(); |
| 311 |
$push[] = "'page' : '/wc_member'"; |
| 312 |
break; |
| 313 |
|
| 314 |
case 'newmemberform': |
| 315 |
$push = array(); |
| 316 |
$push[] = "'page' : '/wc_newmemberform'"; |
| 317 |
break; |
| 318 |
|
| 319 |
case 'newcompletion': |
| 320 |
$push = array(); |
| 321 |
$push[] = "'page' : '/wc_newcompletion'"; |
| 322 |
break; |
| 323 |
|
| 324 |
case 'editmemberform': |
| 325 |
$push = array(); |
| 326 |
$push[] = "'page' : '/wc_editmemberform'"; |
| 327 |
break; |
| 328 |
|
| 329 |
case 'editcompletion': |
| 330 |
$push = array(); |
| 331 |
$push[] = "'page' : '/wc_editcompletion'"; |
| 332 |
break; |
| 333 |
|
| 334 |
case 'lostmemberpassword': |
| 335 |
$push = array(); |
| 336 |
$push[] = "'page' : '/wc_lostmemberpassword'"; |
| 337 |
break; |
| 338 |
|
| 339 |
case 'lostcompletion': |
| 340 |
$push = array(); |
| 341 |
$push[] = "'page' : '/wc_lostcompletion'"; |
| 342 |
break; |
| 343 |
|
| 344 |
case 'changepassword': |
| 345 |
$push = array(); |
| 346 |
$push[] = "'page' : '/wc_changepassword'"; |
| 347 |
break; |
| 348 |
|
| 349 |
case 'changepasscompletion': |
| 350 |
$push = array(); |
| 351 |
$push[] = "'page' : '/wc_changepasscompletion'"; |
| 352 |
break; |
| 353 |
|
| 354 |
default: |
| 355 |
$push = array(); |
| 356 |
break; |
| 357 |
} |
| 358 |
return $push; |
| 359 |
} |
| 360 |
|
| 361 |
//Classic Analytics |
| 362 |
function usces_Classic_trackPageview(){ |
| 363 |
global $usces; |
| 364 |
|
| 365 |
switch($usces->page){ |
| 366 |
case 'cart': |
| 367 |
$push = array(); |
| 368 |
$push = usces_trackPageview_cart($push); |
| 369 |
break; |
| 370 |
|
| 371 |
case 'customer': |
| 372 |
$push = array(); |
| 373 |
$push = usces_trackPageview_customer($push); |
| 374 |
break; |
| 375 |
|
| 376 |
case 'delivery': |
| 377 |
$push = array(); |
| 378 |
$push = usces_trackPageview_delivery($push); |
| 379 |
break; |
| 380 |
|
| 381 |
case 'confirm': |
| 382 |
$push = array(); |
| 383 |
$push = usces_trackPageview_confirm($push); |
| 384 |
break; |
| 385 |
|
| 386 |
case 'ordercompletion': |
| 387 |
$push =array(); |
| 388 |
$push = usces_trackPageview_ordercompletion($push); |
| 389 |
break; |
| 390 |
|
| 391 |
case 'error': |
| 392 |
$push = array(); |
| 393 |
$push = usces_trackPageview_error($push); |
| 394 |
break; |
| 395 |
|
| 396 |
case 'login': |
| 397 |
$push = array(); |
| 398 |
$push = usces_trackPageview_login($push); |
| 399 |
break; |
| 400 |
|
| 401 |
case 'member': |
| 402 |
$push = array(); |
| 403 |
$push = usces_trackPageview_member($push); |
| 404 |
break; |
| 405 |
|
| 406 |
case 'newmemberform': |
| 407 |
$push = array(); |
| 408 |
$push = usces_trackPageview_newmemberform($push); |
| 409 |
break; |
| 410 |
|
| 411 |
case 'newcompletion': |
| 412 |
$push = array(); |
| 413 |
$push = usces_trackPageview_newcompletion($push); |
| 414 |
break; |
| 415 |
|
| 416 |
case 'editmemberform': |
| 417 |
$push = array(); |
| 418 |
$push = usces_trackPageview_editmemberform($push); |
| 419 |
break; |
| 420 |
|
| 421 |
case 'search_item': |
| 422 |
$push = array(); |
| 423 |
$push = usces_trackPageview_search_item($push); |
| 424 |
break; |
| 425 |
|
| 426 |
case 'maintenance': |
| 427 |
case 'editcompletion': |
| 428 |
case 'lostmemberpassword': |
| 429 |
case 'lostcompletion': |
| 430 |
case 'changepassword': |
| 431 |
case 'changepasscompletion': |
| 432 |
default: |
| 433 |
$push = array(); |
| 434 |
break; |
| 435 |
} |
| 436 |
return $push; |
| 437 |
} |
| 438 |
|
| 439 |
?> |