• Resolved MantasM

    (@mantasm)


    Hello, we have been using your plugin for a year, but now we do not remember is it a purchased on of a free version. If you help out with this I promise we will make sure its to buy it if we haven’t.

    Our problem:

    We sell event tickets in our online store and in few physical stores, when purchases happen online, people buy them via Braintree gateway, when a purchase happens in the store, a Cash on Delivery option is used by a store manager. The store has its own counter and invoice number set, thus we have modified your plugin to only set invoice numbers on Braintree payments in the old version:

    public function set_invoice_number( $order_id ) {
    $payment_method = get_post_meta( $order_id, ‘_payment_method’, true );
    if ($payment_method == ‘braintree’) {

    Now after a major update, the template files have changed and we need to get this function back, but the structure of the plugin has changed. Is there a way to modify the public function init_number() to get the same functionality? If not is there any other function where we could recycle the old code to get the same results?

    Kinds Regards

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    I have added a few filters to the init_number method for the invoice document (in addition to what was already there), this will make it possible to generate your own invoice numbers optionally with specific settings.
    Here’s an example using some of your code:

    
    add_filter( 'wpo_wcpdf_external_invoice_number_enabled', 'wpo_wcpdf_external_invoice_number_enabled', 10, 2 );
    function wpo_wcpdf_external_invoice_number_enabled( $enabled, $invoice ) {
    	$payment_method = $invoice->order->get_payment_method();
    	if ($payment_method == 'braintree') {
    		$enabled = true;
    	}
    	return $enabled;
    }
    add_filter( 'wpo_wcpdf_external_invoice_number', 'wpo_wcpdf_external_invoice_number', 10, 2 );
    function wpo_wcpdf_external_invoice_number( $invoice_number, $invoice ) {
    	$number = 999; // do your magic here!
    	// get suffix/prefix/padding from the invoice settings
    	$settings = $invoice->get_number_settings();
    	// or use your own:
    	// $settings = array(
    	// 	'prefix'  = '';
    	// 	'suffix'  = '';
    	// 	'padding' = 8;
    	// );
    	$invoice_number = new \WPO\WC\PDF_Invoices\Documents\Document_Number( $number, $settings, $invoice, $order );
    	return $invoice_number;
    }
    

    Note that this was just added to the development version, so if you want to test, get it from github: https://github.com/wpovernight/woocommerce-pdf-invoices-packing-slips

    Hope that helps!
    Ewout

    Thread Starter MantasM

    (@mantasm)

    Wow thanks,
    so just to be sure, I have to paste the two filters to our functions.php?

    Also what do you mean by the development version? Should I download the plugin from the link you provided to override the one we have installed AND then paste the filters or what?

    Thank you once again πŸ™‚

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! That’s correct, these filters go into functions.php

    By development version I mean the one from github that I linked to. This is the most up to date and contains changes that will be included in the next release.

    So indeed, override the version you have currently installed, add the filters and you should be good to go.

    Ewout

    Plugin Contributor Ewout

    (@pomegranate)

    I just pushed the 2.0.6 update which includes these filters so if you didn’t get around testing with the development version yet, you can just use the latest release now πŸ™‚

    Have a fantastic day!
    Ewout

    Thread Starter MantasM

    (@mantasm)

    Hello,
    thanks for all the hard work, we just updated to 2.0.6 and made a CoD purchase and have received an incremented +1 invoice number. We had last purchase with Braintree at 1173 and now a CoD generated a 1174. I have copy pasted both filters into functions.php. There is some commented text there, is there anything that has to be changed there? I understand that 1st filter, which checks IF payment == braintree -> generate invoice number. But what is the 2nd filter for?

    Plugin Contributor Ewout

    (@pomegranate)

    Hi!

    The first filter (wpo_wcpdf_external_invoice_number_enabled) is to check whether or not invoice numbers should be generated outside of the PDF invoice plugin. In this case the filter says that when a braintree order is placed, the external invoice generation is enabled.

    This then triggers the second filter (wpo_wcpdf_external_invoice_number) which actually creates the invoice number. The example I have given creates a fixed number (999), you have to replace this with your own code that determines what number should be used. The commented code is optional if you want to use custom prefix/suffix/padding settings for the invoice number (otherwise the invoice settings are used).

    Hope that helps! This level of customization is somewhat beyond the scope of free support, if you need more help with this I suggest to hire a developer. With the examples above and your previous code it should be a quick job for an experienced coder.

    Hope that helps!
    Ewout

    Thread Starter MantasM

    (@mantasm)

    Thanks for the reply and explanation, but now I am afraid that we have misunderstood each other. We want to keep on using your invoice numbering system/code. We have around 1100 invoices by now numbered with your plugin, thus making a new system to number the payments doesn’t seem feasible. Basically in this case the 1st function should be “false”, as we need your plugin to do the numbering, BUT just on braintree payments.
    The way I see it would make sense then to make the 1st function to check for Cash on Delivery payments, and then if CoD = True -> Use external invoicing numbers/system “else” use the standard one you have inbuilt in the plugin. So I guess I need to set the payment method to CoD in the 1st function. So as if the purchase happens in a shop, when a shop invoicing system is used, if it happens via Braintree online -> your invoicing numbers are used.

    I’ll try this now and see how it works.

    πŸ™‚

    Plugin Contributor Ewout

    (@pomegranate)

    Yes, sounds right! Indeed I thought you wanted to use a second numbering system for braintree rather than the other way around. Not sure what happens if you set the number to an empty string (”) though, that’s something you’d have to try for yourself.

    Thread Starter MantasM

    (@mantasm)

    Just done that and it works as expected. Everything seems to be in order. Thank you, we will buy the plugin today. Great support!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Invoice numbers’ is closed to new replies.