Woocommerce custom stock update after successful o

2019-09-04 17:16发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-04 17:55

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.' );
}
查看更多
登录 后发表回答