Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter djmono

    (@djmono)

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

    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?

    Thread Starter djmono

    (@djmono)

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

    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 );
        }
    }
    
    Thread Starter djmono

    (@djmono)

    Here is the link to the pink logos: https://developer.klarna.com/en/gb/kco-v3/sofort-design-guidelines/how-to-display-sofort/

    The one you linked is for the company, the payment method Sofortüberweisung is substituted by the pink one with the hand and Sofort. (at least in Germany).

    Edit: Here are the logos for the small heights, about same size as the old one: https://developer.klarna.com/en/gb/kco-v3/sofort-design-guidelines/narrow-checkout-badges

    • This reply was modified 7 years, 6 months ago by djmono.
Viewing 5 replies - 1 through 5 (of 5 total)