ACF download PDF
-
Hello all,
I am using ACF to create custom field to download PDF files such as(brochure, manual) and put it in the woocommerce product custom tabs.
I have two types of PDF:
1-PDF link with existing URL
2-PDF uploaded to the wordpress media librarythis is what I have:
<?php add_filter( 'woocommerce_product_tabs', 'woo_literatures_tab' ); function woo_literatures_tab( $tabs ) { $tabs['literatures'] = array( 'title' => __( 'literatures', 'woocommerce' ), 'priority' => 50, 'callback' => 'woo_literatures_tab_content' ); return $tabs; } function generateDownloadButton($url) { return "<a href='$url'>Download</a>"; } function woo_literatures_tab_content() { $hasFile = false; echo "<ul>"; // Brochure with existing URL if (get_field('brochurePdfLink')) { $hasFile = true; $label = get_field('brochurePdfName'); $downloadButton = get_field('brochurePdfLink'); echo "<li><a href='$downloadButton' target='_blank' rel="noopener"><h5>$label</h5></a></li>"; } // Brochure uploaded to the wordpress media library if (get_field('brochurePdfUrl')) { $hasFile = true; $obj = get_field_object('brochurePdfurl'); $label = get_field('brochurePdfName'); $url = $obj['value']['url']; $downloadButton = generateDownloadButton($url); echo "<li><div class='download-btn-cont'><h5>$label</h5> $downloadButton</div></li>"; } echo "</ul>"; if (!$hasFile) { echo "<h5>The product doesn't have any attachments</h5>"; } }
The function (// Brochure with existing URL) is working correctly. But (// Brochure uploaded to the wordpress media library) is not getting the file link from the media library and display nothing, it only redirect me to the current page with nothing more.
Please let me know what is wrong and how to fix it. Thank you in advance for your help.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘ACF download PDF’ is closed to new replies.