MarieComet / wcs-sell-coupons

WordPress Plugin to sell WooCommerce coupons
9 stars 3 forks source link

Allow resend of gift coupon email #6

Open Jon007 opened 7 years ago

Jon007 commented 7 years ago

If the gift coupon email is lost / not received, it is not easy to resend.

Ideally the giver should also be sent a copy, in case the receiver's email inbox is full or does not receive it (or the address was written wrong).

Jon007 commented 7 years ago

This is like an epic, points to include would be:

        add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ) );
        add_filter( 'woocommerce_locate_core_template', array( $this, 'email_templates' ), 0, 3 );

    /**
     * Add Custom Email templates
     *
     * @param array $mails
     * @return array
     */
    public function add_emails( $mails ) {
        $mails['WC_WCS_Gift_Email'] = include 'includes/emails/class-wc-wcs-gift-email.php';
        return $mails;
    }

  /**
     * Filter Email template to include gift email
     *
     * @param string $core_file
     * @param string $template
     * @param string $template_base
     * @return string
     */
    public function email_templates( $core_file, $template, $template_base ) {

        if ( ! file_exists( $template_base . $template ) && file_exists( $this->plugin_path() . '/templates/' . $template ) ) {
            $core_file = $this->plugin_path() . '/templates/' . $template;
        }

        return apply_filters( 'wcs_email_templates', $core_file, $template, $template_base );
    }

class WC_WCS_Gift_Email extends WC_Email {
...

    function __construct() {
..

        // Should hook paid rather than completed, see #16
        add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 30 );