admin管理员组文章数量:1405149
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.
本文标签: plugin developmentwhy is updateusermeta creating arrays when trying to change the same value
版权声明:本文标题:plugin development - why is update_user_meta creating arrays when trying to change the same value? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744886274a2630503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论