Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Skip invoice creation for specific payment methods

  • Resolved ComMotion

    (@werbeagenturcommotion)


    Hi,

    I want to skip the invoice creation for specific payment methods. How do I realize that? Thanks for your help in advance.

    Sincerely,
    Maxim

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Support kluver

    (@kluver)

    Hi @werbeagenturcommotion,

    You can use a small code snippet for this:

    // exclude certain payment methods from automatic pdf creation
    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_exclude_payment_method', 100, 4 );
    function wpo_wcpdf_exclude_payment_method ( $condition, $order, $status, $document ) {
    	$excluded_methods = array( 'stripe', 'bacs' );
    	$payment_method = get_post_meta( $order->id, '_payment_method', true );
    	if ( $document == 'invoice' && in_array( $payment_method, $excluded_methods ) ) {
    		return false;
    	} else {
    		return $condition;
    	}
    }

    Add the desired payment methods to the excluded_methods array. This code snippet should be placed in the functions.php of your child theme. If you haven’t worked with code snippets or functions.php before please read this: How to use filters

    ComMotion

    (@werbeagenturcommotion)

    Great, thank you very much for your quick reply. I will try this later and will inform you if everything works great. Have a nice day!

    ComMotion

    (@werbeagenturcommotion)

    Works great, thanks a lot!

    Hi,
    I’m having the same issue trying to disable the invoices for mycred payment method. I’ve tried with the snippet you have here by changing

    $excluded_methods = array( ‘stripe’, ‘bacs’ ) to $excluded_methods = array( ‘mycred’ )

    but it’s still creating the invoices automatically. I’m I missing something or should I try something different?

    Regards,
    Alvaro

    Plugin Support kluver

    (@kluver)

    Hi @alprofer,

    That should work if your payment method name was ‘mycred’. You can check if this really is the case by going to WooCommerce > Settings > Payments and click on the Mycred payment method. Now check the URL of the page and see if at the end it says:

    section=mycred

    Hi,

    I’ve just checked it and it ends in section=mycred.
    Do you know if there’s something else I might need to do for it to work?

    Thanks for your quick reply.

    Alvaro

    Plugin Author Ewout

    (@pomegranate)

    Looking at the gateway code, it appears that mycred should indeed be the correct gateway slug:
    https://plugins.trac.wordpress.org/browser/mycred/trunk/addons/gateway/carts/mycred-woocommerce.php

    So I’m not sure why it doesn’t work for you. How do you know the document is automatically created? Do you check the email attachment?

    I’ve tested purchasing with one account and I keep getting the email with the invoice attached, also when checking the orders it shows the invoice number as it has been created (unlike the orders which have failed that have no invoice number nor mail sent)

    Plugin Author Ewout

    (@pomegranate)

    Quite strange. Just to be sure your code is correct, can you post your entire snippet here? (use the code button above or use back ticks to post as a code block here)

    alprofer

    (@alprofer)

    Sure, here’s the code:

    
    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_exclude_payment_method', 100, 4 );
    function wpo_wcpdf_exclude_payment_method ( $condition, $order, $status, $document ) {
    	$excluded_methods = array( 'mycred' );
    	$payment_method = get_post_meta( $order->id, '_payment_method', true );
    	if ( $document == 'invoice' && in_array( $payment_method, $excluded_methods ) ) {
    		return false;
    	} else {
    		return $condition;
    	}
    }
    
    Plugin Author Ewout

    (@pomegranate)

    And you are 100% sure that you are using this plugin = WooCommerce PDF Invoices & Packing Slips, version 2.2.14?

    alprofer

    (@alprofer)

    Yes, I’m 100% sure.
    version 2.2.14 In fact I came to this support forum by following the link in the plugin itself…

    Plugin Author Ewout

    (@pomegranate)

    Very odd (I’m assuming that there are no other PDF invoice plugins installed)… Could you install the WooCommerce Store Toolkit plugin and then open one of these orders to see what value it shows for the _payment_method meta inside the order?

    alprofer

    (@alprofer)

    Sure,
    I’ve checked the _payment_method and it shows mycred.

    Plugin Author Ewout

    (@pomegranate)

    How/where did you add the snippet? And are you sure it is activated?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Skip invoice creation for specific payment methods’ is closed to new replies.