Woocommerce foreach/get_items issue

Help Desk ›› How to ›› Woocommerce foreach/get_items issue
WooCommerce
21 May, 2024 04:19:48
underdog
Topics: 6
Messages: 20
I'm having trouble outputting the list of products from an order on a PDF. I've copied the shortcode example from the Woocommerce Autofill template into my template but every time I save my field the foreach shortcode moves and open and closes at the top of the field which then breaks the output on the pdf. I've checked over the code but I just can't see what I'm doing wrong. Here's my code in the field:

<table class="minimalistBlack">
<thead>
<tr>
<th>Qty</th>
<th>Description</th>
<th>Material</th>
<th>Total Net Weight(kg)</th>
<th>Total Gross Weight(kg)</th>
<th>HS Tariff Code</th>
<th>Country of Origin</th>
<th>Total Value</th>
</tr>
</thead>
<tbody>
[e2pdf-foreach shortcode="e2pdf-wc-order" key="get_items"]
<tr>
<td class="item">
[e2pdf-wc-product key="get_quantity" index="[e2pdf-foreach-index]" order="true"]
</td>
<td>
[e2pdf-wc-product key="get_name" index="[e2pdf-foreach-index]" order="true"]
</td>
<td>
[e2pdf-wc-product key="get_attribute" attribute="material" show="value" index="[e2pdf-foreach-index]"]
</td>
</tr>
[/e2pdf-foreach]
</tbody>
</table>

I've attached images of the issue I'm having when I save the field and the resulting PDF output. Hope you can guide me on how to fix this!
21 May, 2024 04:23:06
E2Pdf
Support
Topics: 7
Messages: 3331
Hello,

Try please to check please the "Disable WYSIWYG Editor" option in the "HTML" object properties, and re-copy your HTML code directly to the "Value".
We would really appreciate your feedback at WordPress.org!
21 May, 2024 05:06:43
underdog
Topics: 6
Messages: 20
Thank you for the quick reply. I have done this but not there's no product item output at all on the pdf. I've attached images of the field.
21 May, 2024 05:11:05
E2Pdf
Support
Topics: 7
Messages: 3331
Can you please share the code somewhere so we can see it, for example at https://codefile.io/ or at https://codeshare.io/ that is used inside value?

Also, is your E2Pdf Template connected to "WooCommerce" -> "Orders"?
We would really appreciate your feedback at WordPress.org!
21 May, 2024 05:29:39
E2Pdf
Support
Topics: 7
Messages: 3331
The code looks correct and is working for us.

Can you also please share the CSS?

You can also try to remove: [e2pdf-wc-product key="get_attribute" attribute="material" show="value" index="[e2pdf-foreach-index]"] to see if it will be any changes.

P.S. As an alternative, you can submit us a support ticket with access details here so we can do checks directly on your side: [hidden]


We would really appreciate your feedback at WordPress.org!
21 May, 2024 06:00:08
E2Pdf
Support
Topics: 7
Messages: 3331
Just be sure that you are closing all tags correctly and not missing "quotes" over attributes:

[e2pdf-wc-product key="get_weight" index="[e2pdf-foreach-index]"]
We would really appreciate your feedback at WordPress.org!
22 May, 2024 03:16:27
underdog
Topics: 6
Messages: 20
Thanks for your assistance this that has really helped me. I have another query:

Using the Woocommerce extension is there a way I can filter out products from a certain category and stop them displaying within the [e2pdf-foreach shortcode="e2pdf-wc-order" key="get_items"] shortcode?
22 May, 2024 08:54:09
E2Pdf
Support
Topics: 7
Messages: 3331
Hello,

It must be possible to accomplish this with the latest RC version: 1.24.07: https://e2pdf.com/docs/install#rc-version.

After update, the code would be as follows: https://codefile.io/f/Vl8cHAOEFc

There is a new block added to the code with [e2pdf-if] condition:

[e2pdf-if]
[e2pdf-condition]Category 2[not_in_array][e2pdf-wc-product key="get_category_ids" order="true" index="[e2pdf-foreach-index]" convert="term_id_to_name"][/e2pdf-condition]
[e2pdf-do]
<tr>
<td class="item">
[e2pdf-wc-product key="get_quantity" index="[e2pdf-foreach-index]" order="true"]
</td>
<td>
[e2pdf-wc-product key="get_name" index="[e2pdf-foreach-index]" order="true"]
</td>
<td>
[e2pdf-wc-product key="get_attribute" attribute="material" show="value" index="[e2pdf-foreach-index]"]
</td>
</tr>
[/e2pdf-do]
[/e2pdf-if]

Explanation:

It checks if Category 2 is not in the List of Categories, retrieved by shortcode: [e2pdf-wc-product key="get_category_ids" order="true" index="[e2pdf-foreach-index]" convert="term_id_to_name"]. And if not, it processes shortcodes in the [e2pdf-do] block.


We would really appreciate your feedback at WordPress.org!