Woocommerce custom stock update after successful o

2019-09-04 17:59发布

问题:

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?

回答1:

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.' );
}