Check this http://imgur.com/a/7A5Xo
Also there is a bunch of code just after payment complete on plugin as below so you can fetch all metas from db if you have transaction id and order id
$transactionmetas = array(
'approved' => $response->approved,
'declined' => $response->declined,
'error' => $response->error,
'held' => $response->held,
'response_code' => $response->response_code,
'response_subcode' => $response->response_subcode,
'response_reason_code' => $response->response_reason_code,
'authorization_code' => $response->authorization_code,
'card_type' => $response->card_type,
'transaction_type' => $response->transaction_type,
'account_number' => $response->account_number,
'cavv_response' => $response->cavv_response,
'card_code_response' => $response->card_code_response
);
add_post_meta( $order_id, '_'.$order_id.'_'.$response->transaction_id.'_metas', $transactionmetas);
function create_expandable_order( $order_id ) {
$transaction_id = 1234; // I have the actual transaction ID
$order_metas = get_post_meta($order_id, "_{$order_id}_{$transaction_id}_metas", true);
// the rest of code
}
add_action( 'woocommerce_payment_complete', 'create_expandable_order', 10 );
This is my code, I am using the woocommerce_payment_complete hook and it seems like the order_meta has not been added to the database yet. What am I doing wrong? When I use this code after the order creation is complete it returns the order_meta $order_metas = get_post_meta($order_id, "_{$order_id}_{$transaction_id}_metas", true);
Metas are being added to database after order complete
This is entire flow
$wc_order->payment_complete($response->transaction_id);
WC()->cart->empty_cart();
$transactionmetas = array(
'approved' => $response->approved,
'declined' => $response->declined,
'error' => $response->error,
'held' => $response->held,
'response_code' => $response->response_code,
'response_subcode' => $response->response_subcode,
'response_reason_code' => $response->response_reason_code,
'authorization_code' => $response->authorization_code,
'card_type' => $response->card_type,
'transaction_type' => $response->transaction_type,
'account_number' => $response->account_number,
'cavv_response' => $response->cavv_response,
'card_code_response' => $response->card_code_response
);
add_post_meta( $order_id, '_'.$order_id.'_'.$response->transaction_id.'_metas', $transactionmetas);
So it seems your hook is not going to work
Is there any workaround for that?
Place below line of code above payment complete
$transactionmetas = array(
'approved' => $response->approved,
'declined' => $response->declined,
'error' => $response->error,
'held' => $response->held,
'response_code' => $response->response_code,
'response_subcode' => $response->response_subcode,
'response_reason_code' => $response->response_reason_code,
'authorization_code' => $response->authorization_code,
'card_type' => $response->card_type,
'transaction_type' => $response->transaction_type,
'account_number' => $response->account_number,
'cavv_response' => $response->cavv_response,
'card_code_response' => $response->card_code_response
);
add_post_meta( $order_id, '_'.$order_id.'_'.$response->transaction_id.'_metas', $transactionmetas);
Did workaround worked for you ?