> For the complete documentation index, see [llms.txt](https://ce-docs.keywordrush.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ce-docs.keywordrush.com/faq/how-to-add-offer-count-as-a-custom-field.md).

# How to add offer count as a custom field

**Update:** Content Egg now stores the total number of offers in the `_cegg_offers_count` meta field by default.

You can read more about this feature here:

[Offers Count (Badge & Shortcodes)](/woocommerce/offers-count-badge-and-shortcodes.md)

***

Add the following code to the `functions.php` file of your theme (preferably the child theme) to ensure future updates don’t overwrite your changes.

```php
add_action('content_egg_save_data', 'add_offer_count_in_custom_field', 20, 4);

function add_offer_count_in_custom_field($data, $module_id, $post_id, $is_last_iteration) {
    if (!$is_last_iteration) {
        return;
    }

    $field_name = 'offercount';  // Change this to your custom field name
    $data = \ContentEgg\application\components\ContentManager::getViewProductData($post_id);

    // Filter out items where 'stock_status' is not set or is -1
    $filtered_data = array_filter($data, function ($item) {
        return isset($item['stock_status']) && $item['stock_status'] != -1;
    });

    \update_post_meta($post_id, $field_name, count($filtered_data));
}

```

Note: The custom field will be updated when posts containing Content Egg offers are created or updated.
