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.