Hi guys,
here is a scenario we are trying to setup. We have a website with woocommerce installed. All products have a pdf file attachment field made with ACF. Its called “product_pdf”.
All products have a “Enquire Now” button that triggers a pop up form, where users have to fill up details and then submit.
What we need is, upon form submission users should be redirected to a thank you page, that has “download pdf” button. The pdf file should be the same as attached with the product. So basically it should change according to the product from where the user was sent to download page.
I would suggest you add a url-parameter to your Custom redirect URL Controls inside the form-element.
this could look something like this: https://your-site.com/thank-you/?download-pdf={post_id}
Now you have a dynamic url-parameter that contains the current-post / product id.
from here, you could either create a custom dynamic-data-tag that returns the acf-value depending on the url-parameter, or wrap the download-button in a custom query (PHP query editor), that takes the post_id and queries for only this post. Then you could just use the standard acf-field-dynamic-data-tag inside the button.
Both solutions should work and it’s up to preference. The ladder might be easier and could look something like this (PHP query editor):
Added this code to my functions.php file in bricks child theme-
3.----> add_filter(‘bricks/dynamic_data’, function ($value, $tag) {
// Check if the dynamic data tag is “custom_product_pdf”
if ($tag === ‘custom_product_pdf’) {
// Check if the URL has the “download-pdf” parameter
if (isset($_GET[‘download-pdf’])) {
$product_id = intval($_GET[‘download-pdf’]); // Get the product ID from the URL
// Fetch the ACF field value (replace 'product_pdf' with your actual ACF field name)
$pdf_url = get_field('product_pdf', $product_id);
// Validate and return the PDF URL
if ($pdf_url && filter_var($pdf_url, FILTER_VALIDATE_URL)) {
$value = $pdf_url;
} else {
$value = ''; // Return empty if no valid URL is found
}
} else {
$value = ''; // Return empty if no product ID is found
}
}
return $value;
}, 10, 2);
Added a download button to my thank you page - with dynamic link → {{ custom_product_pdf }}
when tested, the form redirects with the product id in the url, but the download button fails to render actual pdf link but instead show href=“{{ custom_product_pdf }}” instead.