Support » Plugin: WooCommerce PDF Invoices & Packing Slips » pdf attach terms and conditions to email

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Ewout

    (@pomegranate)

    Yes it is possible, but it’s not within the scope of this plugin. You can use the woocommerce_email_attachments filter and copy some of the code used in the plugin to your functions.php, like this:

    add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
    
    function attach_terms_conditions_pdf_to_email ( $attachments, $status , $order ) {
    	$allowed_statuses = array( 'new_order', 'customer_invoice', 'customer_processing_order', 'customer_completed_order' );
    
    	if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
    		$your_pdf_path = get_template_directory() . '/terms.pdf';
    		$attachments[] = $pdf_path;
    	}
    
    	return $attachments;
    }

    I did not test this code so I cannot guarantee it works, but the basic principle is there.

    @ewout, ‘customer_processing_order’, after updating the status manually in the Admin, doesn’t seem to work, although ‘customer_completed_order’ does.

    My site is using the BACS gateway, and WooCommerce sets the default status for a new order using BACS to “on-hold”, which isn’t in your list above or the list at http://www.mootpoint.org/blog/customising-woocommerce-notification-emails-hooks-filters/.

    Any suggestions to attach the PDF when the gateway is BACS?

    Thank you in advance.

    Plugin Author Ewout

    (@pomegranate)

    Hello Paul,
    Sending static files is now a feature of the Professional extension.

    WooCommerce does not send an email for on-hold orders, so there’s nothing to attach to. You could add a trigger to email the “customer_invoice” email after an order is set to on-hold and the payment method is bacs, but that is something you will have to figure out in WooCommerce. This plugin can only attach a PDF to existing WooCommerce emails.

    Good luck!
    Ewout

    Ewout,

    Thank you for the quick reply. It seems to me that WooCommerce DOES in fact send an email for on-hold orders. The site I inherited from another developer sends an email that says the following, and then calls the functions “email_instructions()” and “order_details()”:

    “Your order has been received and is now being processed. Your order details are shown below for your reference: Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won’t be shipped until the funds have cleared in our account.”

    “Make your payment…” is from line 82 in “woocommerce/includes/gateways/bacs/class-wc-gateway-bacs.php”. See also the implemented action hook on line 54:
    add_action( ‘woocommerce_thankyou_bacs’, array( $this, ‘thankyou_page’ ) );. And on line 57:
    // Customer Emails
    add_action( ‘woocommerce_email_before_order_table’, array( $this, ’email_instructions’ ), 10, 3 );

    There is nothing in his code anywhere that sends the email to the customer. Woocommerce is.

    In my customized “thankyou.php”, I am already sending a second email using “wp_mail()”, and attaching a dynamically created PDF invoice. But I would prefer to send only the first email and attach the invoice to it.

    Please respond. Thanks.

    Ewout,

    Please also note “Account Details” below from: “http://docs.woothemes.com/document/bacs/”

    BACS has the following settings:

    Enable/Disable – Enable or disable the BACS gateway.
    Title – Choose the title which the user is shown during checkout.
    Customer Message – Add a custom message shown to the user if they choose BACS.
    Account Details – Optionally enter account details shown to the user on the thanks page and in order emails after checking out with BACS chosen.

    Ewout,

    Please also see “http://[your site]/wp-admin/admin.php?page=wc-settings&tab=email&section=wc_email_customer_processing_order”.

    Or accessed from Admin > Woocommerce > Settings > Emails tab, “Processing order” area:
    Enable/Disable Enable this email notification.

    When enabled is checked, the email I described above is sent.
    When disabled only my email with the attached PDF invoice is sent. Perfect.

    But I would still like to hear back from you about how Woocommerce functions, or doesn’t, in this regard.

    Thanks.

    Plugin Author Ewout

    (@pomegranate)

    Hello Paul,
    I stand corrected, WooCommerce does indeed send out an email for BACS, it appears to be the processing email. I am not sure what your question is though, it should work when you attach the PDF to the processing email. You don’t even need extra function for this at all – you can just check the checkbox in front of “Customer Processing Order email”. This will work for both the regular processing emails and the automatic BACS “on-hold” processing emails (tested and confirmed), it’s just that it won’t send the email a second time when moving from on-hold to processing manually.

    Ewout

    Ewout,

    My solution is to disable Woo’s processing email in the Admin, as noted above, and only send my email and its dynamically created PDF invoice, in my customized “thankyou.php” script.

    My original question was how can I attach a PDF file to the BACS processing email using the filter hook in the function “get_attachments()”, from line 247, in “plugins/woocommerce/includes/abstracts/abstract-wc-email.php”, that you used in your original answer at the top of this page.

    Aside from using my solution, and without using your plugin, how would I attach the PDF to the processing email?

    There is no field “Customer Processing Order email”.

    Plugin Author Ewout

    (@pomegranate)

    I’m not sure I understand. Without using my plugin it’s not possible at all to create an invoice, unless you use another plugin, in which case you will have to consult the maker of that plugin. The field “Customer Processing Order email” is on the General settings tab of this plugin.

    Ewout,

    I created a dynamic HTML invoice, and used DOMPDF to create the PDF version, and then used “wp_mail() to email and attach the invoice, all in my customized version of “thankyou.pdf”.

    My question was about your code at the top of this thread.

    Why do you say that without using your plugin it’s not possible at all to create an invoice, when I have done just that?

    Please respond to my question about the code at the top of the thread.

    Thanks.

    Plugin Author Ewout

    (@pomegranate)

    That explains, then you are the maker of that plugin that i mentioned in my last post :o)
    This is the forum for the WooCommerce PDF Invoices & Packing Slips plugin.
    I believe I have already answered your question. ‘customer_processing_order’ is the email type / ‘status’ you need. I also wrote that this will not work when you change the status manually from on-hold to processing, because WooCommerce will only send the email once.

    If you have any questions about WooCommerce PDF Invoices & Packing Slips I’d be happy to answer them, but I can’t be expected to help you with your custom code that has nothing to do with this plugin.

    Ewout,

    Sorry to disappoint you 🙁 but I am not the creator of that plugin :).

    My question above and my comment below have everything to do with your plugin and helping its users.

    See “http://www.remicorson.com/change-the-orders-default-status-by-gateway-in-woocommerce/”, where Remi shows “how to change the WooCommerce orders default status by payment gateways. For example, when you make a purchase and use the BACS payment (bank transfer), the default order status is ‘on hold’, but you could choose to automatically mark the status as ‘processing’ instead.”

    I haven’t tried your code at the top of this thread with Remi’s fix, but I am sure they would work together.

    And so the user who started this thread now has a solution.

    I am sticking to my current working solution, which isn’t a plugin, but maybe will be one day LOL.

    Plugin Author Ewout

    (@pomegranate)

    Paul, users of my plugin have an option to attach the PDF invoice to the processing order: simply by checking the “Customer Processing Order email” option. That is why your question (which is about your custom PDF invoice plugin) is irrelevant – users of this plugin do not have this issue.
    Also, nothing needs to be changed in WooCommerce for this to work, please follow along:

    1. As soon as an order is placed it is set to pending. This is true for all orders, regardless of the payment method
    2. When BACS is used, the status is then set to on-hold
    3. In the WC_Email_Customer_Processing_Order class, you can see that there are two trigger actions for this email:
      woocommerce_order_status_pending_to_processing_notification and woocommerce_order_status_pending_to_on-hold_notification. That last action applies to the automatic change between 1. and 2. above.
    4. The get_attachments() function from the WC_Email class passes the id of the email, which is customer_processing_order (see: $this->id in WC_Email_Customer_Processing_Order) for the “processing” email. And so, if you want to attach anything to the BACS email, you use this id (called ‘status’ in my plugin, which may be confusing, since it is not just the end status that triggers an email).
    5. You imply that it is not possible to attach to the BACS email, but I think that is because you moved to the on-hold status manually. As you can see above, that only works if you move from pending to on-hold – which is what happens if you place a BACS order

    The original question was fully answered 11 months ago. Attaching a static file to any WooCommerce email is now a feature of the Professional extension.

    Ewout,

    I did not move to the on-hold status manually, and there is no way to do so from what I can see in the Admin Orders section. Besides, I would need to do it programmatically, not manually.

    And there is no action hook for “woocommerce_order_status_on-hold_to_processing_notification”. Hence the value of Remi Corson’s post.

    Obviously, you are correct in pointing out that this thread is no longer relevant to users of your plugin’s Professional version.

    I arrived here trying to finding a solution to my problem, which your code at the top of the thread seemed to offer.

    Plugin Author Ewout

    (@pomegranate)

    there is no action hook for “woocommerce_order_status_on-hold_to_processing_notification”

    There is:
    If you look in abstract-wc-order.php, you’ll find:

    do_action( 'woocommerce_order_status_' . $old_status . '_to_' . $new_status, $this->id );

    Which means that there’s an action hook for every status transition you can think of.

    I did not move to the on-hold status manually, and there is no way to do so from what I can see in the Admin Orders section.

    You can set any status manually, just not in bulk. If you go into the order you can manually set every state (and thus simulate all state transitions).

    By the way, if you apply that hack from Remi Corson, it won’t include the bank details in the email anymore, since that is only included when the status is on-hold! You can add this by changing copying the email_instructions function into the WC_Gateway_BACS_custom class and modifying the status requirement.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘pdf attach terms and conditions to email’ is closed to new replies.