Making WordPress.org


Ignore:
Timestamp:
04/26/2019 06:21:50 PM (6 years ago)
Author:
coreymckrill
Message:

WordCamp invoices: Fix bug with invoice numbering

This changes the process of creating an invoice to avoid generating more
than one unique invoice number. The number is determined during the save_post
hook, so it doesn't need to happen during the create_invoice method itself.

Props avillegasn

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-invoices/includes/class-camptix-addon-invoices.php

    r8670 r8699  
    273273     */
    274274    public static function create_invoice( $attendee, $order, $metas ) {
    275         $number         = self::create_invoice_number();
     275
     276        $invoice = array(
     277            'post_type'   => 'tix_invoice',
     278            'post_status' => 'draft',
     279        );
     280
     281        $invoice_id = wp_insert_post( $invoice );
     282        if ( ! $invoice_id || is_wp_error( $invoice_id ) ) {
     283            return;
     284        }//end if
     285
     286        $number         = get_post_meta( $invoice_id, 'invoice_number', true );
    276287        $attendee_email = get_post_meta( $attendee->ID, 'tix_email', true );
    277288        $txn_id         = get_post_meta( $attendee->ID, 'tix_transaction_id', true );
     
    300311        }//end if
    301312
    302         $invoice = array(
    303             'post_type'   => 'tix_invoice',
    304             'post_status' => 'draft',
    305             'post_title'  => $invoice_title,
    306             'post_name'   => sprintf( 'invoice-%s', $number ),
    307         );
    308 
    309         $invoice_id = wp_insert_post( $invoice );
    310         if ( ! $invoice_id || is_wp_error( $invoice_id ) ) {
    311             return;
    312         }//end if
    313         update_post_meta( $invoice_id, 'invoice_number', $number );
    314313        update_post_meta( $invoice_id, 'invoice_metas', $metas );
    315314        update_post_meta( $invoice_id, 'original_order', $order );
     
    320319                'ID'          => $invoice_id,
    321320                'post_status' => 'publish',
     321                'post_title'  => $invoice_title,
     322                'post_name'   => sprintf( 'invoice-%s', $number ),
    322323            )
    323324        );
Note: See TracChangeset for help on using the changeset viewer.