Hook Before Coupon Code Is Validated

We have a need to be able to do some processing when a customer enters a coupon code into the cart or checkout coupon field. We want to actually insert a coupon into the promotion system based on the value they enter. I know that does not make sense, but we have a good reason for what we are doing. My problem is trying to find a hook function that allows me to insert a new promotion AND that promotion is usable based on the coupon code the customer entered.

So, for example, the customer enters a code that does not exist, say abc123. After they click the apply arrow I want to actually create a promotion on the fly for coupon code abc123. Then let the normal CS-Cart promotion validation process to see it and use it.

I have tried looking at many hooks mentioned in the documentation, like promotion_apply_pre, pre_promotion_validate, pre_promotion_check_coupon and promotion_check_coupon, but it seems that for all of these by the time the CS-Cart promotion validation process kicks in, it is working off a list of promotions from the database that were loaded BEFORE I could insert my special promotion.

I came across update_cart_by_data_post which I felt might be executed prior to loading the promotions from the database, but the hook never seems to be called, so I cannot confirm it works or not.

Can someone please guide me in the right direction as to which hook to use to accomplish what I am needing to do?

I am working with version 4.1.3.


Add code like

if( !defined('BOOTSTRAP') ) die('Access denied');
switch($mode) {
case 'apply_coupon':
$this_cert =& $_REQUEST['coupon_code'];
// put your code logic here

Thank you very much. That was exactly what I needed.

You're welcome.