Woocommerce 向运输字段中的不同电子邮件地址发送电子邮件通知
Woocommerce Email Notification to Different Email address in Shipping Field
我正在努力实现如下目标。
我想将 woocommerce 产品作为礼物送给我的朋友或兄弟或类似的人。为此,我将依赖结帐页面中的 "Ship to different Address" 字段。因此,如果任何人想将该产品作为礼物发送,那么他或她可以将产品发送到不同的送货地址,即礼物收件人地址。
为此,我修改了结帐页面,在 "Ship to different Address" 部分添加了一个电子邮件字段。
现在我想要的是我也想向礼物接收者发送有关订单的电子邮件通知,以便接收者知道有人将此产品作为礼物送给他..
如何将有关订单的电子邮件通知发送到礼物接收者的电子邮件地址?
谢谢
这是我编写的用于添加运输电子邮件的插件。它应该可以工作,但我不久前写了它,所以不能保证。
<?php
/*
Plugin Name: WooCommerce Shipping Email
Plugin URI: http://www.kathyisawesome.com/
Description: Add a shipping email field to checkout and notify of new orders
Version: 1.0
Author: Kathy Darling
Author URI: http://kathyisawesome.com
Requires at least: 4.0
Tested up to: 4.0
Copyright: © 2014 Kathy Darling.
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* The Main WC_Shipping_Email class
**/
if ( ! class_exists( 'WC_Shipping_Email' ) ) :
class WC_Shipping_Email {
/**
* @var WC_Shipping_Email - the single instance of the class
* @since 1.0
*/
protected static $_instance = null;
/**
* Main WC_Shipping_Email Instance
*
* Ensures only one instance of WC_Shipping_Email is loaded or can be loaded.
*
* @static
* @see WC_Shipping_Email()
* @return WC_Shipping_Email - Main instance
* @since 1.0
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @since 1.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-mix-and-match' ), '2.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'mix-and-match' ), '2.0' );
}
/**
* WC_Shipping_Email Constructor
*
* @access public
* @return WC_Shipping_Email
* @since 1.0
*/
public function __construct() {
$this->id = 'email';
$this->meta = '_shipping_email';
$this->label = __( 'Shipping Email', 'woocommerce-shipping-email' );
// add email field to checkout
add_filter( 'woocommerce_shipping_fields' , array( $this, 'add_shipping_fields' ) );
add_filter( 'woocommerce_admin_shipping_fields' , array( $this, 'admin_shipping_fields' ) );
// add recipient to specific emails
add_filter( 'woocommerce_email_recipient_customer_processing_order' , array( $this, 'add_recipient' ), 20, 2 );
add_filter( 'woocommerce_email_recipient_customer_completed_order' , array( $this, 'add_recipient' ), 20, 2 );
add_filter( 'woocommerce_email_recipient_customer_note' , array( $this, 'add_recipient' ), 20, 2 );
// display meta key in order overview
add_action( 'woocommerce_order_details_after_customer_details' , array( $this, 'after_customer_details' ) );
// display meta key in email
add_action( 'woocommerce_before_template_part' , array( $this, 'before_email_addresses' ), 10, 4 );
}
/*-----------------------------------------------------------------------------------*/
/* Plugin Functions */
/*-----------------------------------------------------------------------------------*/
/**
* Add email to front-end shipping fields
*
* @var array $fields
* @return array
* @since 1.0
*/
function add_shipping_fields( $fields ) {
$fields['shipping_' . $this->id] = array(
'label' => $this->label,
'required' => true,
'class' => array( 'form-row-first' ),
'validate' => array( 'email' ),
);
return $fields;
}
/**
* Add email to Admin Order overview
*
* @var array $fields
* @return array
* @since 1.0
*/
function admin_shipping_fields( $fields ) {
$fields[$this->id] = array(
'label' => $this->label
);
return $fields;
}
/**
* Add recipient to emails
*
* @var mixed $email
* @return mixed
* @since 1.0
*/
function add_recipient( $email, $order ) {
$additional_email = get_post_meta( $order->id, $this->meta, true );
if( $additional_email && is_email( $additional_email )){
$email = explode( ',', $email );
array_push( $email, $additional_email );
}
return $email;
}
/**
* Display meta in my-account area Order overview
*
* @var object $order
* @return null
* @since 1.0
*/
public function after_customer_details( $order ){
$value = get_post_meta( $order->id, $this->meta, true );
if( $value ){
echo '<dt>' . $this->label . ':</dt><dd>' . $value . '</dd>';
}
}
/**
* Display meta in my-account area Order overview
*
* @var array $fields
* @return array
* @since 1.0
*/
public function before_email_addresses( $template_name, $template_path, $located, $args ){
if( $template_name == 'emails/email-addresses.php' && isset( $args['order' ] ) && ( $value = get_post_meta( $args['order']->id, $this->meta, true ) ) ){
if ( isset( $args['plain_text'] ) && $args['plain_text'] ){
echo $this->label . ': ' . $value . "\n";
} else {
echo '<p><strong>' . $this->label . ':</strong> ' . $value . '</p>';
}
}
}
} //end class: do not remove or there will be no more guacamole for you
endif; // end class_exists check
/**
* Returns the main instance of WC_Shipping_Email to prevent the need to use globals.
*
* @since 2.0
* @return WooCommerce
*/
function WC_Shipping_Email() {
return WC_Shipping_Email::instance();
}
// Launch the whole plugin
WC_Shipping_Email();
这是结帐页面的结果,您可以看到 "ship to a different address" 列下添加了 Shipping Email 字段。
其实我已经不需要它了。但我认为这个插件 http://codecanyon.net/item/woocommerce-checkout-field-editor/11725925 会在结帐字段中为您完成您想做的所有事情。这就是我需要的。
感谢大家的努力
我正在努力实现如下目标。
我想将 woocommerce 产品作为礼物送给我的朋友或兄弟或类似的人。为此,我将依赖结帐页面中的 "Ship to different Address" 字段。因此,如果任何人想将该产品作为礼物发送,那么他或她可以将产品发送到不同的送货地址,即礼物收件人地址。
为此,我修改了结帐页面,在 "Ship to different Address" 部分添加了一个电子邮件字段。
现在我想要的是我也想向礼物接收者发送有关订单的电子邮件通知,以便接收者知道有人将此产品作为礼物送给他..
如何将有关订单的电子邮件通知发送到礼物接收者的电子邮件地址?
谢谢
这是我编写的用于添加运输电子邮件的插件。它应该可以工作,但我不久前写了它,所以不能保证。
<?php
/*
Plugin Name: WooCommerce Shipping Email
Plugin URI: http://www.kathyisawesome.com/
Description: Add a shipping email field to checkout and notify of new orders
Version: 1.0
Author: Kathy Darling
Author URI: http://kathyisawesome.com
Requires at least: 4.0
Tested up to: 4.0
Copyright: © 2014 Kathy Darling.
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* The Main WC_Shipping_Email class
**/
if ( ! class_exists( 'WC_Shipping_Email' ) ) :
class WC_Shipping_Email {
/**
* @var WC_Shipping_Email - the single instance of the class
* @since 1.0
*/
protected static $_instance = null;
/**
* Main WC_Shipping_Email Instance
*
* Ensures only one instance of WC_Shipping_Email is loaded or can be loaded.
*
* @static
* @see WC_Shipping_Email()
* @return WC_Shipping_Email - Main instance
* @since 1.0
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @since 1.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-mix-and-match' ), '2.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'mix-and-match' ), '2.0' );
}
/**
* WC_Shipping_Email Constructor
*
* @access public
* @return WC_Shipping_Email
* @since 1.0
*/
public function __construct() {
$this->id = 'email';
$this->meta = '_shipping_email';
$this->label = __( 'Shipping Email', 'woocommerce-shipping-email' );
// add email field to checkout
add_filter( 'woocommerce_shipping_fields' , array( $this, 'add_shipping_fields' ) );
add_filter( 'woocommerce_admin_shipping_fields' , array( $this, 'admin_shipping_fields' ) );
// add recipient to specific emails
add_filter( 'woocommerce_email_recipient_customer_processing_order' , array( $this, 'add_recipient' ), 20, 2 );
add_filter( 'woocommerce_email_recipient_customer_completed_order' , array( $this, 'add_recipient' ), 20, 2 );
add_filter( 'woocommerce_email_recipient_customer_note' , array( $this, 'add_recipient' ), 20, 2 );
// display meta key in order overview
add_action( 'woocommerce_order_details_after_customer_details' , array( $this, 'after_customer_details' ) );
// display meta key in email
add_action( 'woocommerce_before_template_part' , array( $this, 'before_email_addresses' ), 10, 4 );
}
/*-----------------------------------------------------------------------------------*/
/* Plugin Functions */
/*-----------------------------------------------------------------------------------*/
/**
* Add email to front-end shipping fields
*
* @var array $fields
* @return array
* @since 1.0
*/
function add_shipping_fields( $fields ) {
$fields['shipping_' . $this->id] = array(
'label' => $this->label,
'required' => true,
'class' => array( 'form-row-first' ),
'validate' => array( 'email' ),
);
return $fields;
}
/**
* Add email to Admin Order overview
*
* @var array $fields
* @return array
* @since 1.0
*/
function admin_shipping_fields( $fields ) {
$fields[$this->id] = array(
'label' => $this->label
);
return $fields;
}
/**
* Add recipient to emails
*
* @var mixed $email
* @return mixed
* @since 1.0
*/
function add_recipient( $email, $order ) {
$additional_email = get_post_meta( $order->id, $this->meta, true );
if( $additional_email && is_email( $additional_email )){
$email = explode( ',', $email );
array_push( $email, $additional_email );
}
return $email;
}
/**
* Display meta in my-account area Order overview
*
* @var object $order
* @return null
* @since 1.0
*/
public function after_customer_details( $order ){
$value = get_post_meta( $order->id, $this->meta, true );
if( $value ){
echo '<dt>' . $this->label . ':</dt><dd>' . $value . '</dd>';
}
}
/**
* Display meta in my-account area Order overview
*
* @var array $fields
* @return array
* @since 1.0
*/
public function before_email_addresses( $template_name, $template_path, $located, $args ){
if( $template_name == 'emails/email-addresses.php' && isset( $args['order' ] ) && ( $value = get_post_meta( $args['order']->id, $this->meta, true ) ) ){
if ( isset( $args['plain_text'] ) && $args['plain_text'] ){
echo $this->label . ': ' . $value . "\n";
} else {
echo '<p><strong>' . $this->label . ':</strong> ' . $value . '</p>';
}
}
}
} //end class: do not remove or there will be no more guacamole for you
endif; // end class_exists check
/**
* Returns the main instance of WC_Shipping_Email to prevent the need to use globals.
*
* @since 2.0
* @return WooCommerce
*/
function WC_Shipping_Email() {
return WC_Shipping_Email::instance();
}
// Launch the whole plugin
WC_Shipping_Email();
这是结帐页面的结果,您可以看到 "ship to a different address" 列下添加了 Shipping Email 字段。
其实我已经不需要它了。但我认为这个插件 http://codecanyon.net/item/woocommerce-checkout-field-editor/11725925 会在结帐字段中为您完成您想做的所有事情。这就是我需要的。
感谢大家的努力