• Resolved Kybernetik Services

    (@kybernetikservices)


    Hi there.
    I’m currently using YITH WooCommerce PDF Invoice and Shipping List Premium on my multilingual shop.
    I’m wondering how I can switch to WooCommerce PDF Invoices & Packing Slips without keeping the YITH still activated for access the previous invoices.
    Is there a way to take over the previous invoices or, to regenerate the invoices but to make sure to keep the same invoice number?
    Any idea how to achieve this goal?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @kybernetikservices,

    Yes, there is! We only need the meta key used by that plugin to store the invoice number in the order data, that should be something like invoice_number. With that meta key, we can write a code snippet for you to achieve this.

    Do you know what meta key is it? If not, please check this Doc’s article: Finding WooCommerce custom fields

    Thread Starter Kybernetik Services

    (@kybernetikservices)

    Thank you @yordansoares, for your quick reply.
    The invoice number is stored in the meta_key _ywpi_invoice_number which lives in postmeta. The formatted number (with prefix) has the meta_key _ywpi_invoice_formatted_number.
    Can you work with this to provide the code?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @kybernetikservices,

    Sorry for the late reply!

    To migrate the invoice number and its date from the PDF invoices plugin from YITH to ours, follow these steps:

    1. Find which is the Next invoice number located under YITH > PDF Invoice and copy its value. Also, in this same page, find the invoice suffix, prefix, and format.
    2. Now, go to WooCommerce?> PDF?Invoices?> Documents?> Invoice and find the Next?invoice?number and enter the value you copy in the first step. Here, you’ll also find the Number format section, in which you can replicate your number format settings from YITH, but please note that the invoice format need to be merged in the prefix and/or suffix.

      E.g. if the prefix in YITH was F, the suffix US, and your format [prefix]-[number]/[suffix], you’ll need to configure the Number format in our plugin in this way:

      — Prefix: F-
      — Suffix: /US

    3. Finally, add this code snippet to your site:
      /**
       * WooCommerce PDF Invoices & Packing Slips:
       * Migrate invoice numbers from YITH WooCommerce PDF Invoice and Shipping List Premium
       */
      add_filter( 'wpo_wcpdf_invoice_get_date', function( $date, $document ) {
      	if ( $document->get_type() == 'invoice' && $order = $document->order ) {
      		// Get invoice date
      		if ( $legacy_date = $order->get_meta('_ywpi_invoice_date') ) {
      			$date = new \WC_DateTime( "@{$legacy_date}", new \DateTimeZone( 'UTC' ) );
      			$document->set_date( $date );
      		}
      	}
      	return $date;
      }, 10, 2 );
      add_filter( 'wpo_wcpdf_external_invoice_number_enabled', '__return_true' );
      add_filter( 'wpo_wcpdf_external_invoice_number', function( $number, $document ) {
      	if ( ! empty( $document->order ) ) {
      		// Get invoice formatted number
      		$number = $document->order->get_meta( '_ywpi_invoice_formatted_number' ); // if $number is empty, the plugin will generate a new number
      	}
      	return $number;
      }, 10, 2 );

      If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Let me know if it worked! ??

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @kybernetikservices,

    Since we haven’t heard back from you in the last two weeks, we’re assuming you managed to set it up, so I’ll go ahead and mark this ticket as Resolved.

    Feel free to reply to this topic is you still need help with this, or open a new topic if you have any other questions!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Switch from YITH WooCommerce PDF Invoice and Shipping List Premium’ is closed to new replies.