/** * Creates a random 15 digit giftcard number * */ function rf_create_number($data, $postarr) { if (isset($_POST['original_publish'])) { if ($data['post_type'] == 'mg_referfriend' && $_POST['original_publish'] == "Publish") { $myNumber = rf_generate_number(); $data['post_title'] = $myNumber; $data['post_name'] = $myNumber; } } return apply_filters('rf_create_number', $data); }
public function rf_create_coupon($order_id, $description, $type) { $order = new WC_Order($order_id); $invite_email = $order->billing_email; $title = rf_generate_number(); if ($description == 'Invite') { $rf_invite_coupon_amount = get_option('rf_invite_coupon_amount'); $rf_coupon_type = get_option('rf_invite_coupon_type'); } else { $rf_invite_coupon_amount = get_option('rf_reward_coupon_amount'); $rf_coupon_type = get_option('rf_reward_coupon_type'); } $rf_id = base64_decode($_COOKIE['utm']); $user = get_user_by('id', $rf_id); $post = array('post_title' => $title, 'post_status' => 'publish', 'post_type' => 'mg_referfriend'); $post_id = wp_insert_post($post); add_post_meta($post_id, 'rf_coupon_type', $rf_coupon_type); add_post_meta($post_id, 'rf_coupon_amount', $rf_invite_coupon_amount); add_post_meta($post_id, 'rf_description', $description); add_post_meta($post_id, 'rf_usage', 0); add_post_meta($post_id, 'rf_limit', 1); add_post_meta($post_id, 'rf_type', $type); if ($description == 'Invite') { add_post_meta($post_id, 'rf_invite_email', $invite_email); add_post_meta($post_id, 'rf_reward_email', $user->user_email); } $coupon_code = $title; // Code $amount = get_option('rf_coupon_amount', 1000); // Amount $coupon = array('post_title' => $title, 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'shop_coupon'); $new_coupon_id = wp_insert_post($coupon); update_post_meta($new_coupon_id, 'coupon_amount', $rf_invite_coupon_amount); update_post_meta($new_coupon_id, 'discount_type', $rf_coupon_type); update_post_meta($new_coupon_id, 'product_ids', ''); update_post_meta($new_coupon_id, 'exclude_product_ids', ''); update_post_meta($new_coupon_id, 'usage_count', '0'); update_post_meta($new_coupon_id, 'usage_limit', '1'); update_post_meta($new_coupon_id, 'expiry_date', ''); update_post_meta($new_coupon_id, 'apply_before_tax', 'yes'); update_post_meta($new_coupon_id, 'free_shipping', 'no'); if ($description == 'Invite') { update_post_meta($new_coupon_id, 'individual_use', get_option('rf_invite_individual_use')); } else { update_post_meta($new_coupon_id, 'individual_use', get_option('rf_reward_individual_use')); } return $post_id; }