• Resolved jpelayo

    (@jpelayo)


    Hi,

    Please, is it possible to skip invoice creation/association to an order based on the payment method (CoD for instance) ?

    This might be a possible implementation in the functions.php, but a hook would need to be available – and maybe it is – :

    // 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( 'cod', '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;
    	}
    }

    For now I will try a modified version of invoice.php at line 437 :

    
    $payment_method=$order->get_payment_method();
    $excluded_methods = array( 'cod', 'bacs' );
    $free_order_enable = Wf_Woocommerce_Packing_List::get_option('wf_woocommerce_invoice_free_orders',$this->module_id);
    $invoice_creation = 1;
    if(($free_order_enable == "No")|| in_array( $payment_method, $excluded_methods )){
      if(\intval($order->get_total()) === 0){
        $invoice_creation = 0;
      }
    }
    

    Thank you.

    • This topic was modified 2 years, 8 months ago by jpelayo.
    • This topic was modified 2 years, 8 months ago by jpelayo. Reason: added php code
    • This topic was modified 2 years, 8 months ago by jpelayo.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jpelayo

    (@jpelayo)

    Code corrected, better at line 407 and 441 :


    $payment_method=$order->get_payment_method();
    $excluded_methods = array( ‘cod’, ‘bacs’ );
    if(in_array( $payment_method, $excluded_methods )){
    $invoice_creation = 0;
    }

    But, anyway,… it does not work.

    • This reply was modified 2 years, 8 months ago by jpelayo.
    • This reply was modified 2 years, 8 months ago by jpelayo.
    Thread Starter jpelayo

    (@jpelayo)

    This was needed for it to work:

    
    echo self::generate_invoice_number($order,false);
    

    instead of

    
    echo self::generate_invoice_number($order,$force_generate);
    

    in the function

    public function add_invoice_column_value($column)
    

    of invoice.php

    Plugin Author WebToffee

    (@webtoffee)

    Hi @jpelayo,

    Greetings from WebToffee!

    We understand your requirement. However, our plugin currently doesn’t offer any options/hooks to skip the invoice creation based on the payment method. Thanks for understanding.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Skip Invoice creation’ is closed to new replies.