Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $order = new WC_Order( $order_id );
- $order_total_amount = $order->get_formatted_order_total();
- $items = $order->get_items();
- foreach ( $items as $item ) {
- $product_name= $item['name'];
- $product_id= $item['product_id'];
- }
- $_product = wc_get_product( $product_id );
- $product_regular_price = $_product->get_regular_price();
- $order_data = $order->get_data();
- $order_date_created = $order_data['date_created'];
- $order_o_total = $order_data['total'];
- $order_discount_total = $order_data['discount_total'];
- $order_total_tax = $order_data['total_tax'];
- if($order->status === 'completed' ) {
- if( $order->get_used_coupons() ) {
- foreach( $order->get_used_coupons() as $coupon) {
- $coupon_name = $coupon;
- /* get coupon's details */
- $coupon_post_obj = get_page_by_title($coupon, OBJECT, 'shop_coupon');
- $coupon_id = $coupon_post_obj->ID;
- $coupons_obj = new WC_Coupon($coupon_id); /* get coupon instance */
- $coupon_discount_amount = $coupons_obj->get_discount_amount();
- $sales_representative_name = get_post_meta( $coupon_id, 'sales_representative_name', true );
- $sales_representative_email_address = get_post_meta( $coupon_id, 'sales_representative_email_address', true );
- }
- $to = $sales_representative_email_address;
- $subject = 'New Order Completed Using Assigned Coupon Code';
- $headers = 'MIME-Version: 1.0' . "rn";
- $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
- $headers .= 'From: My Name <nanganstella@gmail.com>' . "rn";
- $message = '<html><body>';
- $message .= '<h1>A new order has been completed using assigned coupon code.<br/></h1>';
- $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
- $message .= '<tr><td><strong>Product</strong></td><td>'. $product_name .'</td></tr>';
- $message .= '<tr><td><strong>Coupons used</strong></td><td>'. $coupon_name .'</td></tr>';
- $message .= '<tr><td><strong>Date</strong></td><td>'. $order_date_created .'</td></tr>';
- $message .= '<tr><td><strong>Product Price</strong></td><td>'. $product_regular_price .'CFA</td></tr>';
- $message .= '<tr><td><strong>Order Discount </strong></td><td>'. $order_discount_total.'CFA</td></tr>';
- $message .= '<tr><td><strong>Order Tax</strong></td><td>'. $order_total_tax .'</td></tr>';
- $message .= '<tr><td><strong>Order Amount</strong></td><td>'. $order_total_amount .'</td></tr>';
- $message .= '</table>';
- $message .= '</body></html>';
- wp_mail( $to, $subject, $message, $headers );
- }
- }
Add Comment
Please, Sign In to add comment