0

Anyone can say how to provide ubercart discount coupons only for applicable users and not for the other users ?. For example if a user from texas, then the admin can provide a coupon code only for that texas user and it should not applicable for other out of texas users . please reply ASAP if anyone knows . thanks.

  • how are you determining that the user is from texas? based on their account information or their ip address? – schnippy Feb 20 '13 at 15:41
  • Hi schnippy thanks for your reply ,Actually the users can enter the credentials only at the time of checkout after adding the product to cart.They choose or select the country list in checkout page. – Dhinesh.ES Feb 21 '13 at 5:33
  • got it - so its not a question of when to display the coupon (which is how I would understand providing a coupon code) but more how do you validate it on the backend after they have entered it? is this right? you're not asking how to display it just for specific users? – schnippy Feb 21 '13 at 18:43
  • Hi Schnippy thanks for your queries on this question , the validation process take over only by ubercart modules in backend, we are not doing any custom function on that section for coupon, Am not asking how to display it for specific user. Am asking how to provide it for specific users which are all those from texas. If the users out of texas should not be get benefit using that coupon. – Dhinesh.ES Feb 25 '13 at 7:08
0

What you are looking for is a custom hook_uc_validate_coupon function. Ubercart coupon module allows for custom hooks here:

// Invoke validation hook.
  foreach (module_implements('uc_coupon_validate') as $module) {
    $callback = $module . '_uc_coupon_validate';
    $result = $callback($coupon, $order, $account);

So in your site module you would need to define a new hook function that validates whether the order (or possibly the user object?) is using a billing address from Texas. Roughly, clone the existing validation function and add logic to check the order for your conditions.

function YOURMODULE_uc_coupon_validate($code, $order = NULL, $account = NULL) {

if ($order->billing_state != 'Texas') { // or however you want to handle this
   $coupon = new stdClass();
   $coupon->valid = FALSE;
   $coupon->message = t('This coupon code is only valid in Texas.');
   $coupon->title = t('Unknown');
   return $coupon;
}

.. rest of validation function

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.