| 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_ogp_meta(){ |
| 47 |
global $usces, $post; |
| 48 |
if( empty($post) || !$usces->is_item($post) || !is_single() ) |
| 49 |
return; |
| 50 |
|
| 51 |
$item = $usces->get_item( $post->ID ); |
| 52 |
$pictid = $usces->get_mainpictid($item['itemCode']); |
| 53 |
$image_info = wp_get_attachment_image_src( $pictid, 'thumbnail' ); |
| 54 |
|
| 55 |
$ogs['title'] = $item['itemName']; |
| 56 |
$ogs['type'] = 'product'; |
| 57 |
$ogs['description'] = strip_tags( get_the_title($post->ID) ); |
| 58 |
$ogs['url'] = get_permalink($post->ID); |
| 59 |
$ogs['image'] = $image_info[0]; |
| 60 |
$ogs['site_name'] = get_option('blogname'); |
| 61 |
$ogs = apply_filters( 'usces_filter_ogp_meta', $ogs, $post->ID ); |
| 62 |
|
| 63 |
foreach( $ogs as $key => $value ){ |
| 64 |
echo "\n" . '<meta property="og:' . $key . '" content="' . $value . '">'; |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
function wc_purchase_nonce($html, $payments, $acting_flag, $rand, $purchase_disabled){ |
| 70 |
if( strpos($html, 'wc_nonce') || !in_array( $payments['settlement'], array('COD', 'installment', 'transferAdvance', 'transferDeferred', 'acting_zeus_card')) ) |
| 71 |
return $html; |
| 72 |
$wc_nonce = wp_create_nonce('wc_purchase_nonce'); |
| 73 |
$html .= wp_nonce_field( 'wc_purchase_nonce', 'wc_nonce', false, false )."\n"; |
| 74 |
return $html; |
| 75 |
} |
| 76 |
|
| 77 |
function wc_purchase_nonce_check(){ |
| 78 |
global $usces; |
| 79 |
$entry = $usces->cart->get_entry(); |
| 80 |
if( !isset($entry['order']['payment_name']) || empty($entry['order']['payment_name']) ){ |
| 81 |
wp_redirect( home_url() ); |
| 82 |
exit; |
| 83 |
} |
| 84 |
|
| 85 |
$payments = usces_get_payments_by_name($entry['order']['payment_name']); |
| 86 |
if( !in_array( $payments['settlement'], array('COD', 'installment', 'transferAdvance', 'transferDeferred', 'acting_zeus_card')) ) |
| 87 |
return true; |
| 88 |
|
| 89 |
$nonce = isset($_REQUEST['wc_nonce']) ? $_REQUEST['wc_nonce'] : ''; |
| 90 |
if( wp_verify_nonce($nonce, 'wc_purchase_nonce') ) |
| 91 |
return true; |
| 92 |
|
| 93 |
wp_redirect( home_url() ); |
| 94 |
exit; |
| 95 |
} |
| 96 |
|
| 97 |
?> |