Advertisement
Guest User

Untitled

a guest
May 25th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.47 KB | None | 0 0
  1. <?php
  2.  
  3. function mem_250( $order_id )
  4. {
  5.     $order = new WC_Order($order_id);
  6.     $user_id = $order->user_id;
  7.     $wpf = WP_Fusion();
  8.     $tags = array(921);
  9.     $total = $order->get_subtotal();
  10.  
  11.     if ($total <= 0) {
  12.         $wpf->user->apply_tags($tags, $user_id);
  13.     }
  14.     if ($total <= 0) {
  15.         $prefix = 'ip';// Prefix Code
  16.         $suffix = 'memday';  // Suffix Code
  17.         $random = substr(uniqid('', true), -10);
  18.         $coupon_code = $prefix . $random . $suffix; // Code
  19.         $amount = '10'; // Amount
  20.         $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
  21.         $yearly_expiry = date('Y-m-d', strtotime('+1 year'));
  22.         $customer_email = $order->billing_email;
  23.         update_user_meta( $user_id, 'inpower_coupon', $coupon_code);
  24.  
  25.         $coupon = array(
  26.             'post_title' => $coupon_code,
  27.             'post_content' => '',
  28.             'post_status' => 'publish',
  29.             'post_author' => 1,
  30.             'post_type' => 'shop_coupon'
  31.         );
  32.  
  33.         $new_coupon_id = wp_insert_post($coupon);
  34.  
  35. // Add meta
  36.         update_post_meta($new_coupon_id, 'discount_type', $discount_type);
  37.         update_post_meta($new_coupon_id, 'coupon_amount', $amount);
  38.         update_post_meta($new_coupon_id, 'individual_use', 'no');
  39.         update_post_meta($new_coupon_id, 'product_categories', '8');
  40.         update_post_meta($new_coupon_id, 'exclude_product_ids', '');
  41.         update_post_meta($new_coupon_id, 'usage_limit', '');
  42.         update_post_meta($new_coupon_id, 'expiry_date', $yearly_expiry);
  43.         update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
  44.         update_post_meta($new_coupon_id, 'free_shipping', 'no');
  45.         update_post_meta($new_coupon_id, 'customer_email', $customer_email);
  46.     }
  47.     if ($total <=0) {
  48.         $prefix = 'sf'; // Prefix Code
  49.         $suffix = 'memday';  // Suffix Code
  50.         $random = substr(uniqid('', true), -10);
  51.         $coupon_code = $prefix . $random . $suffix; // Code
  52.         $amount = '10'; // Amount
  53.         $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
  54.         $yearly_expiry = date('Y-m-d', strtotime('+1 year'));
  55.         $customer_email = $order->billing_email;
  56.         update_user_meta( $user_id, 'skinnyfat_coupon', $coupon_code);
  57.  
  58.         $coupon = array(
  59.             'post_title' => $coupon_code,
  60.             'post_content' => '',
  61.             'post_status' => 'publish',
  62.             'post_author' => 1,
  63.             'post_type' => 'shop_coupon'
  64.         );
  65.  
  66.         $new_coupon_id = wp_insert_post($coupon);
  67.  
  68. // Add meta
  69.         update_post_meta($new_coupon_id, 'discount_type', $discount_type);
  70.         update_post_meta($new_coupon_id, 'coupon_amount', $amount);
  71.         update_post_meta($new_coupon_id, 'individual_use', 'no');
  72.         update_post_meta($new_coupon_id, 'product_categories', '7');
  73.         update_post_meta($new_coupon_id, 'exclude_product_ids', '');
  74.         update_post_meta($new_coupon_id, 'usage_limit', '');
  75.         update_post_meta($new_coupon_id, 'expiry_date', $yearly_expiry);
  76.         update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
  77.         update_post_meta($new_coupon_id, 'free_shipping', 'no');
  78.         update_post_meta($new_coupon_id, 'customer_email', $customer_email);
  79.     }
  80.     if ($total <=0) {
  81.         $prefix = 'nut'; // Prefix Code
  82.         $suffix = 'memday';  // Suffix Code
  83.         $random = substr(uniqid('', true), -10);
  84.         $coupon_code = $prefix . $random . $suffix; // Code
  85.         $amount = '10'; // Amount
  86.         $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
  87.         $yearly_expiry = date('Y-m-d', strtotime('+1 year'));
  88.         $customer_email = $order->billing_email;
  89.         update_user_meta( $user_id, 'nutreince_coupon', $coupon_code);
  90.  
  91.         $coupon = array(
  92.             'post_title' => $coupon_code,
  93.             'post_content' => '',
  94.             'post_status' => 'publish',
  95.             'post_author' => 1,
  96.             'post_type' => 'shop_coupon'
  97.         );
  98.  
  99.         $new_coupon_id = wp_insert_post($coupon);
  100.  
  101. // Add meta
  102.         update_post_meta($new_coupon_id, 'discount_type', $discount_type);
  103.         update_post_meta($new_coupon_id, 'coupon_amount', $amount);
  104.         update_post_meta($new_coupon_id, 'individual_use', 'no');
  105.         update_post_meta($new_coupon_id, 'product_categories', '7');
  106.         update_post_meta($new_coupon_id, 'exclude_product_ids', '');
  107.         update_post_meta($new_coupon_id, 'usage_limit', '');
  108.         update_post_meta($new_coupon_id, 'expiry_date', $yearly_expiry);
  109.         update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
  110.         update_post_meta($new_coupon_id, 'free_shipping', 'no');
  111.         update_post_meta($new_coupon_id, 'customer_email', $customer_email);
  112.     }
  113. }
  114. add_action( 'woocommerce_thankyou', 'mem_250' );
  115.  
  116. add_action( 'show_user_profile', 'add_memorial_day_coupons' );
  117. add_action( 'edit_user_profile', 'add_memorial_day_coupons' );
  118.  
  119. function add_memorial_day_coupons( $user )
  120. {
  121.     ?>
  122.     <h3>Memorial Day Coupons</h3>
  123.  
  124.     <table class="form-table">
  125.         <tr>
  126.             <th><label for="nutreince_coupon">Nutreince Coupon</label></th>
  127.             <td><input type="text" name="nutreince_coupon" value="<?php echo esc_attr(get_the_author_meta( 'nutreince_coupon', $user->ID )); ?>" class="regular-text" /></td>
  128.         </tr>
  129.  
  130.         <tr>
  131.             <th><label for="skinnyfat_coupon">SkinnyFat Coupon</label></th>
  132.             <td><input type="text" name="skinnyfat_coupon" value="<?php echo esc_attr(get_the_author_meta( 'skinnyfat_coupon', $user->ID )); ?>" class="regular-text" /></td>
  133.         </tr>
  134.  
  135.         <tr>
  136.             <th><label for="inpower_coupon">InPower Coupon</label></th>
  137.             <td><input type="text" name="inpower_coupon" value="<?php echo esc_attr(get_the_author_meta( 'inpower_coupon', $user->ID )); ?>" class="regular-text" /></td>
  138.         </tr>
  139.     </table>
  140.     <?php
  141. }
  142.  
  143. add_action( 'personal_options_update', 'save_memorial_day_coupons' );
  144. add_action( 'edit_user_profile_update', 'save_memorial_day_coupons' );
  145.  
  146. function save_memorial_day_coupons( $user_id )
  147. {
  148.     update_user_meta( $user_id,'nutreince_coupon', sanitize_text_field( $_POST['nutreince_coupon'] ) );
  149.     update_user_meta( $user_id,'skinnyfat_coupon', sanitize_text_field( $_POST['skinnyfat_coupon'] ) );
  150.     update_user_meta( $user_id,'inpower_coupon', sanitize_text_field( $_POST['inpower_coupon'] ) );
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement