Created
July 16, 2018 16:00
-
-
Save rezzz-dev/01c761bd2c909a5b7e3f2fe2bc9358f5 to your computer and use it in GitHub Desktop.
Restrict Content Pro Automated Discount Creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gre_rcp_discount_offer( $entry, $form ) { | |
$exp_date = date("Y-m-d", strtotime("+ 2 day")); | |
$code = substr(str_shuffle(MD5(microtime())), 0, 10); | |
$discount = new RCP_Discounts(); | |
$args = array( | |
'name' => 'Welcome Offer', | |
'description' => 'FL Sales OTO: '.$code, | |
'amount' => '30.00', | |
'status' => 'active', | |
'unit' => 'flat', | |
'code' => $code, | |
'expiration' => $exp_date, | |
'max_uses' => 1, | |
'use_count' => '0', | |
'subscription_id'=> 4, | |
); | |
$add = $discount->insert( $args ); | |
if ( is_wp_error( $add ) ) { | |
rcp_log( sprintf( 'Error creating new discount code: %s', $add->get_error_message() ) ); | |
wp_die( $add ); | |
} | |
if ( $add ) { | |
$_POST['input_10'] = $code; | |
rcp_log( sprintf( 'Successfully added discount #%d.', $add ) ); | |
} else { | |
rcp_log( 'Error inserting new discount code into the database.' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment