woocommerce/classes/emails/class-wc-email-customer-inv...

185 lines
5.2 KiB
PHP
Raw Normal View History

<?php
2013-02-20 17:14:46 +00:00
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Customer Invoice
*
* An email sent to the customer via admin.
*
* @class WC_Email_Customer_Invoice
2012-12-03 19:19:58 +00:00
* @version 2.0.0
* @package WooCommerce/Classes/Emails
* @author WooThemes
* @extends WC_Email
*/
class WC_Email_Customer_Invoice extends WC_Email {
2012-11-27 16:22:47 +00:00
var $find;
var $replace;
2012-11-27 16:22:47 +00:00
/**
* Constructor
*/
function __construct() {
2012-11-27 16:22:47 +00:00
$this->id = 'customer_invoice';
$this->title = __( 'Customer invoice', 'woocommerce' );
2012-10-12 14:30:20 +00:00
$this->description = __( 'Customer invoice emails can be sent to the user containing order info and payment links.', 'woocommerce' );
$this->template_html = 'emails/customer-invoice.php';
$this->template_plain = 'emails/plain/customer-invoice.php';
2012-11-27 16:22:47 +00:00
$this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce');
$this->heading = __( 'Invoice for order {order_number}', 'woocommerce');
2012-11-27 16:22:47 +00:00
$this->subject_paid = __( 'Your {blogname} order from {order_date}', 'woocommerce');
$this->heading_paid = __( 'Order {order_number} details', 'woocommerce');
2012-11-27 16:22:47 +00:00
// Call parent constuctor
parent::__construct();
}
/**
* trigger function.
2012-11-27 16:22:47 +00:00
*
* @access public
* @return void
*/
function trigger( $order ) {
global $woocommerce;
if ( ! is_object( $order ) ) {
$order = new WC_Order( absint( $order ) );
}
2012-11-27 16:22:47 +00:00
if ( $order ) {
$this->object = $order;
$this->recipient = $this->object->billing_email;
2012-11-27 16:22:47 +00:00
$this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
2012-11-27 16:22:47 +00:00
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number();
}
2012-11-27 16:22:47 +00:00
if ( ! $this->is_enabled() || ! $this->get_recipient() )
return;
2012-11-27 16:22:47 +00:00
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
2012-11-27 16:22:47 +00:00
/**
* get_subject function.
2012-11-27 16:22:47 +00:00
*
* @access public
* @return string
*/
function get_subject() {
if ( $this->object->status == 'processing' || $this->object->status == 'completed' )
return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $this->subject_paid ), $this->object );
else
return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $this->subject ), $this->object );
}
/**
* get_heading function.
2012-11-27 16:22:47 +00:00
*
* @access public
* @return string
*/
function get_heading() {
if ( $this->object->status == 'processing' || $this->object->status == 'completed' )
return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $this->heading_paid ), $this->object );
else
return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $this->heading ), $this->object );
}
/**
* get_content_html function.
2012-11-27 16:22:47 +00:00
*
* @access public
* @return string
*/
function get_content_html() {
ob_start();
woocommerce_get_template( $this->template_html, array(
'order' => $this->object,
'email_heading' => $this->get_heading()
) );
return ob_get_clean();
}
2012-11-27 16:22:47 +00:00
/**
* get_content_plain function.
2012-11-27 16:22:47 +00:00
*
* @access public
* @return string
*/
function get_content_plain() {
ob_start();
woocommerce_get_template( $this->template_plain, array(
'order' => $this->object,
'email_heading' => $this->get_heading()
) );
return ob_get_clean();
}
2012-11-27 16:22:47 +00:00
/**
* Initialise Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes'
),
'subject' => array(
'title' => __( 'Email subject', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
'placeholder' => '',
'default' => ''
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
'placeholder' => '',
'default' => ''
),
'subject_paid' => array(
'title' => __( 'Email subject (paid)', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_paid ),
'placeholder' => '',
'default' => ''
),
'heading_paid' => array(
'title' => __( 'Email heading (paid)', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_paid ),
'placeholder' => '',
'default' => ''
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type',
'options' => array(
'plain' => __( 'Plain text', 'woocommerce' ),
'html' => __( 'HTML', 'woocommerce' ),
'multipart' => __( 'Multipart', 'woocommerce' ),
)
)
);
}
}