안녕하세요 !
이전에 컨텐츠몰스킨의 중복결제 되는 부분에 대해 문의드렸었는데요.
- https://www.cosmosfarm.com/threads/document/47941
해당 스레드에서 답변주신
kboard_first_contents_mall_is_downloadable 필터를 사용하려고 history.php에서 사용된 방식과 해당 필터를 참고하여 아래와 같이 퍼스트콘텐츠몰 스킨의 document.php에 임의로 다운로드가 가능할때만 버튼이 활성화되도록 해보았으나 적용이 되지 않습니다..
<form method="post" action="<?php echo $url->set('uid', $content->uid)->set('mod', 'order')->toString()?>">
<input type="hidden" name="<?php echo $order->getItemFieldName($content->uid, 'uid')?>" value="<?php echo $content->uid?>">
<input type="hidden" name="<?php echo $order->getItemFieldName($content->uid, 'title')?>" value="<?php echo $content->title?>">
<input type="hidden" name="<?php echo $order->getItemFieldName($content->uid, 'price')?>" value="<?php echo floatval($content->option->price)?>">
<?php if(kboard_first_contents_mall_is_use_point_order($board) && $content->option->reward_point):?>
<input type="hidden" name="<?php echo $order->getItemFieldName($content->uid, 'reward_point')?>" value="<?php echo floatval($content->option->reward_point)?>">
<?php endif?>
<input type="hidden" name="<?php echo $order->getItemFieldName($content->uid, 'quantity')?>" value="1">
<h1><?php echo $content->title?></h1>
<div class="image-gallery-wrap mobile-gallery">
<?php if($media_list):?>
<div class="kboard-first-contents-mall-image-gallery">
<?php foreach($media_list as $media_item):?>
<div data-thumb="<?php echo kboard_resize($media_item->file_path, 200, 200)?>" data-src="<?php echo site_url($media_item->file_path)?>">
<img src="<?php echo kboard_resize($media_item->file_path, 600, 338)?>" alt="<?php echo esc_attr(basename($media_item->file_name))?>">
</div>
<?php endforeach?>
</div>
<?php endif?>
</div>
<dl class="detail-group">
<?php if($content->category1 || $content->category2):?>
<dt><?php echo __('Category', 'kboard')?></dt>
<dd>
<?php echo implode(', ', $content->getCategoryValues('<span>%s</span>'))?>
</dd>
<?php endif?>
<dt><?php echo __('Seller', 'kboard')?></dt>
<dd><?php echo apply_filters('kboard_user_display', $content->member_display, $content->member_uid, $content->member_display, 'kboard', $boardBuilder)?></dd>
<dt><?php echo __('Period of use', 'kboard')?></dt>
<dd><?php echo kboard_first_contents_mall_period_display($content->option->download_expiry)?></dd>
<dt><?php echo __('Last updated', 'kboard')?></dt>
<dd><?php echo date('Y-m-d', strtotime($content->update))?></dd>
<?php if($content->option->price):?>
<?php if($content->option->list_price):?>
<dt><?php echo __('List price', 'kboard')?></dt>
<dd class="list-price"><?php echo $board->currency($content->option->list_price)?></dd>
<?php endif?>
<dt><?php echo __('Price', 'kboard')?></dt>
<dd class="price">
<em><span id="amount-display"><?php echo $board->currency($content->option->price)?></span></em>
</dd>
<?php if(kboard_first_contents_mall_is_use_point_order($board) && $content->option->reward_point):?>
<dt><?php echo __('Reward point', 'kboard')?></dt>
<dd class="reward-point"><?php echo $board->currency($content->option->reward_point)?></dd>
<?php endif?>
<?php else:?>
<dt><?php echo __('Price', 'kboard')?></dt>
<dd class="price">
<em><span id="amount-display"><?php echo __('For free', 'kboard')?></span></em>
</dd>
<?php endif?>
</dl>
<hr>
<div class="kboard-document-detail-button">
<?php if(kboard_first_contents_mall_is_downloadable()):?>
<?php if($content->isAttached()):?>
<?php foreach($content->attach as $key=>$attach):?>
<button type="button" class="kboard-first-contents-mall-button-action" onclick="window.location.href='<?php echo $url->getDownloadURLWithAttach($content->uid, $key)?>'" title="<?php echo sprintf(__('Download %s', 'kboard'), $attach[1])?>"><i class="fas fa-download"></i> <?php echo $attach[1]?></button>
<?php endforeach?>
<?php endif?>
<?php elseif($board->isOrder()):?>
<?php if(kboard_first_contents_mall_is_current_user_order($board)):?>
<?php if(kboard_first_contents_mall_is_downloadable($item->order_item_id)):?>
<button type="submit" class="kboard-first-contents-mall-button-order"><?php echo __('Buy It Now', 'kboard')?></button>
<?php endif ?>
<?php else:?>
<a href="<?php echo wp_login_url($_SERVER['REQUEST_URI'])?>" class="kboard-first-contents-mall-button-order" onclick="return confirm('구매하기 위해서는 먼저 로그인해야 합니다. 로그인 페이지로 이동할까요?');"><?php echo __('Buy It Now', 'kboard')?></a>
<?php endif?>
<?php else:?>
<?php echo __('Sold Out', 'kboard')?>
<?php endif?>
</div>
</form>
안녕하세요~^^
KBoard 퍼스트 콘텐츠몰 스킨 document.php 파일에서
현재 사용자가 해당 제품을 구매했는지 체크하는 예제 코드를 작성해봤습니다.
아래의 코드를 활용해보시겠어요?
function kboard_first_contents_mall_is_buy(){
global $wpdb;
$is_buy = false;
$user_id = get_current_user_id();
$uid = kboard_uid();
if($user_id && $uid){
$order_item_id = $wpdb->get_var("SELECT `b`.`meta_value` FROM `{$wpdb->prefix}kboard_order_item_meta` AS `a`
LEFT JOIN `{$wpdb->prefix}kboard_order_item_meta` AS `b`
ON `a`.`order_item_id`=`b`.`order_item_id`
WHERE `a`.`meta_key`='uid' AND `a`.`meta_value`='{$uid}' AND `b`.`meta_key`='order_user_id' AND `b`.`meta_value`='{$user_id}'");
if($order_item_id){
$is_buy = true;
}
}
return $is_buy;
}
테마의 functions.php 파일에 코드를 추가하거나 Code Snippets 플러그인을 사용해서 코드를 추가할 수 있습니다.
document.php 파일에는 아래의 코드처럼 활용해서 사용하실 수 있습니다.
<?php
if(!kboard_first_contents_mall_is_buy()){
// 상품을 구매하지 않은 사용자에게만 실행됩니다.
}
else{
// 상품을 구매한 사용자에게만 실행됩니다.
}
?>
고맙습니다.