• Resolved kasimrixa

    (@kasimrixa)


    Hello team,

    I’m trying to figure out how to change the Titles of the PDFs when downloaded.

    I’m using a specifc Format for all the Pdfs before sending to my Accountant.

    PDF: Invoice Number – Buyers Name – Price – Date

    Can I achive that result. So far the pdf has the following format.

    “Invoice” – Invoice number.

    thank you so much ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    are you referring to the title, or the filename?

    See:
    Change the document title
    Custom pdf filenames

    Thread Starter kasimrixa

    (@kasimrixa)

    Ewout thank you so much ??

    I’m referring to the filename.

    For example, So far I get: invoice-128.pdf

    but I need to have this:

    128 – [Buyers Name] (Price) (Date).pdf
    128 – [Jonathan] (204.3€) (Aug).pdf

    So how can I retrieve the name of the buyer, number of the invoice, and the price as well?

    $new_filename = $numberInvoice.’-[‘.$buyer.’](‘.$price.’)(‘.$date.’).pdf’;
    return $new_filename;

    I hope you got the point ??

    Plugin Contributor Ewout

    (@pomegranate)

    For the free version you’ll have to collect this information yourself from the order object in the last example on the documentation page: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/custom-pdf-filenames/#free-version
    This is quite custom and beyond what we can offer as part of free support.

    With the Professional extension you can use placeholders for this in the filename format:

    {{document_number}}-{{formatted_billing_full_name}}-{{order_total}}-{{order_date}}.pdf

    Thread Starter kasimrixa

    (@kasimrixa)

    Hi Ewout,

    Unfortunately, I’m trying to just copy-paste the code from your examples on the function.php but the functions don’t find an application. Did I miss something?

    It seems that when I download the pdf file the filename remains the same.

    Just to let you know, I’m not the beginner WP users.

    Plugin Contributor Ewout

    (@pomegranate)

    The “example 4” does indeed not change anything, it simply gives you a basis to work from but you’ll need to add the customizations yourself.

    Thread Starter kasimrixa

    (@kasimrixa)

    I got the point with the example4.

    Even if I put some custom text on the $filename still doesn’t take any effect on the file name

    Plugin Contributor Ewout

    (@pomegranate)

    can you share your code with us here? And can you double check that you are using this PDF invoice plugin (“WooCommerce PDF Invoices & Packing Slips”, version 2.3.3)

    Thread Starter kasimrixa

    (@kasimrixa)

    Just a simple snippet

    add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename', 10, 4 );
    function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) {
        
        $count = count($order_ids);
        $name = _n( 'invoice', 'invoices', $count, 'woocommerce-pdf-invoices-packing-slips' );
        $filename = $name . 'Invoice Custom Text.pdf';
        return $filename;
        }

    version 2.3.3 -> https://ibb.co/7Nzdy14

    Plugin Contributor Ewout

    (@pomegranate)

    That looks fine to me. Some themes/sites disable function.php in certain contexts. Can you try the Code Snippets plugin to rule this out (and don’t forget to rename the function to something else to prevent crashes on duplicate function names:

    
    add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename_2', 10, 4 );
    function wpo_wcpdf_custom_filename_2( $filename, $template_type, $order_ids, $context ) {
        $count = count($order_ids);
        $name = _n( 'invoice', 'invoices', $count, 'woocommerce-pdf-invoices-packing-slips' );
        $filename = $name . 'Invoice Custom Text.pdf';
        return $filename;
    }
    
    • This reply was modified 5 years, 6 months ago by Ewout. Reason: prevent duplicate function names
    Thread Starter kasimrixa

    (@kasimrixa)

    Really appreciate your effort and your guidance,

    I will follow your recommendations.

    You won a review ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Change downloadable pdf title’ is closed to new replies.