• Resolved djmono

    (@djmono)


    Hallo,

    ich habe ein seltsames Problem: In einer Kundenmail, die nach Bestellung mit Vorkasse kommt, wird die Lieferzeit doppelt ausgegeben, untereinander.

    Diese Mail habe ich als zus?tzliche Mailklasse mit einem kleinen plugin eingebunden und sie wird korrekt nur dann verschickt, wenn Vorkasse gew?hlt wird. Eine weitere, mit identischem Template (bis auf Eingangstext) habe ich für Sofortüberweisung — dort wird die Lieferzeit richtig nur einmal ausgegeben.

    Ich denke, dass es von Germanized kommt, mit deaktiviertem Plugin ist gar keine Lieferzeit in der Mail drin.

    Was kann ich da machen? Macht mich verrückt, weil ich gefühlt schon in jeder Ecke geguckt habe, aber ich komme einfach nicht drauf …

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Dennis

    (@vdwoocommercesupport)

    Hi,

    hm, leider kenne ich dein Plugin/Setup nicht genau. Grunds?tzlich klinken wir uns in den woocommerce_order_item_name filter ein, wenn eine Mail versendet wird um die Informationen zu platzieren. Du solltest dir mal die Methode set_order_email_filters in der Klasse WC_GZD_Emails ansehen. Diese Hooks setzen wir im Hook woocommerce_email_before_order_table und entfernen sie anschlie?end erneut. Du solltest mal checken ob in deinen E-Mail-Templates der Hook woocommerce_email_after_order_table ausgeführt wird.

    Leider ist das etwas kompliziert zu debuggen – ich denke mal du wirst einige Testausgaben vornehmen müssen und dir evtl. die aktiven Filter zur Laufzeit ansehen müssen.

    Grü?e

    Thread Starter djmono

    (@djmono)

    Hm, ich habe mir die genannten Sachen angeshen, leider übersteigt das meine Coding-Kompetenz (die daraus besteht, einfache Snippets zu copypasten). Wie kann man denn die Hooks in den Mails checken? Simply Show Hooks in Verbindung mit WP Mail Log funktioniert schon mal nicht …

    Bzgl. meines Plugins, der besteht im Wesentlichen hieraus:

    function custom_woocommerce_email( $email_classes ) {
    
    	// include our custom email class
    	
    
    	require_once( 'includes/class_sofort_email.php' );
    	require_once( 'includes/class_vorkasse_email.php' );
    
    	// add the email class to the list of email classes that WooCommerce loads
    	
    	$email_classes['Sofort_Email'] = new Sofort_Email();
    	$email_classes['Vorkasse_Email'] = new Vorkasse_Email();
    
    	return $email_classes;
    
    }
    add_filter( 'woocommerce_email_classes', 'custom_woocommerce_email' );
    

    Die Klasse sieht dann so aus:

    <?php
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    /**
     * Welcome Email class used to send out welcome emails to customers purchasing a course
     *
     * @extends \WC_Email
     */
    class Vorkasse_Email extends WC_Email {
    	
    	/**
    	 * Set email defaults
    	 */
    	public function __construct() {
    		// Unique ID for custom email
    		$this->id = 'vorkasse_email';
    		// Is a customer email
    		$this->customer_email = true;
    		
    		// Title field in WooCommerce Email settings
    		$this->title = __( 'Vorkasse Email', 'woocommerce' );
    		// Description field in WooCommerce email settings
    		$this->description = __( 'This email is sent when Vorkasse payment is used.', 'woocommerce' );
    		// Default heading and subject lines in WooCommerce email settings
    		$this->subject = apply_filters( 'vorkasse_email_default_subject', __( 'Danke für Vorkasse', 'woocommerce' ) );
    		$this->heading = apply_filters( 'vorkasse_email_default_heading', __( 'Welcome to Online Training Program', 'woocommerce' ) );
    		
    		// 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
    		$upload_dir = wp_upload_dir();
    		
    		$this->template_html  = 'emails/vorkasse_email.php';
    
    		// Call parent constructor to load any other defaults not explicity defined here
    		parent::__construct();
    	}
    	/**
    	 * Prepares email content and triggers the email
    	 *
    	 * @param int $order_id
    	 */
    	public function trigger( $order_id ) {
    		// Bail if no order ID is present
    		if ( ! $order_id )
    			return;
    		
    		// Send welcome email only once and not on every order status change		
    		if ( ! get_post_meta( $order_id, '_vorkasse_email_sent', true ) ) {
    			
    			// setup order object
    			$this->object = new WC_Order( $order_id );
    			
    			// get order items as array
    			$order_items = $this->object->get_items();
    			//* Maybe include an additional check to make sure that the online training program account was created
    			/* Uncomment and add your own conditional check
    			$online_training_account_created = get_post_meta( $this->object->id, '_crwc_user_account_created', 1 );
    			
    			if ( ! empty( $online_training_account_created ) && false === $online_training_account_created ) {
    				return;
    			}
    			*/
    			/* Proceed with sending email */
    			
    			$this->recipient = $this->object->billing_email;
    			// 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;
    			}
    			// All well, send the email
    			$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
    			
    			// add order note about the same
    			$this->object->add_order_note( sprintf( __( '%s email sent to the customer.', 'woocommerce' ), $this->title ) );
    			// Set order meta to indicate that the welcome email was sent
    			update_post_meta( $this->object->id, '_vorkasse_email_sent', 1 );
    			
    		}
    		
    	}
    	
    	/**
    	 * get_content_html function.
    	 *
    	 * @return string
    	 */
    	public function get_content_html() {
    		return wc_get_template_html( $this->template_html, array(
    			'order'					=> $this->object,
    			'email_heading'			=> $this->get_heading(),
    			'sent_to_admin'			=> false,
    			'plain_text'			=> false,
    			'email'					=> $this
    		) );
    	}
    	/**
    	 * get_content_plain function.
    	 *
    	 * @return string
    	 */
    	public function get_content_plain() {
    		return wc_get_template_html( $this->template_plain, array(
    			'order'					=> $this->object,
    			'email_heading'			=> $this->get_heading(),
    			'sent_to_admin'			=> false,
    			'plain_text'			=> true,
    			'email'					=> $this
    		) );
    	}
    	/**
    	 * Initialize settings form fields
    	 */
    	public function init_form_fields() {
    		$this->form_fields = array(
    			'enabled'    => array(
    				'title'   => __( 'Enable/Disable', 'woocommerce' ),
    				'type'    => 'checkbox',
    				'label'   => 'Enable this email notification',
    				'default' => 'yes'
    			),
    			'subject'    => array(
    				'title'       => __( 'Subject', 'woocommerce' ),
    				'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', 'woocommerce' ),
    				'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', 'woocommerce' ),
    				'type'        => 'select',
    				'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
    				'default'       => 'html',
    				'class'         => 'email_type wc-enhanced-select',
    				'options'     => array(
    					'plain'	    => __( 'Plain text', 'woocommerce' ),
    					'html' 	    => __( 'HTML', 'woocommerce' ),
    					'multipart' => __( 'Multipart', 'woocommerce' ),
    				)
    			)
    		);
    	}
    		
    }

    Und das Template so:

    <?php
    /**
     *
     * Welcome email content template
     *
     * The file is prone to modifications after plugin upgrade or alike; customizations are advised via hooks/filters
     *
     */
     
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    /**
     * @hooked WC_Emails::email_header() Output the email header
     */
    do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
    <p><?php printf( __( "Hallo, %s!", 'woocommerce' ), $order->billing_first_name ); ?></p>
    <p><?php _e( 'Bitte überweise den f?lligen Betrag an unsere Bankverbindung unter Angabe der Bestellnummer. Deine Bestellung wird nach Geldeingang auf unserem Konto umgehend versandt. ', 'woocommerce' ); ?></p>
    <p><?php _e( 'Unsere Bankverbindung:' ) ?></p><p><?php _e( 'Zahlungsempf?nger: xxx' ) ?></p><p><?php _e( 'Bank: xxx' ) ?></p><p><?php _e( 'IBAN: xxx' ) ?></p><p><?php _e( 'BIC: xxx' ) ?></p>
    </br>
    <p><?php _e( 'Die Bestelldetails werden nachstehend zur Kontrolle angezeigt:' ) ?></p>
    <?php
    /**
    * @hooked WC_Emails::order_details() Shows the order details table.
    * @hooked WC_Emails::order_schema_markup() Adds Schema.org markup.
    * @since 2.5.0
    */
    do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
    /**
    * @hooked WC_Emails::order_meta() Shows order meta data.
    */
    do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
    /**
    * @hooked WC_Emails::customer_details() Shows customer details
    * @hooked WC_Emails::email_address() Shows email address
    */
    do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
    /**
     * @hooked WC_Emails::email_footer() Output the email footer
     */
    do_action( 'woocommerce_email_footer', $email );
    

    Wie gesagt, die Dateien für Sofortüberweisung sind bis auf die Texte identisch, dort wird aber die Lieferzeit nicht gedoppelt.

    Vielleicht noch erw?hnenswert, dass ich die automatische Bestellbest?tigung von Gzd mit einem Snippet unterdrücke, und die beiden Sonderemails keinen Bestellstatus als Trigger haben, sondern damit ausgel?st werden:

    /* send email when Vorkasse payment is chosen */
    add_action( 'woocommerce_thankyou', 'wc_vorkasse_payment_method_email_notification', 10, 1 );
    function wc_vorkasse_payment_method_email_notification( $order_id ) {
        if ( ! $order_id ) return;
    
        $order = wc_get_order( $order_id );
    
        $user_complete_name_and_email = $order->billing_first_name . ' ' . $order->billing_last_name . ' <' . $order->billing_email . '>';
        $to = $user_complete_name_and_email;
    
        // Sending a custom email when 'cheque' is the payment method.
        if ( get_post_meta($order->id, '_payment_method', true) == 'bacs' ) {
    $mailer = WC()->mailer();
    $mails = $mailer->get_emails();
    if ( ! empty( $mails ) ) {
        foreach ( $mails as $mail ) {
            if ( $mail->id == 'vorkasse_email' ) {
               $mail->trigger( $order->id );
            }
         }
    }
        }
        
    	    
        if( $subject & $message) {
            wp_mail($to, $subject, $message, $headers );
        }
    }
    
    Plugin Contributor Dennis

    (@vdwoocommercesupport)

    Hi,

    hm, verstehe. Vielleicht hilft dir folgender “Trick” weiter. Füge mal in deine “wc_vorkasse_payment_method_email_notification” folgendes mit ein (bevor die E-Mail versendet wird):

    $mailer = WC_germanized()->emails;
    $mailer->remove_order_email_filters();

    Damit sollten die Filter noch einmal manuell entfernt werden, bevor deine Mail versendet wird.

    Grü?e

    Thread Starter djmono

    (@djmono)

    Hat leider nicht funktioniert … Ich hab den Code auch an verschiedenen Stellen ausprobiert, die Dopplung bleibt einfach hartn?ckig drin. ??

    Plugin Contributor Dennis

    (@vdwoocommercesupport)

    Hi,

    verstehe. Kannst du mal folgendes testen:

    In includes/wc-gzd-template-functions.php die Zeile 482 (dort wird der Filter für die Anzeige der Lieferzeit in den Bestelldetails auf der Danke-Seite gesetzt) auskommentieren.

    Wird nun die Lieferzeit in deiner Vorkasse-Mail nur noch einmal angezeigt?

    Grü?e

    Thread Starter djmono

    (@djmono)

    Ahhhh endlich, so wird die Lieferzeit nicht gedoppelt ?? Auf der ThankYou-Seite wird sie dann natürlich auch nicht angezeigt, damit kann ich leben. Aber der Trick wird beim n?chsten Update überschrieben, sch?tze ich?

    Plugin Contributor Dennis

    (@vdwoocommercesupport)

    Hi,

    gut, dann sind wir ja auf der richtigen F?hrte ?? Ich habe mal folgendes via GitHub commited: https://github.com/vendidero/woocommerce-germanized/commit/cf212441780bdd1851df12c9248293cc522ef971

    Ich habe die Filter explizit in der Methode “remove_order_email_filters” entfernt, sodass diese nun nicht mehr doppelt in der Mail ausgegeben werden sollten. Kannst du die Zeile mal wieder einfügen (also in wc-gzd-template-functions.php) und den Patch von GitHub anwenden, d.h. die Datei includes/wc-gzd-emails.php ersetzen (mit der Master-Version von GitHub) und anschlie?end vor deinem Mail-Versand wieder:

    $mailer = WC_germanized()->emails;
    $mailer->remove_order_email_filters();

    aufrufen? Die Lieferzeit sollte jetzt nur noch einmalig ausgegeben werden..

    Grü?e

    Thread Starter djmono

    (@djmono)

    Sorry, dass es so lange gedauert hat, so funktioniert es, vielen Dank! ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Lieferzeit doppelt in der Mail’ is closed to new replies.