How to execute a php function into pdf template

WordPress
18 December, 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
18 December, 2021 06:05:21
E2Pdf
Support
Topics: 7
Messages: 3330
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!
18 December, 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!
18 December, 2021 23:11:06
E2Pdf
Support
Topics: 7
Messages: 3330
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!
19 December, 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!