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

    (@cealin)

    Forgot to mention, in another topic I saw it the other way around. I would like to do the opposite, using the invoice number as order number:

    /**
     * Format order number with invoice number settings
     */
    add_filter( 'wpo_wcpdf_invoice_number', 'wpo_wcpdf_format_invoice_number', 20, 4 );
    function wpo_wcpdf_format_invoice_number( $invoice_number, $order_number, $order_id, $order_date ) {
    	// We want to use the order number as invoice number!
    	$invoice_number = ltrim($order_number, '#');
    
    	// get format settings
    	$template_settings = get_option('wpo_wcpdf_template_settings');
    
    	$formats['prefix'] = isset($template_settings['invoice_number_formatting_prefix'])?$template_settings['invoice_number_formatting_prefix']:'';
    	$formats['suffix'] = isset($template_settings['invoice_number_formatting_suffix'])?$template_settings['invoice_number_formatting_suffix']:'';
    	$formats['padding'] = isset($template_settings['invoice_number_formatting_padding'])?$template_settings['invoice_number_formatting_padding']:'';
    
    	// Replacements
    	$order_year = date_i18n( 'Y', strtotime( $order_date ) );
    	$order_month = date_i18n( 'm', strtotime( $order_date ) );
    
    	foreach ($formats as $key => $value) {
    		$value = str_replace('[order_year]', $order_year, $value);
    		$value = str_replace('[order_month]', $order_month, $value);
    		$formats[$key] = $value;
    	}
    
    	// Padding - minimum of 3 for safety
    	if ( ctype_digit( (string)$formats['padding'] ) && $formats['padding'] > 3 ) {
    		$invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number);
    	}
    
    	$formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ;
    
    	return $formatted_invoice_number;
    }
    Plugin Author Bas Elbers

    (@baaaaas)

    Are you sure you are using this plugin?
    The code you are showing is for Packing Slips plugin and is not associated with this plugin in any way.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PDF Invoice Number instead of standard WordPress Order Number’ is closed to new replies.