• Resolved doctordisco

    (@discomidget)


    Hi, I read the FAQ and support guides and forum, but didn’t see this issue. I followed your great guide to use code snippets to add a meta custom field to invoices. It looks great when I generate it from the Woocommerce orders page (under actions) and I can see the custom field correctly. The previews in the PDF Invoices plugin show the field correctly. I have the invoice set to attach to: New order (Admin email). But that invoice pdf doesn’t have the custom field.

    I tried checking the box ‘ Always use most current settings ‘ in settings: documents, but it didn’t help. Please let me know what I can share or what I should try. THANKS!

    If I can share the code that I have in code snippets, please let me know if there is a preferred way other than to paste it in this text.

    The page I need help with: [log in to see the link]

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @discomidget,

    Maybe your custom field is filled after the order is placed? If so, you could send the PDF invoices in a later stage, e.g. when the order has reached the?Processing?or?Completed?status.

    Thread Starter doctordisco

    (@discomidget)

    Hello,

    Thanks for your quick reply. How could I send the PDF invoices in a later stage? It is automated. Do you mean manually? Or in settings/documents, under the Attach to: it says Disable for: ‘Select one or more statuses’. Is this what you mean? Or is that something I would enter in code? Do I want Woocommerce to wait to send the order email – New order (Admin email) so that it does so after the custom field has been added to the invoice?

    I forward the New order email with the pdf invoice attached to the office once I check the order details. I added the custom field with a second sku number that helps to identify the product on the shelf (we also have a physical retail store).

    At this point, I am opening the New order email, deleting the attached pdf invoice, logging into WordPress, downloading the pdf invoice and attaching it to the new order email that I forward to the office. Hopefully there is something I can do so that the PDF invoice that goes into the automated New Order email appears the same as the PDF invoice in Woocommerce.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    How could I send the PDF invoices in a later stage? It is automated. Do you mean manually?

    The way our free plugin creates an invoice automatically is when you select order email notifications in which it will be attached, under?WooCommerce > PDF Invoices > Documents > Invoice > Attach to: The attachment process will create an invoice document with its respective number:

    A screenshot that displays the Attach to setting

    Please note that the New order email notification is sent immediately, just right after the order has been placed.

    I forward the New order email with the pdf invoice attached to the office once I check the order details. I added the custom field with a second sku number that helps to identify the product on the shelf (we also have a physical retail store).

    For this purpose, you could use the?Order Notification,?included in the?Professional extension. This notification allows you to send PDF documents copy to another email address(es), based in a trigger, e.g. when the order reaches the?Completed?status.

    That said, since WordPress doesn’t allow us to provide support or answering pre-sale questions for paid plugins in this forum, please contact us by email at [email protected].

    Thread Starter doctordisco

    (@discomidget)

    When I look into the Woocommerce settings, it looks like Processing and Completed go to the customer. I don’t see a simple way to add my admin email to those. It wouldn’t make sense for my customers to receive the invoice with the custom sku.

    I will definitely contact you by email to find out more about if the paid version is what I need.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    The Order Notification email seems to be what you are looking for. This is a new separated email notification, not a copy of the Completed or Processing notifications. See Configuring the Order Notification email

    That said, you can also check this article, if you just need a copy of those email notifications: Receive a copy of each invoice sent by email

    Thread Starter doctordisco

    (@discomidget)

    I followed the directions to receive a ‘bcc’ of the order notification for ‘processing’ that is sent to the customer. The invoice attached to that email is the same as the one attached to the ‘new order.’ Initially you were saying,

    Maybe your custom field is filled after the order is placed? If so, you could send the PDF invoices in a later stage, e.g. when the order has reached the Processing

    Again, after customization, when I click on the ‘action’ in orders, the invoice has my custom field, but the invoices attached to ‘new order’ and ‘processing’ don’t have the custom field.

    If the solution for this is the paid version of the plugin, I will respond further in email.

    • This reply was modified 1 year, 5 months ago by doctordisco.
    • This reply was modified 1 year, 5 months ago by doctordisco.
    • This reply was modified 1 year, 5 months ago by doctordisco.
    Thread Starter doctordisco

    (@discomidget)

    I have not been having success communicating via email. It was recommended that I do so because some of the answers may have been to suggest the paid plugin. After following the link below to add a custom field added with a code snippet, the invoices attached to ANY email do not show the custom field. However, when I click on the icon in the Woocommerce orders area, THAT invoice shows the custom field. I have tried the recommended troubleshooting and not been able to reason why the backend invoice and email attached invoice are different.

    https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-product-custom-fields/

    since WordPress doesn’t allow us to provide support or answering pre-sale questions for paid plugins in this forum

    
    
    Using an action hook
    If you’ve never edited your themes functions.php before, make sure to read this first.
    
    Let’s say your custom field is called ‘Location’, you can display this below the product description with the following code:
    
    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
    
    function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
    
        // check if product exists first
    
        if (empty($item['product'])) return;
    
        // replace 'Location' with your custom field name!
    
        $field_name = 'Location';
    
        $location = $item['product']->get_meta($field_name,true,'edit');
    
        if (!empty($location)) {
    
            echo '<div class="product-location">Location: '.$location.'</div>';
    
        }
    
    }

    • This reply was modified 1 year, 5 months ago by doctordisco.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @discomidget,

    This behavior has only sense if the value is added in a later stage, as I mentioned already.

    Could you please tell me what kind of custom field is this (a product, item, or order field), and how are you filling it, so I can try to understand what is happening?

    Thread Starter doctordisco

    (@discomidget)

    Thanks very much for replying. This is a meta custom field ‘ sku_RE ‘ that is a second sku number. I added it by exporting the products as csv, adding a meta column and importing. If I need to add or change that field, I repeat the export to csv, edit and import.

    After adding the action hook code snippet above, the meta custom field ‘ sku_RE ‘ appears on invoices from the Woo backend but not on any email, regardless of stage.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    This is a meta custom field

    Do you mean a product custom field?

    …the meta custom field ‘ sku_RE ‘ appears on invoices from the Woo backend but not on any email, regardless of stage.

    Just to clarify, are you referring to the PDF invoice attached to the email notification or the email body?

    Thread Starter doctordisco

    (@discomidget)

    Following the steps from the link above: displaying-product-custom-fields/

    It is a product custom field that has meta in front of it – Meta: sku_RE I added ‘sku_RE’ in place of ‘Location’ in the code provided.

    add_action( 'wpo_wcpdf_before_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
    function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
        // check if product exists first
        if (empty($item['product'])) return;
      
        // replace 'Location' with your custom field name!
        $field_name = 'sku_RE';
        $sku_RE = $item['product']->get_meta($field_name,true,'edit');
        if (!empty($sku_RE)) {
            echo '<div class="product-sku_RE">sku_RE: '.$sku_RE.'</div>';
        }
    }

    When I tried it with ‘Meta:’ in front of it, it gave an error.

    To clarify, I am referring to the PDF invoice attached to the email.

    Thank you for your help.

    Thread Starter doctordisco

    (@discomidget)

    Thank you for your reply.? Based on your comments, I found a possible issue.? I had the snippet set to ‘ administration area ‘

    ?? ?Run snippet everywhere ?
    x? Only run in administration area ?
    Only run on site front-end ?
    Only run once

    I have changed it to ‘ run everywhere ‘  let me see if that allows the emails to have the correct PDF attached.

    Thanks again for your help. This is my first experience with php and code snippets.

    -Kevork

    Thread Starter doctordisco

    (@discomidget)

    I cautiously (and incorrectly) had set the snippet to only run in the administration area. Once I changed it to ‘run snippet everywhere’ I am receiving invoices with custom product field attached to emails. THANK YOU very much for all of your help!!!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @discomidget,

    I’m glad to hear that you managed to make it work.

    Let us know if you need anything else.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Custom field hook not appearing in PDF attached to email’ is closed to new replies.