Create a custom order status in the dropdown ‘shipped’ and mail on change status to shipped.
functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | function register_shipped_order_status() { register_post_status( 'wc-shipped', array( 'label' => 'Shipped', 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>' ) ) ); } add_action( 'init', 'register_shipped_order_status' ); add_filter( 'wc_order_statuses', 'custom_order_status'); function custom_order_status( $order_statuses ) { $order_statuses['wc-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' ); return $order_statuses; } //--Email on status change--> add_action("woocommerce_order_status_changed", "my_awesome_publication_notification"); function get_custom_email_html( $order, $heading = false, $mailer ) { $template = 'emails/customer-shipped-order.php'; return wc_get_template_html( $template, array( 'order' => $order, 'email_heading' => $heading, 'sent_to_admin' => false, 'plain_text' => false, 'email' => $mailer ) ); } function my_awesome_publication_notification($order_id, $checkout=null) { global $woocommerce; $order = new WC_Order( $order_id ); // Get the Customer ID (User ID) $customer_id = $order->get_customer_id(); // Or $order->get_user_id(); // Get the WP_User Object instance $user = $order->get_user(); // Get the WP_User roles and capabilities $user_roles = $user->roles; // Get the Customer billing email $billing_email = $order->get_billing_email(); // Get the Customer billing phone $billing_phone = $order->get_billing_phone(); // Customer billing information details $billing_first_name = $order->get_billing_first_name(); if($order->status === 'shipped' ) { // Create a mailer $mailer = $woocommerce->mailer(); //$message_body = __( 'Dear '.$billing_first_name.',<br> Your order shipped, <br>Please check ORDER TRACKING detail on your <a href="https://antesports.com/my-account/orders/">dashboard</a>' ); $subject = 'Order '.$order_id.' Shipped'; $message_body = get_custom_email_html($order,$subject,$mailer); /* $message = $mailer->wrap_message( // Message head and message body. sprintf( __( 'Order %s Shipped' ), $order->get_order_number() ), $message_body ); */ // Cliente email, email subject and message. $mailer->send( $order->billing_email, sprintf( __( 'Order %s Shipped' ), $order->get_order_number() ), $message_body ); } } //--Status button color --> add_action('admin_head', 'styling_admin_order_list' ); function styling_admin_order_list() { global $pagenow, $post; if( $pagenow != 'edit.php') return; // Exit if( get_post_type($post->ID) != 'shop_order' ) return; // Exit // HERE we set your custom status $order_status = 'Shipped'; // <==== HERE ?> <style> .order-status.status-<?php echo sanitize_title( $order_status ); ?> { background: #d7f8a7; color: #0c942b; } </style> <?php } |
Create a mail file ‘customer-shipped-order.php‘
/wp-content/themes/storefront/woocommerce/emails/customer-shipped-order.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | <?php /** * Customer completed order email * * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-order.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce\Templates\Emails * @version 3.7.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; } /* * @hooked WC_Emails::email_header() Output the email header */ do_action( 'woocommerce_email_header', $email_heading, $email ); ?> <?php /* translators: %s: Customer first name */ ?> <p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p> <p><?php esc_html_e( 'We have shipped your order.', 'woocommerce' ); ?></p> <?php /* * @hooked WC_Emails::order_details() Shows the order details table. * @hooked WC_Structured_Data::generate_order_data() Generates structured data. * @hooked WC_Structured_Data::output_structured_data() Outputs structured data. * @since 2.5.0 */ do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email ); /* * @hooked WC_Emails::order_meta() Shows order meta data. */ do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email ); /*=========================|Tracking Detail|==============================*/ $order_id = $order->get_order_number(); $order = wc_get_order( $order_id ); $shipping = $order->meta_data; $billing = json_decode($order); $billing_email = $billing->billing->email; $message = '<table style="width:100%;" border="1">'; foreach($shipping as $shippingVal){ if($shippingVal->key=="ywot_tracking_code"){ $message .= '<tr>'; $message .= '<td>Tracking Code : </td><td>'.$shippingVal->value.'</td>'; $message .= '</tr>'; } if($shippingVal->key=="ywot_pick_up_date"){ $message .= '<tr>'; $message .= '<td>Pickup Date : </td><td>'.$shippingVal->value.'</td>'; $message .= '</tr>'; } if($shippingVal->key=="ywot_carrier_name"){ $message .= '<tr>'; $message .= '<td>Courier Name : </td><td>'.$shippingVal->value.'</td>'; $message .= '</tr>'; } if($shippingVal->key=="ywot_carrier_url"){ $message .= '<tr>'; $message .= '<td>Tracking URL : </td><td><a href="'.$shippingVal->value.'" target="_blank">'.$shippingVal->value.'</a></td>'; $message .= '</tr>'; } } $message .= '</table>'; if(count($shipping) > 0){ echo'<strong>Tracking Detail:</strong>'.$message.'<br><br>'; } /*=========================|Tracking Detail Close|==============================*/ /* * @hooked WC_Emails::customer_details() Shows customer details * @hooked WC_Emails::email_address() Shows email address */ do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email ); /** * Show user-defined additional content - this is set in each email's settings. */ if ( $additional_content ) { echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) ); } /* * @hooked WC_Emails::email_footer() Output the email footer */ do_action( 'woocommerce_email_footer', $email ); |