Guest User

Untitled

a guest
Feb 21st, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. $order = new WC_Order( $order_id );
  2.  
  3. $order_total_amount = $order->get_formatted_order_total();
  4.  
  5. $items = $order->get_items();
  6.  
  7. foreach ( $items as $item ) {
  8. $product_name= $item['name'];
  9. $product_id= $item['product_id'];
  10.  
  11. }
  12.  
  13. $_product = wc_get_product( $product_id );
  14. $product_regular_price = $_product->get_regular_price();
  15.  
  16. $order_data = $order->get_data();
  17. $order_date_created = $order_data['date_created'];
  18. $order_o_total = $order_data['total'];
  19. $order_discount_total = $order_data['discount_total'];
  20. $order_total_tax = $order_data['total_tax'];
  21.  
  22. if($order->status === 'completed' ) {
  23.  
  24. if( $order->get_used_coupons() ) {
  25.  
  26. foreach( $order->get_used_coupons() as $coupon) {
  27.  
  28. $coupon_name = $coupon;
  29. /* get coupon's details */
  30. $coupon_post_obj = get_page_by_title($coupon, OBJECT, 'shop_coupon');
  31. $coupon_id = $coupon_post_obj->ID;
  32.  
  33. $coupons_obj = new WC_Coupon($coupon_id); /* get coupon instance */
  34.  
  35. $coupon_discount_amount = $coupons_obj->get_discount_amount();
  36. $sales_representative_name = get_post_meta( $coupon_id, 'sales_representative_name', true );
  37. $sales_representative_email_address = get_post_meta( $coupon_id, 'sales_representative_email_address', true );
  38. }
  39.  
  40. $to = $sales_representative_email_address;
  41. $subject = 'New Order Completed Using Assigned Coupon Code';
  42.  
  43. $headers = 'MIME-Version: 1.0' . "rn";
  44. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
  45. $headers .= 'From: My Name <nanganstella@gmail.com>' . "rn";
  46.  
  47. $message = '<html><body>';
  48. $message .= '<h1>A new order has been completed using assigned coupon code.<br/></h1>';
  49.  
  50. $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
  51.  
  52. $message .= '<tr><td><strong>Product</strong></td><td>'. $product_name .'</td></tr>';
  53.  
  54. $message .= '<tr><td><strong>Coupons used</strong></td><td>'. $coupon_name .'</td></tr>';
  55.  
  56. $message .= '<tr><td><strong>Date</strong></td><td>'. $order_date_created .'</td></tr>';
  57.  
  58. $message .= '<tr><td><strong>Product Price</strong></td><td>'. $product_regular_price .'CFA</td></tr>';
  59.  
  60. $message .= '<tr><td><strong>Order Discount </strong></td><td>'. $order_discount_total.'CFA</td></tr>';
  61.  
  62.  
  63. $message .= '<tr><td><strong>Order Tax</strong></td><td>'. $order_total_tax .'</td></tr>';
  64.  
  65. $message .= '<tr><td><strong>Order Amount</strong></td><td>'. $order_total_amount .'</td></tr>';
  66.  
  67.  
  68.  
  69. $message .= '</table>';
  70. $message .= '</body></html>';
  71.  
  72. wp_mail( $to, $subject, $message, $headers );
  73.  
  74. }
  75. }
Add Comment
Please, Sign In to add comment