Marco Marsala
Marco Marsala

Reputation: 2462

Get invoice number from a WooCommerce order

I'm trying to export WooCommerce orders to my CRM. I was able to get line items, quantity and prices, but I miss invoice number.

function custom_woocommerce_complete_order_crm( $order_id ) {
    global $woocommerce;
    if ( !$order_id )
    return;
    $order = new WC_Order( $order_id );

    $order_items = $order->get_items();

    foreach( $order_items as $product ) {
        $product_name[] = $product['name']; 
        $product_qty[] = $product['qty']; 
    }

...

var_dump does not helped me and the WooCommerce documentation does not say anything about invoices.

Upvotes: 1

Views: 4853

Answers (2)

Ajith
Ajith

Reputation: 11

$invoice number = $order->get_order_number();

Upvotes: 1

danyo
danyo

Reputation: 5846

If you are not using any function on woocommerce to have subquential order numbers, you can just get the post ID.

something like:

$orderid = get_the_id();

And by invoice number, do you mean the order id?

Hope this helps!

Upvotes: 0

Related Questions