• Resolved hyperV

    (@hyperv)


    Hi Ewout,

    I used your code from the FaQ part on your plugin site. I have the premium one from you. Now the Invoicenumer works. I like also to xustomize the Order Number and set it from 2 to B-2014-100002 from 23 to B-2014-100023. I like to use the sequential ordernumber from Woocommerce.

    I get only B-2014-000000

    I have changed you code to following:

    add_filter( 'wpo_wcpdf_order_number', 'wpo_wcpdf_order_number', 10, 4 );
    function wpo_wcpdf_order_number( $invoice_number, $order_number, $order_id, $order_date ) {
        $prefix = 'B-';
        $order_year = date_i18n( 'Y', strtotime( $order_date ) );
        $padding = 6; // number of digits - so 42 becomes 000042
        $suffix = '-';
        $order_number = $prefix . $order_year . $suffix . sprintf('%0'.$padding.'d', $order_number) ;
        return $order_number;
    }

    Any idea to improve it?

    Thanks a lot

    Josef

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

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

    (@pomegranate)

    Hi Josef,
    The wpo_wcpdf_order_number filter only takes one argument, $order_number.
    You can tell this by looking at the place where it’s applied, in woocommerce-pdf-invoices-packingslips.php:

    return apply_filters( 'wpo_wcpdf_order_number', $order_number);

    so in this case you don’t have an order date to work with, but you should be able to get the right date from $wpo_wcpdf->export->order->order_date.

    However, I have a better solution for you, which works across all of WooCommerce, so that it looks the same everywhere:

    add_filter( 'woocommerce_order_number', 'hyperv_custom_order_number', 99, 2);
    function hyperv_custom_order_number( $order_number, $order ) {
    	if ( isset( $order_number ) ) {
    		$order_number = (int) ltrim($order_number, '#'); // strip #
    		$order_number = $order_number + 100000; // padding / offset
    		$order_year = date_i18n( 'Y', strtotime( $order->order_date ) );
    
    		// B-2014-100002
    		$order_number = 'B-' . $order_year . '-' . $order_number;
    	}
    
    	return $order_number;
    }

    It depends a little bit on how the order_number is currently displayed, but for most configurations, this should work – let me know!

    Thread Starter hyperV

    (@hyperv)

    Thanks Ewout works really great

    One hint for the extra fields:

    It makes live muche easier for the user if you enable the 3 extra fields for html code that you can input tables and text formating for better design.

    I had the need to do so and ended up in deleting the 3 extra fields an implement my own footer.

    Thanks a lot

    Josef

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

The topic ‘Custom Ordernumber’ is closed to new replies.