$quantity = (int) get_post_meta($product_id, 'stock_quantity', true); update_post_meta($product_id, 'stock_quantity', $quantity - 1);