Skip Navigation

[Résolu] Display Fields with PHP

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How can I display a Custom Field created with Toolset Types, using PHP?

Solution:
Either you can use the native WordPress function `get_post_meta()` or our own Types API function `types_render_field()`

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://toolset.com/documentation/customizing-sites-using-php/functions/

0% of people find this useful.

This support ticket is created Il y a 6 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : ,

This topic contains 5 réponses, has 3 voix.

Last updated by ThierryR232 Il y a 6 années et 2 mois.

Assisted by: Beda.

Auteur
Publications
#607901
packing-slip.jpg

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:
hidden link
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?

#608188

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!

#608198
detail-invoice-pdf.jpg
pdf.jpg

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

#608206

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

#609118
code.jpg

hi Beda,

we (my husband and I) worked hard on it this day, and we managed it!
See our code 🙂

#1121642

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 : hidden link but don't work. How i can do this ? Thx.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.