How to execute a php function into pdf template

WordPress
December 18, 2021 05:13:38
DanielPG
Topics: 1
Messages: 3
Hi,

First of all, congratulations for this plugin, it's useful and powerful.

I'm using WordPress and I need execute a php function called "showProductsPDF()" located in "functions.php" file. I created a shortcode for this php function with the sentence: add_shortcode('products', 'showProductsPDF'); so I've got the shortcode [products] ready for use, but I tried to run it without success.

I tried this three ways, but they didn't run:

[products]
[e2pdf-wp key='products']
[products id="[e2pdf-dataset]"]

Could you help me? thanks a lot.

Best Regards
December 18, 2021 06:05:21
E2Pdf
Topics: 7
Messages: 3617
Support
Hi, thank you.

It must work if you have correct function. Check please this example: https://codeshare.io/wnlZoD.

It's custom shortcode code which can be used inside E2Pdf Template as:

[show_products]
[show_products id="[e2pdf-dataset]"] - If you need to get also Post/Page ID inside function. It will be assigned to $id inside function.

P.S. Keep attention that shortcode function must "return" value and not "echo".
P.P.S. We used "show_products" instead of "products" as if you will install WooCommerce, [products] will not work as it's WooCommerce internal shortcode.

We remain at your service.

We would really appreciate your feedback at WordPress.org!
December 18, 2021 10:50:54
DanielPG
Topics: 1
Messages: 3
Great!, your answer was really fast and detailed.

I'm trying to run your code proposed, but I've got another dummy issue:

How could I set 'id' key into dataset shortcode? As you can see, there are three levels of nested quotation marks:

do_shortcode( "[e2pdf-view id='1' dataset = ' [e2pdf-wp key='id'] ' ]" );

Thanks so much!
December 18, 2021 23:11:06
E2Pdf
Topics: 7
Messages: 3617
Support
Hi,

Inside PHP context it must be used PHP code and not wordpress shortcodes.

It must be used something like: echo do_shortcode("[e2pdf-view id='1' dataset = '" . $post_id . "' ]");

* where $post_id - is the ID of Page/Post and its usage depends inside which filter or where it's used.

For example:

global $post;
$post_id = $post->ID;
echo do_shortcode("[e2pdf-view id='1' dataset = '" . $post_id . "' ]");

But it's very depend on where and how this code called so this code may not work.

We remain at your service.

We would really appreciate your feedback at WordPress.org!
December 19, 2021 10:29:53
DanielPG
Topics: 1
Messages: 3
Great! it runs perfectly, the final result is nice and awesome.

Thanks again for the quickness and precision of your answer, your plugin is really amazing!
Get News and Updates
Our monthly newsletter keeps you in the loop, so you'll always be up to date with the latest news and updates about E2Pdf.
* You can update your email subscription preferences here.
All trademarks, service marks, trade names, product names, and logos appearing on this website are the property of their respective owners. The use of trademarks such as Formidable Forms®, Forminator Forms®, Gravity Forms®, JetFormBuilder®, WordPress®, WooCommerce®, WPForms® and others is solely for identification purposes (nominative use) and does not imply any affiliation, sponsorship, or endorsement by the respective trademark holders.
© 2017 - 2026, https://e2pdf.com

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. By clicking "Accept Selected", you consent to use of selected cookies according to our Cookie Policy.