plugin development - why is update_user_meta creating arrays when trying to change the same value?

admin2025-04-17  0

I added a custom field using update_user_meta to count the products user can buy. Initially the counter starts at 10 and after buying each product the field is deducted by the number of products user bought. Here is the code

function deduct_product($order_id){
  $order=wc_get_order($order_id);
  $items=$order->get_items();
  $quantity=0;
  foreach($items as $item_id => $item_data){
    $quantity+=$item_data->get_quantity();
  }
  $remaining_products=get_user_meta(get_current_user_id(),'remaining_products');  
  $remaining_products-=$quantity;
  update_user_meta(get_current_user_id(  ),'remaining_products',$remaining_products);
}

It gives me error that unsupported operand types on line where i have used $remaining_products-=$quantity. How do I change the user meta for remaining_products by the number of products user has bought.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744886276a272552.html

最新回复(0)