Support » Plugin: Germanized for WooCommerce » PDF Attachments when manually calling WC_Email_Customer_Completed_Order()

  • Resolved teresasumisu

    (@teresasumisu)


    Hi!

    I need to send the order confirmation only after the payment is completed.
    So i inserted this code, which works fine:

    add_action( 'woocommerce_payment_complete', 'ww_payment_complete' );
    function ww_payment_complete( $order_id ){
        $email_o = new WC_Email_Customer_Completed_Order();
        $email_o->trigger($order_id);
    }

    BUT I also need to attach PDFs (via Germanized > E-Mails), but the way I am calling the E-Mail function, the PDF is not attached.
    It works fine, when the Order Confirmation Mail is sent by WooCommerce directly – the files get attached.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author vendidero

    (@vendidero)

    Hi there,

    we are attaching the PDFs through official WooCommerce Filters (e.g. woocommerce_email_attachments). You might want to check whether our filter gets applied by inserting some test outputs in WC_GZDP_Legal_Page_Helper::attach_pdfs.

    Maybe it would be better to not initiate a new email object but to use the existing ones, e.g.:

    $mails  = WC()->mailer()->emails;
    $email_o = $mails['WC_Email_Customer_Completed_Order'];

    Cheers

    Thread Starter teresasumisu

    (@teresasumisu)

    Unfortunately, using the existing object did not work.

    Plugin Author vendidero

    (@vendidero)

    Hi,

    then please investigate that further by following my approach from above. You might need to check, whether our filter gets applied or not. I do not see any issue with the code – normally it should be applied successfully even when manually triggering the email. Did you try to deactivate other plugins one after another?

    Cheers

    Thread Starter teresasumisu

    (@teresasumisu)

    Hi!
    I tried to attach an other file in WC_GZDP_Legal_Page_Helper::attach_pdfs with an absolute path – and the file got attached. So it is a path problem, or the variable $attachments is empty at this point.
    I can’t investigate this further for now. I hope you fix this, it would be great.

    This is how I am doing it now:

    add_filter( 'woocommerce_email_attachments', 'attach_disclaimer_pdf_to_email', 10, 3);
    function attach_disclaimer_pdf_to_email ( $attachments , $id, $object ) {
    
        if($id = 'customer_completed_order') {
            $serverRoot = $_SERVER['DOCUMENT_ROOT'];
            $attachments[] = $serverRoot. '/wp-content/uploads/2019/10/pdf.pdf';
            $attachments[] = $serverRoot. '/wp-content/uploads/2019/10/myfile.pdf';
        }
    
    	return $attachments;
    }
    
    add_action( 'woocommerce_payment_complete', 'lw_payment_complete' );
    function lw_payment_complete( $order_id ){
        $mails  = WC()->mailer()->emails;
        $email_o = $mails['WC_Email_Customer_Completed_Order'];
        $email_o->trigger($order_id);
    }
    • This reply was modified 4 years, 4 months ago by teresasumisu.
    • This reply was modified 4 years, 4 months ago by teresasumisu.
    Plugin Author vendidero

    (@vendidero)

    Hi there,

    I’ve just tested the script by myself. I’ve manually triggered the order complete mail including attachments – just like you did. I can’t find any problems with the attachments – my chosen attachments are attached as configured.

    You might need to debug that a little further, e.g. check the $attachments variable within WC_GZDP_Legal_Page_Helper::attach_pdfs (var_dump( $attachments )).

    Cheers

    Thread Starter teresasumisu

    (@teresasumisu)

    I just found out, that no changes Ido to the Order Confirmation Mail in the WC settings are applied to the mail I’m sending within the ‘woocommerce_payment_complete’ action… neither Subject, nor Confirmation Text, Attachments etc… this seems to be a WC bug.
    I also tried the same thing in another WP installation, same problem.

    Plugin Author vendidero

    (@vendidero)

    Hi there,

    as I said, I’ve tested that successfully. You should try disabling other plugins and extensions before considering that as a bug..

    Cheers

    • This reply was modified 4 years, 4 months ago by vendidero.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘PDF Attachments when manually calling WC_Email_Customer_Completed_Order()’ is closed to new replies.