• Resolved GlideAgency

    (@glideagency)


    Hi, I have been in contact with the WooCommerce Custom Payment Gateway plugin developers to try and figure out if this issue is related to their plugin however it seems to be an issue with a combination of that plus your plugin for custom invoices.

    The current situation is, we have a custom payment gateway called ‘Invoice Payment’ which customers can select at checkout. This allows them to add a PO number and complete the checkout without payment.

    The payment is usually taken at the end of the month, however currently all these Invoice orders are generating an invoice that says ‘Paid In Full’.

    Can you please advise on this issue? I am happy to create a WP user for you if required.

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    @glideagency,

    What do you think about using CSS to hide the “paid in full” text? Would that be a good enough solution for you?

    Thread Starter GlideAgency

    (@glideagency)

    Hi @dpeyou unfortunately this is not an option since the customers that pay by credit card need to have that field visible as proof of payment.

    Plugin Contributor Ewout

    (@pomegranate)

    @glideagency how did you add the ‘paid in full’ text in the first place? Our plugin does not have such a text by default, which means that it was something that was added with custom code or a custom template on your site.

    Thread Starter GlideAgency

    (@glideagency)

    @pomegranate yes we are using a custom template for the invoices. The issue is that the functionality has stopped working even though we didn’t make any changes to the template.

    For reference the particular line of code that shows this text is:
    Total amount (inc GST): $<?php echo $this->order->get_total(); ?><br/>PAID IN FULL

    In addition to this in the functions.php file we define the payment method with the following code:
    $report_payment_method = $order->get_payment_method() == 'cybersource'?'CC':'Invoice';

    So effectively it is meant to check if it is a Credit Card payment or an Invoice Payment, however at the moment it seems to be treating the custom Invoice payments as a Credit Card payment.

    Plugin Contributor Ewout

    (@pomegranate)

    @glideagency the only reason I can think of for this to stop working would be that the payment_method has change names. Since this is custom code, I’m afraid I can’t be of much help, also because you are only showing separate lines of code without the if-statements that show how the logic is currently setup.

    Thread Starter GlideAgency

    (@glideagency)

    @pomegranate I understand where you are coming from, it is hard to debug with that big of code.

    However I just want to clarify the required functionality.

    Essentially we have 3 different types of orders.
    1. Paid Product – Credit Card Order (Invoice is generated and sent as attachment with completed order email)
    2. Paid Product – Invoice Order (Invoice should not be attached to completed order email but it currently is)
    3. Free Products – Same as above

    We also have some custom code that auto completes every order.

    So without considering any custom code, how would your plugin achieve the above result?

    Thanks

    Plugin Contributor Ewout

    (@pomegranate)

    Unfortunately this is not possible without any custom code.

    Thread Starter GlideAgency

    (@glideagency)

    @pomegranate okay, can you then confirm how I can disable invoices being generated on certain orders based on either the payment method, or if it’s a free product?

    Also to clarify, the invoices are always meant to be visible on the WP admin, but the main issue here is that they are also being attached to the completed order emails that go to the customer, and this is what we want to stop.

    This has always been working previously, hence the reason to suspect it has changed due to a plugin update. Either way can you please advise on how we can achieve this?

    Plugin Contributor Ewout

    (@pomegranate)

    can you then confirm how I can disable invoices being generated on certain orders based on either the payment method, or if it’s a free product?

    This is different from your original question which was just about when the “Paid in full” text should appear or not, correct?

    To disable the automatic generation (=email attachment) for the PDF invoice, you can use the wpo_wcpdf_custom_attachment_condition filter hook. Here’s an example that will block the creation of the invoice for your example payment method cybersource:

    
    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type ){
    	if ( $order->get_payment_method() == 'cybersource' ) {
    		$attach = false;
    	}
    	return $attach;
    }, 10, 4 );
    

    For blocking invoices on free products there’s a setting (WooCommerce > Documents > Invoice):

    Note that this setting will also prevent the admin from creating invoices for free orders, if you also need the admin to be able to create invoices for free orders you’d have to write a new snippet using that wpo_wcpdf_custom_attachment_condition hook, checking the order total:

    
    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type ){
    	if ( $order->get_total() == 0 ) {
    		$attach = false;
    	}
    	return $attach;
    }, 10, 4 );
    

    This has always been working previously, hence the reason to suspect it has changed due to a plugin update. Either way can you please advise on how we can achieve this?

    Nothing has changed in the process of how/when an invoice is created, so I suspect it’s related to a change relative to the logic in your custom code (as suggested previously, it could be the slug of the payment method for example). You have only shared small bits of your custom code and without the full code it’s not possible for me to know what other reasons there could be behind this. Your best bet is consulting with the person that originally wrote that code!

    Thread Starter GlideAgency

    (@glideagency)

    Hi @pomegranate thanks for that info. Sorry for the misunderstanding, it is a relatively complicated setup and unfortunately the developer that originally wrote the code is no longer working here.

    Disabling invoices on free products is now working as expected.

    With regards to the attachment issue, I just wanted to clarify that rather than disable the attachments for the cybersource payments, we need them disabled when using the custom invoice payment method.

    Here is a screenshot of the payments screen if that helps – https://imgur.com/k65yHOG

    So the main question is since the custom payment method is via a separate plugin, is it possible to detect if the payment method is the custom one via the same code above, and just changing cybersource to “other_payment” instead? “other_payment” seems to be the key for the Invoice Payment from what I can see in the functions file – $order->get_payment_method() == 'other_payment'

    Finally can you confirm if this code is meant to be added to the functions.php file or should it be in the WooCommerce Order Complete email template?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @glideagency,

    So the main question is since the custom payment method is via a separate plugin, is it possible to detect if the payment method is the custom one via the same code above, and just changing cybersource to “other_payment” instead?

    That’s right: if the payment ID is other_payment, this code snippet should ignore the PDF attachment if that payment method is selected:

    /**
     * Disable the automatic invoice creation/attachment for "Invoice Payment" (payment method)
     */
    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type ){
    	if ( $document->get_type() = 'invoice' & $order->get_payment_method() == 'other_payment' ) {
    		$attach = false;
    	}
    	return $attach;
    }, 10, 4 );

    Please note that this code snippet disables the automatic invoice creation (or, in other words: the PDF invoice sending by email), but you still will be able to create it from your WordPress dashboard.

    If you want to disable invoices completely for this payment method, use this code snippet instead:

    /**
     * Disable invoice for "Invoice Payment" (payment method)
     */
    add_filter( 'wpo_wcpdf_document_is_allowed', function( $allowed, $document ){	
    	if ( $document->get_type() == 'invoice' && $document->order->get_payment_method() == 'other_payment' ) {
    		if ( $document->exists() ) {
    			return $allowed;
    		}
    		$allowed = false;
    	}
    	return $allowed;
    }, 10, 2 );

    Finally can you confirm if this code is meant to be added to the functions.php file or should it be in the WooCommerce Order Complete email template?

    Yes, you should put this code in your child theme’s functions.php file or using the Code Snippets plugin. Read this guide to learn more: How to use filters

    Thread Starter GlideAgency

    (@glideagency)

    Thanks everyone for your help. I can confirm everything is working as expected now.

    Just to confirm though I did have to remove the document->get_type bit of the code since I was getting a critical error. But without that bit it works fine.

    Thanks again.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Thanks for mentioning that!

    My mistake! This is the corrected code for the first code snippet:

    /**
     * Disable the automatic invoice creation/attachment for "Invoice Payment" (payment method)
     */
    add_filter( 'wpo_wcpdf_custom_attachment_condition', function( $attach, $order, $email_id, $document_type ){
    	if ( $document_type == 'invoice' & $order->get_payment_method() == 'other_payment' ) {
    		$attach = false;
    	}
    	return $attach;
    }, 10, 4 );

    By the way, the intention of the $document_type == 'invoice' check is to apply this only to invoices, but you can remove this if you want to disable the PDF document attachment for all documents* when the 'other_payment' method is selected.

    *If you’re using the Professional extension, that also includes the proforma and credit note documents, as well as the Attach to feature for packing slips.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Issue with Invoice on custom payment’ is closed to new replies.