Hello, under a certain condition, I need to have a coupon added automatically to an order, at the checkout form, or preferably reflected in the cart if that is possible. Tried a few things but having no luck. Is there any documentation, or a quick and easy description of how this is done? thank you.

Comments

bob.hinrichs’s picture

Would this be the best method?

function my_module_checkout_pane() {
  $panes[] = array(
    'id' => 'team_coupon',
    'callback' => 'my_module_pane_coupon',
    'title' => t(' Special Discount'),
    'desc' => t(''),
    'weight' => 5,
    'process' => TRUE,
  );
  return $panes;
}

 function my_module_pane_coupon($op, &$arg1, $arg2) {
	 switch ($op) {
	 	case 'view':
	 		if ($codeinfo = validate_session_code()){
				$arg1->data['coupon'] = $codeinfo->code;
	 			uc_checkout_pane_coupon('view', $arg1, $arg2);
	 		}
	 	break;
	 }
}
longwave’s picture

Status: Active » Fixed

If you use 6.x-1.x-dev, the code has been refactored a little, which makes this easier:


$coupon = uc_coupon_validate($code);
if ($coupon->valid) {
  _uc_coupon_apply_to_order($order_id, $coupon);
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.