• Resolved jerryskate

    (@jerryskate)


    Hi!

    I have a custom template and inside it I have two documents, enquiry.php and invoice.php.

    I would like to change titles from Invoice to Quote.

    These filters does what I want, but unsure how to set this for the enquiry document only:

    
    add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_invoice_title', 10, 2 );
    function wpo_wcpdf_invoice_title ( $title, $document ) {
    	if ($template_type == 'invoice' ) {
        $title = 'Quote';
        return $title;
        }
    }
    add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename', 10, 4 );
    function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) {
        $invoice_string = _n( 'invoice', 'invoices', count($order_ids), 'woocommerce-pdf-invoices-packing-slips' );
        $new_prefix = _n( 'quote', 'quotes', count($order_ids), 'woocommerce-pdf-invoices-packing-slips' );
        $new_filename = str_replace($invoice_string, $new_prefix, $filename);
        return $new_filename;
    }         
       

    Any help would be appreciated!

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

    (@pomegranate)

    The second filter looks alright to me, the first one is using a non-existing variable, try this instead:

    
    add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_invoice_title', 10, 2 );
    function wpo_wcpdf_invoice_title ( $title, $document ) {
        if ($document->get_type() == 'invoice' ) {
            $title = 'Quote';
        }
        return $title;
    }
    

    You could even remove the condition, because that filter wpo_wcpdf_invoice_title is already specific to the invoice document:

    
    add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_invoice_title', 10, 2 );
    function wpo_wcpdf_invoice_title ( $title, $document ) {
        return 'Quote';
    }
    

    If you want a no-code way to change document titles (and filenames), I highly recommend the Professional extension, since it lets you do this directly from the plugin settings:

    https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-professional/

    Plugin Contributor Ewout

    (@pomegranate)

    I just now noticed that you are referring to a document enquiry.php but this is not an official document. Was this added by a third party plugin? Or did you simply add the enquiry.php file? If that’s the case than you cannot edit the filename or use the title filter, but you can edit the title directly in the template php file.

    Thread Starter jerryskate

    (@jerryskate)

    The enquiry.php file is added to the template folder, we have a custom status for quotes.

    Both enquiry.php and invoice.php are in my template folder.

    How do I edit the title directly on the php?

    Plugin Contributor Ewout

    (@pomegranate)

    Just open the enquiry.php file and look for the line that prints the enquiry title, in the invoice that’s this line:
    https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips/blob/v2.7.3/templates/Simple/invoice.php#L11
    or this line:
    https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips/blob/v2.7.3/templates/Simple/invoice.php#L27
    (depending on whether you have uploaded a logo)

    Thread Starter jerryskate

    (@jerryskate)

    Will that affect the filename? Thats the important for me. Thanks!

    Plugin Contributor Ewout

    (@pomegranate)

    No, if you want to change the filename, you will need to extend the Order_Document class the same way this is implemented for the Invoice document (source). This is not a trivial thing to do and beyond what we can provide as part of the free plugin. This actually sounds like a perfect usecase for the Proforma Invoice document in the Professional extension. You’ll get separate buttons/settings/numbering etc. and the ability to rename the document and file directly from the plugin settings.

    Thread Starter jerryskate

    (@jerryskate)

    Yeah that would be an option for me. Just worried that the extension will just see my custom template as one document, and not divide between the two document types inside the custom template?

    Plugin Contributor Ewout

    (@pomegranate)

    The Professional extension only adds the extra Proforma Invoice document, everything else would work the same as with the free version (including your enquiry.php). But with the pro version I would drop the enquiry.php template altogether and use the proforma.php template for this and do all the renaming from the settings. If you have any further questions about this, please send an email to [email protected] and we’ll do our best to answer them!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Change PDF Title on template’ is closed to new replies.