Skip to content

Instantly share code, notes, and snippets.

@territutich
Created December 17, 2015 23:15
Show Gist options
  • Save territutich/525d765d24d3a7af9375 to your computer and use it in GitHub Desktop.
Save territutich/525d765d24d3a7af9375 to your computer and use it in GitHub Desktop.
portion of code to create GF coupons based on user registration
function bto_create_builder_coupon($user_id) { // need to pass user data to this function
if( is_callable( 'gf_coupons' ) ) {
$user = get_user_by( 'id', $user_id );
//$meta['gravityForm'] = $form_id ? $form_id : 0;
$form_id = '16'; // would like this to be 0. Have tried 0, '0', and specific form id. Nothing is working properly.
$meta['couponName'] = $user->user_login . date('M d, Y');
//$coupon_code = substr($user->user_firstname,0, 1) . substr($user->user_lastname, 0, 3) . date('ymd');
$meta['couponCode'] = strtoupper($user->user_login . date('ymd'));
$meta['couponAmountType'] = 'percentage';
$meta['couponAmount'] = 100;
$meta['startDate'] = date('m/d/y');
$meta['endDate'] = false;
$meta['usageLimit'] = 10;
$meta['isStackable'] = false;
$meta['usageCount'] = 0;
gf_coupons()->insert_feed( $form_id, true, $meta );
} else {
GFCouponsData::update_feed( 0, $form_id, true, $meta );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment