Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@flymke
Last active February 16, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flymke/6c79f95c23462dba100134ef2955c84a to your computer and use it in GitHub Desktop.
Save flymke/6c79f95c23462dba100134ef2955c84a to your computer and use it in GitHub Desktop.
description
<?php
/**
* Script to send a WooCommerce tracking email to the client
* @author: Mike Schoenrock (ms@halloecho.de)
*/
// Load the WordPress Environment
// change that to where your wp-blog-header.php is located
require( dirname( __FILE__ ) . '../../../../../wp-blog-header.php' );
// Load the email class
require_once( 'class-email.php' );
// get the order from WooCommerce
$order_id = '12345'; // WooCommerce order_id
$order = new WC_Order($order_id);
$customer_name = $order->get_formatted_billing_full_name();
$customer_email = $order->billing_email;
// tracking number
$tracking_number = '123456789';
// generate and send email
$email = new Tracking_Email();
$body = $email->generate_message($tracking_number, $customer_name);
$content = $email->wrap_message('Your tracking number', $body, ''); // see https://docs.woocommerce.com/wc-apidocs/class-WC_Email.html
$email->send( $customer_email, 'Your tracking number', $content );
// additional, if you want you can add a note to the order that the tracking email was sent
// the thirds parameter (false) tells WC to make this comment not visible to the customer
$order->add_order_note( $order_note, 0, false ); // see https://docs.woocommerce.com/wc-apidocs/source-class-WC_Abstract_Order.html#2306-2344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment