Woocommerce Refund Email

Ich habe viel gesucht und obwohl ich Benutzer gefunden habe, die gefragt haben, wie man das Folgende erreicht, gibt es meines Wissens nach keine Beispiele für funktionierende Lösungen.

Die Frage betrifft das sehr beliebte Wordpress-Plugin "Woocommerce". Das Plugin wird mit einem E-Mail-System geliefert, um dem E-Commerce-Site-Inhaber und dem Kunden das Leben zu erleichtern. Ein Problem ist, dass keine E-Mail gesendet wird, wenn ein Shop-Manager den Bestellstatus auf "Rückerstattet" ändert. Jemand hat gesagt, dass dies ein manueller Prozess ist. Dies ist wahr, es ist ein Vorgang, den der Ladenbesitzer über sein Händlerkonto oder sein Paypal-Konto ausführen würde. Sobald dies erledigt ist und sich der Shop-Besitzer in seinem WordPress-Admin-Bereich anmeldet und den Bestellstatus in "Rückerstattet" ändert, ist es vorteilhaft, eine E-Mail zu generieren und dem Kunden zu senden.

Dies ist etwas, was ich angefordert gesehen habe.

Also habe ich beschlossen, ein Tutorial um zu ändernhttp://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/#comment-553147

Ich versuche, eine E-Mail zu versenden, wenn der Auftragsstatus einer Bestellung auf "Rückerstattet" aktualisiert wird.

Hier ist der Code für die anfängliche Plugin-Datei

<?php
/**
 * Plugin Name: WooCommerce Custom Expedited Order Email
 * Plugin URI: http://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
 * Description: Demo plugin for adding a custom WooCommerce email that sends admins an email when an order is received with expedited shipping
 * Author: SkyVerge
 * Author URI: http://www.skyverge.com
 * Version: 0.1
 *
 * License: GNU General Public License v3.0
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 *
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 *  Add a custom email to the list of emails WooCommerce should load
 *
 * @since 0.1
 * @param array $email_classes available email classes
 * @return array filtered available email classes
 */
function add_expedited_order_woocommerce_email( $email_classes ) {

    // include our custom email class
    require( 'includes/class-wc-expedited-order-email.php' );

    // add the email class to the list of email classes that WooCommerce loads
    $email_classes['WC_Expedited_Order_Email'] = new WC_Expedited_Order_Email();

    return $email_classes;

}
add_filter( 'woocommerce_email_classes', 'add_expedited_order_woocommerce_email' );

Und hier ist ein Link zum Code meiner Klasse

<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * A custom Expedited Order WooCommerce Email class
 *
 * @since 0.1
 * @extends \WC_Email
 */
class WC_Expedited_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_expedited_order';

        // this is the title in WooCommerce Email settings
        $this->title = 'Refunded Order Email';

        // this is the description in WooCommerce email settings
        $this->description = 'Refunded Emails are sent when an order status has been changed to Refunded';

        // these are the default heading and subject lines that can be overridden using the settings
        $this->heading = 'Refunded Order';
        $this->subject = 'Refunded Order';

        // 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/admin-new-order.php';
        $this->template_plain = 'emails/plain/admin-new-order.php';

        // Trigger on new paid orders
        add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) );
        add_action( 'woocommerce_order_status_failed_to_processing_notification',  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;

        $order = new WC_Order( $order_id );

          //bail if not a refunded order
        if ( 'refunded' !== $order->status ) {
              return;
        }

        // setup order object
        $this->object = new WC_Order( $order_id );

        // bail if shipping method is not expedited
        //if ( ! in_array( $this->object->get_shipping_method(), array( 'Three Day Shipping', 'Next Day Shipping' ) ) )
            //return;

        // replace variables in the subject/headings
        $this->find[] = '{order_date}';
        $this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );

        $this->find[] = '{order_number}';
        $this->replace[] = $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();
        woocommerce_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();
        woocommerce_get_template( $this->template_plain, array(
            'order'         => $this->object,
            'email_heading' => $this->get_heading()
        ) );
        return ob_get_clean();
    }

    /**
     * Initialize Settings Form Fields
     *
     * @since 0.1
     */
    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',
                    'html'      => 'HTML', 'woocommerce',
                    'multipart' => 'Multipart', 'woocommerce',
                )
            )
        );
    }


} // end \WC_Expedited_Order_Email class

Dies sind die einzigen 2 Dateien in meinem Plugin. Ich habe es aktiviert und es wird als E-Mail in der E-Mail-Liste auf der Registerkarte "Woo Commerce-E-Mail" angezeigt. Leider wird keine E-Mail gesendet, wenn der Bestellstatus aktualisiert wird.

Kann jemand raten, warum dies nicht funktioniert?

Ich habe einige Rückmeldungen von einer Person erhalten, die Folgendes sagte

"Die Aktionen, zu denen Sie den Auslöser hinzufügen, sind für die ausstehende / fehlgeschlagene Verarbeitung von Auftragsstatusänderungen bestimmt. -http://cld.wthms.co/cZzw Sie möchten, dass dies Aktionen sind, die sich auf die rückerstatteten Bestellungen beziehen, wie: add_action ('woocommerce_order_status_refunded', array ($ this, 'trigger')); (für den genauen Überblick schauen Sie sich die E-Mail-Klassen von woocommerce an) "

Ich benutze Woocommerce 2.1.12

Antworten auf die Frage(2)

Ihre Antwort auf die Frage