Get PDF URL (Not entire Shortcode)

Help Desk ›› How to ›› Get PDF URL (Not entire Shortcode)
WooCommerce
2 November, 2021 09:29:01
PGK37
Topics: 1
Messages: 1
Hello

Is it possible to only retrieve the URL to a PDF and not the entire "shortcode" that generates the "Download" link?
Like this for example:

---------------

<?php
// GET URL FONCTION
global $product;
$id = $product->get_id();
$dataset_id = $id;
$pdf_path = do_shortcode('[e2pdf-download id="1" dataset="'.$dataset_id.'" apply="true"]');
?>


<a href="<?php echo $pdf_path; ?>" title="Télécharger la fiche technique" class="btn btn-outline-light btn-sm"><i class="far fa-file-pdf"></i> Fiche technique</a>

-------------

Thanks for your help

2 November, 2021 11:51:26
E2Pdf
Support
Topics: 7
Messages: 3335
Hi,

Yes, it's possible. You must use "output" attribute as:

$pdf_path = do_shortcode('[e2pdf-download id="1" dataset="'.$dataset_id.'" output="url"]');

or direct shortcode as

[e2pdf-download id="1" output="url"]

P.S. In case if you will need to send this URL to some other API and not output directly as it's showed in your example - you will need to define "esc_url_raw" attribute as by default entities (&) will be encoded:

$pdf_path = do_shortcode('[e2pdf-download id="1" dataset="'.$dataset_id.'" output="url" esc_url_raw="true"]');

We remain at your service.
We would really appreciate your feedback at WordPress.org!