Looking for assistance with a plugin development project involving PDF generation using AJAX. The challenge lies in generating multiple PDFs for each user within a loop.
The goal is to create PDFs with multiple pages for individual users. If that's not feasible, then separate PDFs per user will suffice.
The current code seems to be only producing one page for the first user in the loop, followed by a blank page and halting the process.
Check out the mPDF Library for more information.
Data
Array
(
[group_name] => Food Lovers
[group_admin] => John Doe
[identifier] => AtR4deAVgU4Ensi1_1ac2b33a4df7c5f0cf148d6232074352
[group_order_number] => 1615962332298
[start_date] => 2021-03-20
[group_user_ids] => Array
(
[0] => 63
[1] => 73
[2] => 83
)
[63] => Array
(
[products] => Array
(
[0] => stdClass Object
(
[id] => 100
[order_number] => 2021031729863
[group_order_number] => 1615962332298
[product] => 100
[product_option] =>
[qty] => 6
[group_id...
Callback Function
function gs_group_users_order_pdf_generator_ajax()
{
// Implementation details for handling AJAX requests
...
}
// Attaching the function to AJAX hooks
add_action('wp_ajax_gs_group_users_order_pdf_generator', 'gs_group_users_order_pdf_generator_ajax');
add_action('wp_ajax_nopriv_gs_group_users_order_pdf_generator', 'gs_group_users_order_pdf_generator_ajax');
Javascript
Calling function
// Initiating PDF generation on click event
$(document).on('click', '.gs-guo-pdf-orders', function () {
if (confirm('Are you sure you want to generate group users order PDFs?')) {
ajax_process.call(this, '', 'gs_group_users_order_pdf_generator', 'fa-window-close');
}
});
Complete Javascript
(function ($) {
$(function () {
...
});
})(jQuery);
HTML for Button
<button class="gs-guo-pdf-orders btn btn-sm btn-outline-info ml-3" type="button" title="Generate Group Users Order PDFs"
data-ordernum="1615962332298" data-gid="298" data-gadmin="72" data-identifier="AtR4deAVgU4Ensi1_1ac2b33a4df7c5f0cf148d6232074352">
<i class="fas fa-copy"></i></button>