• Resolved bitfenix

    (@bitfenix)


    Hello

    How to insert different text on invoice depending on order email template (or by email status) with free plugin version if possible?
    For example: put ‘text 1’ on the invoice if it’s Processing order email template, and put ‘text 2’ on the invoice if it’s a Cancelled order email template/status. Also to change the filename depending on these two.

    I’ve tried something like

    add_action( 'wpo_wcpdf_after_order_data', 'insert_text', 10, 2 );
    function insert_text( $template_type, $order ) {
    	if ( $order->get_status() == 'cancelled' && $template_type == 'invoice' ) {
    		?>
    		<p>text2</p>
    		<?php
    	}
    }

    but didn’t work

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi @bitfenix,

    The code you’ve sent is actually working although it isn’t formatted correctly. The wpo_wcpdf_after_order_data hook lets you add an extra row to the order data table. So you will have to set it up like a table row:

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_custom_text_on_cancelled_status', 10, 2 );
    function wpo_wcpdf_custom_text_on_cancelled_status( $template_type, $order ) {
    	if ( $order->get_status() == 'cancelled' && $template_type == 'invoice' ) {
    		?>
    		<tr class="custom-order-data">
    			<th><?php _e( 'Your label:', 'wpo_wcpdf_custom' ); ?></th>
    			<td><?php _e( 'Your value:', 'wpo_wcpdf_custom' ); ?></td>
    		</tr>
    		<?php
    	}
    }
    Thread Starter bitfenix

    (@bitfenix)

    Thanks for the quick reply. Unfortunately, nothing happens. I’ve placed code in function file of child theme, and testing with Preview Emails plugin.
    Any suggestion and how to change the invoice file name depending on email status?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hello @bitfenix,

    Try replacing the code snippet that my colleague @kluver sent to you for this one:

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_custom_text_on_processing_cancelled_status', 10, 2 );
    function wpo_wcpdf_custom_text_on_processing_cancelled_status( $template_type, $order ) {
    	if ( $template_type == 'invoice' ) {
    		switch ($order->get_status()) {
    			case 'processing':
    				?>
    				<tr class="custom-message-order-processing">
    				<th><?php _e( 'Your label:', 'wpo_wcpdf_custom' ); ?></th>
    				<td><?php _e( 'Your value for processing status', 'wpo_wcpdf_custom' ); ?></td>
    				</tr>			
    				<?php
    				break;
    			case 'cancelled':
    				?>		
    				<tr class="custom-message-order-cancelled">
    				<th><?php _e( 'Your label:', 'wpo_wcpdf_custom' ); ?></th>
    				<td><?php _e( 'Your value for cancelled status', 'wpo_wcpdf_custom' ); ?></td>
    				</tr>			
    				<?php
    				break;
    		}			
    	}
    }

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Let me know if it works 🙂

    Thread Starter bitfenix

    (@bitfenix)

    Still not work unfortunately. Works if I remove a condition, but then it’s on all email templates. Tried with placing in template-functions.php too.
    Also, any advice for changing filename depending on status?

    Thread Starter bitfenix

    (@bitfenix)

    It’s something with email status because also works when this is removed from condition:

    && $order->get_status() == 'cancelled'

    • This reply was modified 5 years ago by bitfenix.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Could you try by selecting the Simple template under WooCommerce > PDF Invoices > Choose a template?

    If it works, so you’ll need to update your custom template.

    Please note this code is to add a custom message to the PDF invoices, not the WooCommerce notification emails 😉

    Thread Starter bitfenix

    (@bitfenix)

    Already tried switching to Simple default template, and it’s the same. (and also tried with different hooks)

    Yes, it’s about attached PDF invoice, not notification email 🙂

    • This reply was modified 5 years ago by bitfenix.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    I just saw that you edited your previous comment adding a line of the first code snippet.

    Please use the last code I sent you (this one) 🙂

    Thread Starter bitfenix

    (@bitfenix)

    Tried with both code snippets, but the same result unfortunately

    Plugin Contributor Yordan Soares

    (@yordansoares)

    That’s strange: the code is working for me without any issues (tested on orders with Processing and Cancelled statuses).

    Are you sure that the order where you’re testing is has the Processing or Cancelled status?

    If so, could you add this code snippet to check what order status is showing in red:

    add_action( 'wpo_wcpdf_after_order_data', function( $template_type, $order ) {
    	if ( $template_type == 'invoice' ) {
    		?>
    		<tr class="order-status">
    			<th><?php _e( 'Order Status:', 'wpo_wcpdf_custom' ); ?></th>
    			<td><?php printf(__( '<span style="color:red;font-weight:bold">%s</span>', 'wpo_wcpdf_custom' ), $order->get_status()); ?></td>
    		</tr>			
    		<?php
    	}
    }, 10, 2);
    Thread Starter bitfenix

    (@bitfenix)

    It’s definitely something with email status because it works ok when it is removed. I’ve also checked the email status slug, but slug was ok

    Gonna check your new snippet now

    • This reply was modified 5 years ago by bitfenix.
    Thread Starter bitfenix

    (@bitfenix)

    So :), no matter what status I check for testing http://prntscr.com/131wgfw in PDF this status is always “pending”. I’ve changed now to this in plugin settings http://prntscr.com/131wn8t and now works fine, it’s not always “pending” status.

    Thanks a lot!

    Could you please just write me about filename, is it possible to change it depending on email status? Or is this possible in premium plugin version?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    The Allow My Account invoice download setting give your customers the chance to download the invoice from their My account page, but if you choose the Always option, they will be able to generate an invoice even if the payments has not been processed yet. My recommendation is to choose the first option: Only when an invoice is already created/emailed.

    However, I don’t think this setting has something to do with your issue. What you need to check is if your test orders have the Processing or Cancelled status, and if the output of the latest code snippet I sent you match with it.

    If yes, maybe the code snippet that is working is not mine, but the one Michael sent to you. Or maybe did you try another one that is overriding it (?). If no, this behavior is something abnormal and needs to be fixed first.

    Could you please just write me about filename, is it possible to change it depending on email status? Or is this possible in premium plugin version?

    The Professional extension allows you to set up a custom filename for your documents, but this name will be applied globally for that document.

    For your specific case, you’ll need a code snippet to achieve what you describe. The good news is that when you have a license we can provide you help with this as part of our premium support 🙂

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I saw again one of your screenshots:

    But this appears to be the Send order email panel or other email plugin (is it maybe the Preview Email plugin that you mentioned previously?), instead of the order status dropdown:

    A screenshot that display the single order details highligthing the order statys

    This is the place where you need to set the new Processing or Cancelled status to test the code snippet, located on WooCommerce > Orders > Select an order.

    Let me know if you have success on testing the code snippet 🙂

    Thread Starter bitfenix

    (@bitfenix)

    Thank you very much for your support, now it works properly!

Viewing 15 replies - 1 through 15 (of 16 total)

The topic ‘Different text for different order emails’ is closed to new replies.