0

I am currently using this solution in order to save the stock status of items at the time they are purchased,

 add_action('woocommerce_checkout_create_order_line_item', 'save_stock_status_order_item_meta', 10, 4 );
function save_stock_status_order_item_meta( $item, $cart_item_key, $values, $order ) {
    $item->update_meta_data( '_stock_status', $values['data']->get_stock_status() );
}

however this has a problem:

  • If an item has 1 item in stock and has backorder on, a user orders 2 items (1 is missing) the save_stock_status_order_item_meta will save the metadata as "instock" incorrectly, instead of as "backorder" which is what the product really is at the time of the order considering the user ordere 2 of them. This leads it to inform users that the product is instock incorrectly when in fact the quantity selected would be out of stock. So this seems to not be correctly tackling the initial problem of customers receiving emails saying that the product is still in stock, when in fact it is not. Thank you in advance for the attention and advice.
Jaime Matos
  • 343
  • 1
  • 14
  • i did a simple test and dont understand what is incorrect. Woo returns the total amount ordered and backorder amount. In the email is the same. The test is latest wp,woo versions. What is not tracking its unclear to me. – Snuffy Oct 11 '22 at 10:05

0 Answers0