How to Pass [e2pdf-wc-order key="get_id"] Output to Another Shortcode’s Attribute

9 January, 2025 11:37:25
eliodata
Topics: 17
Messages: 51
Hello,

I’m trying to retrieve the current WooCommerce order ID inside my own custom shortcode when generating a PDF automatically.

If I place [e2pdf-wc-order key="get_id"] by itself in the template, it correctly displays the current order ID (for example, “268259”).

Also, if I manually hardcode [fsbdd_all_days order_id="268259"], it works perfectly for order ID 268259, and displays the full planning from my custom CPT.

However, if I attempt to do:

csharp
Copier le code
[fsbdd_all_days order_id="[e2pdf-wc-order key='get_id']"]
the ID does not get passed to my shortcode. Essentially, my shortcode does not receive the correct order ID.

How can I ensure that the value returned by [e2pdf-wc-order key='get_id'] is properly passed as the order_id attribute to my custom shortcode [fsbdd_all_days]?

Thank you in advance for your help!
9 January, 2025 12:36:28
E2Pdf
Support
Topics: 7
Messages: 3377
Hello,

Unfortunately, WordPress doesn't support nested shortcodes as attributes by default. However, it is possible to accomplish this task with some modifications to your shortcode function and additional PHP code:

1. Your shortcode should be modified to use the inner content as follows:

[fsbdd_all_days][e2pdf-wc-order key="get_id"][/fsbdd_all_days]

To do so, the shortcode function should be modified as follows:

https://codefile.io/f/uczvKXh78T

2. A filter should be added to your theme's functions.php file or as a PHP snippet to allow the shortcode to work as nested in the E2Pdf Template:

https://codefile.io/f/By0gUpCZDM

We would really appreciate your feedback at WordPress.org!
10 January, 2025 01:10:01
eliodata
Topics: 17
Messages: 51
Best support ever, as usual!
Thank you guys :)