Skip to content

Instantly share code, notes, and snippets.

@rezzz-dev
Created July 16, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezzz-dev/01c761bd2c909a5b7e3f2fe2bc9358f5 to your computer and use it in GitHub Desktop.
Save rezzz-dev/01c761bd2c909a5b7e3f2fe2bc9358f5 to your computer and use it in GitHub Desktop.
Restrict Content Pro Automated Discount Creation
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