0

I have a custom database table linked to my Woocommerce tables with some information like SKU and Stock. I want to add custom function to update this table after successful order (when Woocommerce updates product stock). I've tried to do something with this:

add_action( 'woocommerce_reduce_order_stock', 'wpet_testnote' );
function wpet_testnote() {

// Lets grab the order
$order = wc_get_order( $order_id );
$order->add_order_note( 'Stock Updated.' );

I've tried to testing my action with basic order note adding, but it's not working. Any ideas?

AstroCB
  • 12,337
  • 20
  • 57
  • 73
exspet
  • 48
  • 2
  • 11
  • "it's not working" -> elaborate.. – Kashyap Mar 29 '15 at 22:12
  • Thanks for answer @Kashyap. As I was mentioned my question before, I'm trying to run a function after succesifull order (for example, getting stock after order), I've tried to do this with add_action( 'woocommerce_reduce_order_stock', 'wpet_testnote' ); add_action( 'reduce_order_stock', 'wpet_testnote' ); but these are not working for me. So, my real question is how can I execute a function after order placed in woocommerce? – exspet Mar 29 '15 at 22:15

1 Answers1

0

you forgot to submit the $order_id. this one works on my end:

add_action( 'woocommerce_reduce_order_stock', 'wpet_testnote' );
function wpet_testnote( $order_id ) {
  $order = wc_get_order( $order_id );
  $order->add_order_note( 'Stock Updated.' );
}
honk31
  • 3,895
  • 3
  • 31
  • 30