• Resolved malaiac

    (@malaiac)


    I’m not sure about to do that :
    (pro version)
    e-commerce website, taking orders online from their website AND receiving order creations from Amazon (via a third party connector)
    Goal is to have those invoice numbers :
    website orders :
    2021W-1
    2021W-2
    2021W-3
    orders from amazon :
    2021A-1
    2021A-2
    2021A-3

    I hooked into wpo_wcpdf_formatted_document_number filter but it doesn’t seem enough.
    I got duplicate invoice numbers (the index check fails and generate 2021-W{NNN} multiple times.

    What is the proper way to hook into the invoice number generation ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter malaiac

    (@malaiac)

    As I’m working on it, maybe this should work :

    add_filter('woocommerce_invoice_number_by_plugin', '__return_true');
    add_filter('woocommerce_generate_invoice_number', 'mycustom_generate_invoice_number', 10, 2 );
    function mycustom_generate_invoice_number( $null, $WC_Order ) {
    	if( method_exists( $WC_Order, 'get_created_via' ) ) {
    		$_acq_channel = $WC_Order->get_created_via();
    	}
    	else {
    		$_acq_channel = 'web';
    	}
    
    	$last_invoice_number = get_option( 'mycustom_wpo_last_' . $_acq_channel . '_number');
    	if( !$last_invoice_number ) {
    		$last_invoice_number = 1;
    
    	}
    	$prefix = 'W';
    	if( $_acq_channel == 'amazon' ) {
    		$prefix = 'A';
    	}
    
    	$last_invoice_number++;
    	$invoice_number = sprintf(
    		'%s%s-%d',
    		date('Y'),
    		$prefix,
    		$last_invoice_number
    	);
    	update_option(  'mycustom_wpo_last_' . $_acq_channel . '_number', $last_invoice_number );
    	return $invoice_number;
    
    }
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @malaiac,

    Since you mentioned that you have the “pro version”, I assume that you have the Professional extension, and as WordPress doesn’t allow us to provide support for paid plugins in this forum, please contact us by email: [email protected]

    I’ll be looking forward to your message!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dual invoice numbering (depending on order source)’ is closed to new replies.