最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览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.

发布评论

评论列表(0)

  1. 暂无评论