Johnny Beltran
Johnny Beltran

Reputation: 821

WooCommerce: why is get_transaction_id() returning empty?

I'm trying to build a custom payment gateway. One of the requirements of this gateway is that I send to them a parameter called merchantTransactionId. I guess that $order->get_transaction_id() is exactly what I need for this case but the method is returning an empty string. Why?

Upvotes: 0

Views: 1888

Answers (1)

Rohit Vyas
Rohit Vyas

Reputation: 790

$order->get_transaction_id() is return an empty string, that means transaction id is not set to an order. First set transaction id to selected order and then check, you will get transaction id by $order->get_transaction_id().

$order->set_transaction_id($transaction_id);
$order->save();

where $transaction_id is unique number. In your case, you can take as merchantTransactionId.

You can create order object ($order) by wc_get_order($order_id);

$order = wc_get_order( $order_id );

Upvotes: 3

Related Questions