• Resolved pdsxerox

    (@pdsxerox)


    Hello,

    I have two payment methods on my site, PayPal and COD. When a cart checkout is complete through Paypal, I was hoping to have the PDF generated read “INVOICE” (like it does now) and when COD is selected, read “QUOTE” (I use COD to generate quotes more than actual CODs).

    I’m guessing this line in the email template has something to do with that:
    <h1 class=”document-type-label”>
    <?php if( $wpo_wcpdf->get_header_logo_id() ) echo apply_filters( ‘wpo_wcpdf_invoice_title’, __( ‘Invoice’, ‘wpo_wcpdf’ ) ); ?>
    </h1>

    Can this be done?

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

    (@yordansoares)

    Hi @pdsxerox,

    This can be certainly be done, but what’s about the number sequence? Although we can provide a custom code snippet to help you to achieve this, in the background this is the same ‘invoice’ document, therefore it uses the same numbering system.

    My recommendation is to use the packing slips as quote document instead, and check for the payment method to enable the invoices just for the PayPal orders.

    Let me know your thoughts ??

    Thread Starter pdsxerox

    (@pdsxerox)

    Thank you, Yordan, for the reply!

    The numbering sequence isn’t important. I tried to assemble some code from other posts and failed; I’m really not sure what I’m doing, and I’m probably about to embarrass myself on a public forum:

    add_filter( ‘wpo_wcpdf_invoice_title’, ‘wpo_wcpdf_invoice_title’);
    function wpo_wcpdf_invoice_title ( $title ) {
    $payment_method = get_post_meta(‘_payment_method’, true );
    if ($payment_method == ‘cod’) {
    $title = ‘Product Quote’;
    return $title;
    }
    else {
    $title = ‘Invoice’;
    return $title;
    }
    }

    Here’s the link so you can see how we’re using this: https://www.eoeusvi.com/

    If you put something in your cart and click through the checkout process, you’ll see at the end an option for either PayPal or a Quote. Schools and other government entities want the quote and then will pay the quote later when approved. So if there was a way to conditionally set the title of those PDFs to Invoice so we know it’s paid or Quote so we know it’s pending, that’s our hope.

    Again, thank you for your reply!

    • This reply was modified 3 years, 2 months ago by pdsxerox.
    Plugin Contributor kluver

    (@kluver)

    Hi @pdsxerox,

    No worries, you have the correct filter. You can change the title to ‘Quote’ when the payment method is cod like this:

    add_filter( 'wpo_wcpdf_invoice_title', 'wpo_wcpdf_change_title_based_on_payment_method', 10, 2 );
    function wpo_wcpdf_change_title_based_on_payment_method ( $title, $document ) {
    	if ( $order = $document->order ) { 
    		if ( $order->get_payment_method() == 'cod' ) $title = 'Quote';
    	}
    	return $title;
    }

    Please note that, like my colleague explained, this will cause gaps in your invoice number sequence. As some invoices will be relabeled as quote. If you want to setup a proper quote/proposal workflow you might want to check out our WooCommerce Order Proposal plugin.

    Thread Starter pdsxerox

    (@pdsxerox)

    Hi @kluver

    Thank you for the reply! When I added the snippet to my function.php file, it crashes the plugin:

    Fatal error: Too few arguments to function wpo_wcpdf_change_title_based_on_payment_method(), 1 passed in /nas/content/live/eoebusiness/wp-includes/class-wp-hook.php on line 303 and exactly 2 expected

    Again, I’m in the dark as far as how this all works and I totally appreciate any help you can offer.

    Cheers and have a great weekend!

    Thread Starter pdsxerox

    (@pdsxerox)

    Could the fact that I’m using a template in my child theme be the issue?

    Plugin Contributor Ewout

    (@pomegranate)

    @pdsxerox that appears to be the case indeed (it would be quite old though, from before 2017).

    Here you can see how this is done in the current template:
    https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips/blob/v2.9.3/templates/Simple/invoice.php#L27

    I would strongly recommend you update the entire template because the $wpo_wcpdf global has been deprecated for over 4 years and will eventually be retired completely. Plus what you want to do now with the title change is only possible with the new functions.

    Thread Starter pdsxerox

    (@pdsxerox)

    Absolute rockstars. Thank you so much, reverting to the simple theme did the trick.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to know that it worked!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Conditional Title Based on Payment Method?’ is closed to new replies.