Hello
I just purchased business version, looking for extra restriction over coupons.
Is it possible to create one coupon that any user can use a predefine time, and mostly only once ?
I try this code below, but it comes to conflict with the coupon removal process.
I'm sure you'll be able to implement this very easely :
function check_coupon(){
// restricted usage numbers
$user=&JFactory::getUser();
$db =& JFactory::getDBO();
$coupon = JRequest::getString('coupon','');
if(!empty($coupon)){
$db->setQuery("SELECT COUNT(order_id) FROM #__hikashop_order AS o".
" LEFT JOIN #__hikashop_user AS u ON o.order_user_id=u.user_id".
" WHERE u.user_cms_id=".$user->id.
" AND o.order_discount_code='".$coupon."'"
);
$already = $db->loadResult();
// the number 1 below might be replaced with a parameter from the backend
if ($already>1){
$app =& JFactory::getApplication();
$app->enqueueMessage(JText::_('COUPON_ALLREADY_USED'));
return false;
} else {
return true ;
}
} else {
return true;
}
}