WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce PDF Invoices & Packing Slips
[resolved] add fields in the simple template from WooCommerce Checkout Manager (21 posts)

  1. max66max
    Member
    Posted 6 months ago #

    there is any way to add fields in the simple template from WooCommerce Checkout Manager ?

    http://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

  2. Ewout
    Member
    Plugin Author

    Posted 6 months ago #

    Yes, you can add any custom meta fields, you need a bit of php in the template:

    <?php
    $yourfield = get_post_meta($wpo_wcpdf->export->order->id,'Your field name',true);
    if (isset($yourfield)) {
    	echo $yourfield;
    }
    ?>

    where you replace 'Your field name' with the name of your checkout field of course :o)

  3. max66max
    Member
    Posted 6 months ago #

    I tried this

    <?php
    $email = get_post_meta($wpo_wcpdf->export->order->id,'billing_email',true);
    if (isset($email)) {
    echo '
    email:'.$email;
    }
    ?>

    no error but does not retrieve the email

  4. Ewout
    Member
    Plugin Author

    Posted 6 months ago #

    billing email is not a custom field, but a default woocommerce checkout field. I have a built in function to call the billing email:

    <?php $wpo_wcpdf->billing_email(); ?>

    the default woocommerce meta fields have a leading underscore, so it's _billing_email if you wanted to call it with the previously posted function:

    <?php
    $yourfield = get_post_meta($wpo_wcpdf->export->order->id,'_billing_email',true);
    if (isset($yourfield)) {
    	echo $yourfield;
    }
    ?>
  5. max66max
    Member
    Posted 6 months ago #

    email works, I added a new field in checkout-manager

    label Placeholder Choose Type Abbreviation
    Partita IVA Partita IVA Text Input piva

    tried

    <?php
    $yourfield = get_post_meta($wpo_wcpdf->export->order->id,'_piva',true);
    if (isset($yourfield)) {
    echo $yourfield;
    }
    ?>

    tried '_piva' or 'piva' or 'Partita IVA' or '_Partita IVA'does not work

    many thanks for the assistance

  6. Ewout
    Member
    Plugin Author

    Posted 6 months ago #

    The leading underscore is only for hidden fields like the woocommerce ones.

    What do you see if you go to the corresponding order? There's a tab there called "Custom Fields". You should enter what's displayed in the field "Name". There you can also check if the field actually received it's value correctly, because if there's nothing to display of course it won't. In theory it should be 'Partita IVA'. I tried on my test install with a field labeled "This is a test" and I used that in the code like this:

    get_post_meta($wpo_wcpdf->export->order->id,'This is a test',true);

    and it showed up properly.

    By the way, remember to put code on this forum between backticks, it's better!

  7. max66max
    Member
    Posted 6 months ago #

    it works thanks.
      there was a space character ' Partita IVA' instead of 'Partita IVA'

    thank you very much great plugin

  8. Ewout
    Member
    Plugin Author

    Posted 6 months ago #

    Ah, yes, those kind of typos are always so annoying! Good to hear it's resolved now.

    I'd really appreciate it if you leave me a review here!

  9. SimonBak
    Member
    Posted 5 months ago #

    Hello,

    I'm using "WooCommerce Custom Checkout Options" plugin to add custom fields on my checkout.
    And i use your plugin to send PDF after the orde and i want to add my custom fields on the PDF template.

    How can i do that ?
    Thanks for your help.

  10. Ewout
    Member
    Plugin Author

    Posted 5 months ago #

    Hi Simon,
    I don't know that plugin, but the steps are the same as above:
    1. find out the name of the custom field
    2. Use that field name in the following code (replace 'Your field name' with the correct name).

    <?php
    $yourfield = get_post_meta($wpo_wcpdf->export->order->id,'Your field name',true);
    if (isset($yourfield)) {
    	echo $yourfield;
    }
    ?>

    The field name should either be visible on the edit order page or in the database if it's a hidden field.

  11. SimonBak
    Member
    Posted 5 months ago #

    Ok i will try that.
    But where i have to put the code ?

    <?php
    $yourfield = get_post_meta($wpo_wcpdf->export->order->id,'Your field name',true);
    if (isset($yourfield)) {
    	echo $yourfield;
    }
    ?>
  12. Ewout
    Member
    Plugin Author

    Posted 5 months ago #

    Wherever you want it to appear in the template. Copy all the files from woocommerce-pdf-invoices-packing-slips/templates/pdf/Simple/ to yourtheme/woocommerce/pdf/yourtemplate/ to customize them, then they won't be overriden when you update the plugin later.

  13. SimonBak
    Member
    Posted 5 months ago #

    Thanks a lot for your help.
    It's perfect now.
    Have a good day.

  14. michaldybczak
    Member
    Posted 1 week ago #

    It doesn't work :(

    I have a child theme. I also use "WooCommerce Custom Checkout Options" where I added two custom fields:
    NIP (do fakury VAT)
    Rodzaj faktury

    I used the code as you posted above, that is:

    <?php
    $yourfield = get_post_meta($wpo_wcpdf->export->order->id,'NIP (do fakury VAT)',true);
    if (isset($yourfield)) {
    	echo $yourfield;
    }
    ?>

    The same for the other field.

    I added it to invoice.php and packing-slip.php. You didn't explained it more so I just added the code directly below the code that is in those files. Then I created a 'woocommerce' folder within my child theme directory and then inside another folder: 'pdf' , where I placed the modified files from above.

    What did I do wrong?

  15. Ewout
    Member
    Plugin Author

    Posted 1 week ago #

    Hello Michal,
    You write that you placed this 'below the code that is in those files', which probably means that the custom fields showed up somewhere below the footer or at the very end of the file, because the code outputs exactly where you place it.
    In your case, I can imagine you want to put it right after the recipient address:

    <div class="recipient-address"><?php $wpo_wcpdf->billing_address(); ?></div>

    Make sure that you use the correct path for the modified template! As per the instructions in the FAQ:

    How do I create my own custom template?
    Copy the files from wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/pdf/Simple/ to wp-content/themes/yourtheme/woocommerce/pdf/yourtemplate and customize them there. The new template will show up as 'yourtemplate' (the folder name) in the settings panel.

    Note the 'yourtemplate' part (which you can name 'Michal Custom' or anything else if you like). Also, you need to copy all files, not just the modified files.
    Then you select that modified template in the plugin settings.

  16. michaldybczak
    Member
    Posted 1 week ago #

    OK, I finally get it to work but on the document I see only what a customer puts in the field, there is no field name.

    Is there a way to make the name of the custom field visible? So instead for example:

    5468468462

    we would see:
    NIP (do fakury VAT): 5468468462

    And by the way, if some function of the plugin is available ONLY after putting custom code and modyfing files, that means that this function is NOT AVAILABLE in plugin, otherwise every plugin author could claim that every possible function is possible, all one needs to do is to put XYZ code.

    My idea to implement this function really would be to add a field in your plugin options: "name of the custom field" and plus sign "add new custom field" where one could place another name of the custom field. At the end: Apply to template: xxxxx.

    A proper code, file or whatever would be placed in chosen template. That way not programing skilled persons, like me, had easy way to add any custom field providing they put a correct custom field name.

    Taking into account that custom fields are quite often when using various plugins or through customizing woocommerce, this function would make your plugin extremely universal and adaptable :D. What do you think?

  17. Ewout
    Member
    Plugin Author

    Posted 1 week ago #

    Hello Michal,
    You can just type "NIP (do factury VAT):" in front of the code, it's as simple as that :o)
    If you only want to display the label when the field data is present, you can use a slightly altered code snippet:

    <?php
    $nip = get_post_meta($wpo_wcpdf->export->order->id,'NIP (do fakury VAT)',true);
    if (isset($nip)) {
    	echo 'NIP (do factury VAT): ' . $nip;
    }
    ?>

    I disagree with you that the function is NOT AVAILABLE in the plugin. I am not asking you to modify any core files, I have created a templating system that allows to you create a custom template completely to your liking. This is quite different from adding functionality to the plugin.
    You don't need programming skills to add the custom fields code, just some basic knowledge of HTML and a text editor. You type text like you normally would in a document, and add the code snippets where you want the custom fields to appear.

    What you propose is very complex to implement, programming wise, because there are many possible locations and formatting for these custom fields in the invoice. Moreover, it would impede the flexibility that the custom templating system currenly offers, because there would be much more code in the template. This is a choice I made, the template flexibility is a very important aspect of the plugin that also sets it apart from other PDF plugins on the market.

    That said, I agree with you that it would be nice to be able to add a custom field as easy as you suggest. I am tinkering with the idea to create a template editor that you can install besides the main plugin, and I think this would meet your wish to alter the contents of the invoices and packing slips more easily, while still maintaining the basic template flexibility of the plugin.

  18. Ewout
    Member
    Plugin Author

    Posted 1 week ago #

    I have a little surprise for you. I added a function that makes displaying a custom field a little bit more simple. If you update to the latest version of the plugin (1.4.3) you can use the following code:

    <?php $wpo_wcpdf->custom_field('NIP (do fakury VAT)', 'NIP (do fakury VAT):'); ?>

    The plugin only displays the field when it contains data. If you also want to display the label when the field is empty, you can pass a third parameter (true), like this:

    <?php $wpo_wcpdf->custom_field('NIP (do fakury VAT)', 'NIP (do fakury VAT):',  true); ?>
  19. michaldybczak
    Member
    Posted 1 week ago #

    OK, thanks for explanations :)

    Your idea about template editor sounds great! :)

    I'll adjust the code as you suggested.

    One thing is sure: this plugin has INCREDIBLE SUPPORT :D. You rock! :)

  20. michaldybczak
    Member
    Posted 1 week ago #

    Ooooo! Thanks man!

    Showing this field only when there are data in it is exactly what I need, because custom fields are optional, but important for some.

    GREAT! :)

  21. Ewout
    Member
    Plugin Author

    Posted 9 hours ago #

    Just for anyone reading this and trying to do the same, I'm copying the text that is now included in the FAQ too:

    How can I display custom fields in the invoice or packing slip?
    First, you need to create a custom template following instructions from the first item in this FAQ. Then place the following snippet where you would like the custom field to appear:

    <?php $wpo_wcpdf->custom_field('custom_fieldname', 'Custom field:'); ?>

    Where you replace 'custom_fieldname' with the name of the field you want to display, and 'Custom field' with the label. The plugin only displays the field when it contains data. If you also want to display the label when the field is empty, you can pass a third parameter (true), like this:

    <?php $wpo_wcpdf->custom_field('custom_fieldname', 'Custom field:',  true); ?>

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.