Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function mem_250( $order_id )
- {
- $order = new WC_Order($order_id);
- $user_id = $order->user_id;
- $wpf = WP_Fusion();
- $tags = array(921);
- $total = $order->get_subtotal();
- if ($total <= 0) {
- $wpf->user->apply_tags($tags, $user_id);
- }
- if ($total <= 0) {
- $prefix = 'ip';// Prefix Code
- $suffix = 'memday'; // Suffix Code
- $random = substr(uniqid('', true), -10);
- $coupon_code = $prefix . $random . $suffix; // Code
- $amount = '10'; // Amount
- $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
- $yearly_expiry = date('Y-m-d', strtotime('+1 year'));
- $customer_email = $order->billing_email;
- update_user_meta( $user_id, 'inpower_coupon', $coupon_code);
- $coupon = array(
- 'post_title' => $coupon_code,
- 'post_content' => '',
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_type' => 'shop_coupon'
- );
- $new_coupon_id = wp_insert_post($coupon);
- // Add meta
- update_post_meta($new_coupon_id, 'discount_type', $discount_type);
- update_post_meta($new_coupon_id, 'coupon_amount', $amount);
- update_post_meta($new_coupon_id, 'individual_use', 'no');
- update_post_meta($new_coupon_id, 'product_categories', '8');
- update_post_meta($new_coupon_id, 'exclude_product_ids', '');
- update_post_meta($new_coupon_id, 'usage_limit', '');
- update_post_meta($new_coupon_id, 'expiry_date', $yearly_expiry);
- update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
- update_post_meta($new_coupon_id, 'free_shipping', 'no');
- update_post_meta($new_coupon_id, 'customer_email', $customer_email);
- }
- if ($total <=0) {
- $prefix = 'sf'; // Prefix Code
- $suffix = 'memday'; // Suffix Code
- $random = substr(uniqid('', true), -10);
- $coupon_code = $prefix . $random . $suffix; // Code
- $amount = '10'; // Amount
- $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
- $yearly_expiry = date('Y-m-d', strtotime('+1 year'));
- $customer_email = $order->billing_email;
- update_user_meta( $user_id, 'skinnyfat_coupon', $coupon_code);
- $coupon = array(
- 'post_title' => $coupon_code,
- 'post_content' => '',
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_type' => 'shop_coupon'
- );
- $new_coupon_id = wp_insert_post($coupon);
- // Add meta
- update_post_meta($new_coupon_id, 'discount_type', $discount_type);
- update_post_meta($new_coupon_id, 'coupon_amount', $amount);
- update_post_meta($new_coupon_id, 'individual_use', 'no');
- update_post_meta($new_coupon_id, 'product_categories', '7');
- update_post_meta($new_coupon_id, 'exclude_product_ids', '');
- update_post_meta($new_coupon_id, 'usage_limit', '');
- update_post_meta($new_coupon_id, 'expiry_date', $yearly_expiry);
- update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
- update_post_meta($new_coupon_id, 'free_shipping', 'no');
- update_post_meta($new_coupon_id, 'customer_email', $customer_email);
- }
- if ($total <=0) {
- $prefix = 'nut'; // Prefix Code
- $suffix = 'memday'; // Suffix Code
- $random = substr(uniqid('', true), -10);
- $coupon_code = $prefix . $random . $suffix; // Code
- $amount = '10'; // Amount
- $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
- $yearly_expiry = date('Y-m-d', strtotime('+1 year'));
- $customer_email = $order->billing_email;
- update_user_meta( $user_id, 'nutreince_coupon', $coupon_code);
- $coupon = array(
- 'post_title' => $coupon_code,
- 'post_content' => '',
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_type' => 'shop_coupon'
- );
- $new_coupon_id = wp_insert_post($coupon);
- // Add meta
- update_post_meta($new_coupon_id, 'discount_type', $discount_type);
- update_post_meta($new_coupon_id, 'coupon_amount', $amount);
- update_post_meta($new_coupon_id, 'individual_use', 'no');
- update_post_meta($new_coupon_id, 'product_categories', '7');
- update_post_meta($new_coupon_id, 'exclude_product_ids', '');
- update_post_meta($new_coupon_id, 'usage_limit', '');
- update_post_meta($new_coupon_id, 'expiry_date', $yearly_expiry);
- update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
- update_post_meta($new_coupon_id, 'free_shipping', 'no');
- update_post_meta($new_coupon_id, 'customer_email', $customer_email);
- }
- }
- add_action( 'woocommerce_thankyou', 'mem_250' );
- add_action( 'show_user_profile', 'add_memorial_day_coupons' );
- add_action( 'edit_user_profile', 'add_memorial_day_coupons' );
- function add_memorial_day_coupons( $user )
- {
- ?>
- <h3>Memorial Day Coupons</h3>
- <table class="form-table">
- <tr>
- <th><label for="nutreince_coupon">Nutreince Coupon</label></th>
- <td><input type="text" name="nutreince_coupon" value="<?php echo esc_attr(get_the_author_meta( 'nutreince_coupon', $user->ID )); ?>" class="regular-text" /></td>
- </tr>
- <tr>
- <th><label for="skinnyfat_coupon">SkinnyFat Coupon</label></th>
- <td><input type="text" name="skinnyfat_coupon" value="<?php echo esc_attr(get_the_author_meta( 'skinnyfat_coupon', $user->ID )); ?>" class="regular-text" /></td>
- </tr>
- <tr>
- <th><label for="inpower_coupon">InPower Coupon</label></th>
- <td><input type="text" name="inpower_coupon" value="<?php echo esc_attr(get_the_author_meta( 'inpower_coupon', $user->ID )); ?>" class="regular-text" /></td>
- </tr>
- </table>
- <?php
- }
- add_action( 'personal_options_update', 'save_memorial_day_coupons' );
- add_action( 'edit_user_profile_update', 'save_memorial_day_coupons' );
- function save_memorial_day_coupons( $user_id )
- {
- update_user_meta( $user_id,'nutreince_coupon', sanitize_text_field( $_POST['nutreince_coupon'] ) );
- update_user_meta( $user_id,'skinnyfat_coupon', sanitize_text_field( $_POST['skinnyfat_coupon'] ) );
- update_user_meta( $user_id,'inpower_coupon', sanitize_text_field( $_POST['inpower_coupon'] ) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement