WooCommerce - senden Sie benutzerdefinierte E-Mail auf custom order status ändern
Ich Hinzugefügt eine benutzerdefinierte status wc-order-confirmed
:
//Register new status
function register_order_confirmed_order_status() {
register_post_status( 'wc-order-confirmed', array(
'label' => 'Potvrzení objednávky',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Potvrzení objednávky <span class="count">(%s)</span>', 'Potvrzení objednávky <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_order_confirmed_order_status' );
//Add to list of WC Order statuses
function add_order_confirmed_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
//add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-order-confirmed'] = 'Potvrzení objednávky';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_order_confirmed_to_order_statuses' );
Ich Hinzugefügt eine benutzerdefinierte E-Mail -wc_confirmed_order
:
/**
* A custom confirmed Order WooCommerce Email class
*
* @since 0.1
* @extends \WC_Email
*/
class WC_Confirmed_Order_Email extends WC_Email {
/**
* Set email defaults
*
* @since 0.1
*/
public function __construct() {
//set ID, this simply needs to be a unique name
$this->id = 'wc_confirmed_order';
//this is the title in WooCommerce Email settings
$this->title = 'Potvrzení objednávky';
//this is the description in WooCommerce email settings
$this->description = 'Confirmed Order Notification';
//these are the default heading and subject lines that can be overridden using the settings
$this->heading = 'Potvrzení objednávky';
$this->subject = 'Potvrzení objednávky';
//these define the locations of the templates that this email should use, we'll just use the new order template since this email is similar
$this->template_html = 'emails/customer-confirmed-order.php';
$this->template_plain = 'emails/plain/admin-new-order.php';
//Trigger on confirmed orders
add_action( 'woocommerce_order_status_pending_to_order_confirmed', array( $this, 'trigger' ) );
add_action( 'woocommerce_order_status_processing_to_order_confirmed', array( $this, 'trigger' ) );
//Call parent constructor to load any other defaults not explicity defined here
parent::__construct();
//this sets the recipient to the settings defined below in init_form_fields()
$this->recipient = $this->get_option( 'recipient' );
//if none was entered, just use the WP admin email as a fallback
if ( ! $this->recipient )
$this->recipient = get_option( 'admin_email' );
}
/**
* Determine if the email should actually be sent and setup email merge variables
*
* @since 0.1
* @param int $order_id
*/
public function trigger( $order_id ) {
//bail if no order ID is present
if ( ! $order_id )
return;
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-number'] = $this->object->get_order_number();
}
if ( ! $this->is_enabled() || ! $this->get_recipient() )
return;
//woohoo, send the email!
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
/**
* get_content_html function.
*
* @since 0.1
* @return string
*/
public function get_content_html() {
ob_start();
wc_get_template( $this->template_html, array(
'order' => $this->object,
'email_heading' => $this->get_heading()
) );
return ob_get_clean();
}
/**
* get_content_plain function.
*
* @since 0.1
* @return string
*/
public function get_content_plain() {
ob_start();
wc_get_template( $this->template_plain, array(
'order' => $this->object,
'email_heading' => $this->get_heading()
) );
return ob_get_clean();
}
/**
* Initialize Settings Form Fields
*
* @since 2.0
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable this email notification',
'default' => 'yes'
),
'recipient' => array(
'title' => 'Recipient(s)',
'type' => 'text',
'description' => sprintf( 'Enter recipients (comma separated) for this email. Defaults to <code>%s</code>.', esc_attr( get_option( 'admin_email' ) ) ),
'placeholder' => '',
'default' => ''
),
'subject' => array(
'title' => 'Subject',
'type' => 'text',
'description' => sprintf( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', $this->subject ),
'placeholder' => '',
'default' => ''
),
'heading' => array(
'title' => 'Email Heading',
'type' => 'text',
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.' ), $this->heading ),
'placeholder' => '',
'default' => ''
),
'email_type' => array(
'title' => 'Email type',
'type' => 'select',
'description' => 'Choose which format of email to send.',
'default' => 'html',
'class' => 'email_type',
'options' => array(
'plain' => __( 'Plain text', 'woocommerce' ),
'html' => __( 'HTML', 'woocommerce' ),
'multipart' => __( 'Multipart', 'woocommerce' ),
)
)
);
}
} //end \WC_confirmed_Order_Email class
Kann ich die E-Mail in der E-Mail-Einstellungen und den status in der Status meiner Bestellung dropdown-Menü. Jetzt brauche ich ihm meine neue E-Mail, wenn der status der Bestellung geändert wird wc-order-confirmed
. Der übergang Haken scheint nie feuern.
Ich auch versucht:
/**
* Register the "woocommerce_order_status_pending_to_quote" hook which is necessary to
* allow automatic email notifications when the order is changed to refunded.
*
* @modified from http://stackoverflow.com/a/26413223/2078474 to remove anonymous function
*/
add_action( 'woocommerce_init', 'so_25353766_register_email' );
function so_25353766_register_email(){
add_action( 'woocommerce_order_status_pending_to_order_confirmed', array( WC(), 'send_transactional_email' ), 10, 10 );
add_action( 'woocommerce_order_status_processing_to_order_confirmed', array( WC(), 'send_transactional_email' ), 10, 10 );
}
Denen scheint auch nicht zu funktionieren... Irgendwelche Ideen, bitte?
InformationsquelleAutor user1049961 | 2014-11-24
Du musst angemeldet sein, um einen Kommentar abzugeben.
Als Xcid die Antwort gibt, die Sie benötigen, um registrieren Sie die E-Mail.
In den WC 2.2+ ich glaube, man kann dies über die folgenden:
Ich würde einen filter Hinzugefügt, um WooCommerce 2.3, also wenn das raus kommt Sie benutzerdefinierte E-Mails werden in der Lage sein Hinzugefügt zu die Liste der E-Mail-Aktionen, WooCommerce Register:
InformationsquelleAutor helgatheviking
Den Haken, die Sie brauchen, ist:
woocommerce_order_status_changed
die hook ist richtig und funktioniert. senden Sie E-mails auf, deren status noch ändern, wenn der status der Bestellung ist nur geschaffen als "on-hold". die wc - ()->mailer ist über die php-mail-Klasse, so dass Sie noch verwenden können, die wp_mail-Funktion zum senden von mails und das hinzufügen von Anlagen etc. sehr einfach zu bedienen, wenn Sie wissen, wie Sie mails versenden mit php-Skript.
InformationsquelleAutor Queli Coto
Wie man hier sehen kann :
https://github.com/woothemes/woocommerce/blob/f8a161c40673cb019eb96b04c04a774ca040a15a/includes/abstracts/abstract-wc-order.php#L2097
Sie können mit diesem Haken :
do_action( 'woocommerce_order_status_' . $new_status, $this->id );
mit Ihnen individuelle status geben sollte :
add_action( 'woocommerce_order_status_wc-order-confirmed' , array( $this, 'trigger' ) );
Ich mir vorstellen, dass Sie auch fügen Sie benutzerdefinierte E-Mail an den mailer, wenn nicht :
nur hinzufügen :
Edit :
Müssen Sie instantiieren woocommerce E-Mails vor, so dass Sie hinzufügen können,
WC()->mailer() ist eine interne woocommerce-Funktion, die instanziert werden woocommerce E-Mails-service, in anderen Worten, die Funktion wird instantiieren Ihre benutzerdefinierte Klasse.
Yup, ich verstehe das WC - ()->mailer() sollte instantiieren meiner Klasse, aber ich bin mir nicht sicher, wohin damit? Du meinst, um es der
woocommerce_order_status_wc-order-confirmed
Aktion oder wo?Fügen Sie eine benutzerdefinierte status, wenn Sie change de status ? Manuell? Auf das back office ?
Im backoffice...
InformationsquelleAutor XciD
Können Sie versuchen, zu beobachten, wenn der status der Bestellung geändert, so dass dieses in functions.php:
Dieser Funktion löst Sie Ihre E-Mail und senden Sie es.
InformationsquelleAutor JoseLazo
hinzufügen einer benutzerdefinierten E-Mail-Klasse
dies ist der beste link zum hinzufügen einer benutzerdefinierten E-Mail-Klasse für woocommerce. Hat mir geholfen, wenn ich vor diesem problem
InformationsquelleAutor Mrinal