Hi,
I have a question about rendering fields in a PDF file from the plugin WooCommerce PDF Invoices & Packing Slips
I want to customize the packing slip into a certificate.
We want to send this to the participants after attending the event. I thought this would be the easiest way to send them a personalised certificate. We don't need the packing slip as it is only a virtual product.
here you see the product (event) in WooCommerce:
enlace oculto
I would like to display the date (and other fields) on the PDF file of the packing slip.
I wrote this code in the packing-slip.php
Datum: <?php echo(types_render_field("startdatum")); ?>
Unfortunately it is not working. Is this crzay idea of mine even possible?
A PDF would be a file that you read on your desktop, hence you have two download it from somewhere.
You cannot execute PHP or ShortCodes or anything similar in a PDF on a Desktop.
You can, however, do that when you produce the content of the page in a website, or when you (somehow) generate your PDF file in a process that involves a Server, where PHP can be executed.
This means, you can use the API you tried only in Theme or Plugin's Files, in a WordPress install.
Not on common PDF's.
If I misunderstood you please do not hesitate to update the ticket!
The PDF is generated by clicking on an icon under orders, from WooCommerce customers. So, how can the pdf generate the fields from the product and no other fields?
see the detail of de invoice.php.
I was hoping that I can add some extra fields.
kind regards
Hmm, it seems in this file you should be able to add your own PHP calls to the database, hence it should be possible to pass Post Information, but the issue probably is that the Post Object is not there.
This is not a Post, it's a PDF of something (eventually of a post, but not a post itself)
So this means you would need to tell the code where to look for the information.
This is done for example by passing the ID of the Post you want to get the Field information from, in types_render_field it's "id=" and in get_post_meta() (which types_render_meta() uses itself) it's simply an integer:
https://developer.wordpress.org/reference/functions/get_post_meta/
If this does not work, it means it's too late at the stage of this script to have Post information.
You can make a few tests:
- hardcode something in the file (a string) to see where it is output
- then replace the string with let's say a $variable you are sure that exists (could be a Post Title, called by ID)
- if that works then also Post Fields will work
hi Beda,
we (my husband and I) worked hard on it this day, and we managed it!
See our code 🙂
Hello,
I want displaying a custom field in my pdf invoice (with this plugin : https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
I read this : enlace oculto but don't work. How i can do this ? Thx.