Reputation: 51
I am using the following to hook into the admin order refund hooks to get hold of the order data and send it to another database. However, wc_get_order always returns false.
When you refund from the admin it does this via ajax and reloads the page so I was wondering if Im missing something.
Note: I call my plugin files and classes on "plugins_loaded". I have tried with init and woocommerce_loaded as well with no success.
//Add the full order refund action
add_action( 'woocommerce_order_fully_refunded', [$this, 'refund_items_mysql_insert'], 20, 2);
add_action( 'woocommerce_order_partially_refunded', [$this, 'refund_items_mysql_insert'], 20, 2);
public function refund_items_mysql_insert($order_id, $refund_id){
// Get the WC_Order Object instance (from the order ID)
$order = wc_get_order( $order_id );
echo json_encode($order);
wp_die();
}
Upvotes: 1
Views: 1819
Reputation: 51
The error here was that the object was protected and thus it wouldnt send back the data as json.
// Get the WC_Order Object instance (from the order ID)
$order = wc_get_order( $order_id );
echo <pre>;
print_r($order);
echo </pre>
wp_die();
Upvotes: 1