> For the complete documentation index, see [llms.txt](https://ei-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://ei-docs.keywordrush.com/for-developers/hooks.md).

# Useful hooks

### How to Enable This Filter

To enable these filters, **paste the code into the `functions.php` file of your active theme** (preferably a **child theme**) by following these steps:

* Go to **Appearance → Theme File Editor** in your WordPress dashboard,\
  or access the file via **FTP / file manager**.
* Open the `functions.php` file.
* Paste the code at the bottom of the file and save.

*Using a child theme is recommended to avoid losing changes during theme updates.*

### Disabling synchronization for selected products

To disable synchronization for selected products, add the following to the functions.php file of your theme:

```php
add_filter('ei_disable_sync_product_ids', 'my_ei_disable_sync_product_ids');
function my_ei_disable_sync_product_ids() {
    return array(111, 222, 333, 444);
}
```

Replace 111, 222, 333, 444 with the actual product IDs.

### Enabling synchronization only for selected products

```php
/**
 * Only sync products 101, 202 and 303.
 *
 * @param int[] $ids  Current list of IDs to sync (empty by default).
 * @return int[]      Filtered list of IDs to sync.
 */
add_filter( 'ei_enable_sync_product_ids', function( $ids ) {
    // Override any existing list—only these three will be synced.
    return array( 101, 202, 303 );
} );

```

```php
/**
 * Enabling synchronization only for products in a specific category.
 *
 * @param int[] $ids  Current list of product IDs to sync (empty by default).
 * @return int[]      Product IDs belonging to the 'featured-products' category.
 */
add_filter( 'ei_enable_sync_product_ids', function( $ids ) {
    // You can change 'featured-products' to any category slug
    $category_slug = 'featured-products';

    // This runs on every sync, so for large catalogs, consider caching the IDs
    $products_in_category = get_posts([
        'post_type'      => 'product',
        'posts_per_page' => -1,
        'fields'         => 'ids',
        'tax_query'      => [
            [
                'taxonomy' => 'product_cat',
                'field'    => 'slug',
                'terms'    => $category_slug,
            ],
        ],
    ]);

    return $products_in_category;
} );

```

### **Allowing HTML and images in product descriptions**

To disable description sanitization and include all images and HTML formatting from the source site, add the following to the functions.php file of your theme:

```php
add_filter('cegg_description_sanitization', '__return_false');
```

### Import domain as brand taxonomy

For the Rehub theme only, to import the domain as the "brand" taxonomy, add the following to your functions.php file:

```php
add_filter('ie_import_brand', '__return_false');
add_filter('ie_import_store', '__return_true');
```

### Custom parameters for scraping services

```php
// Add country_code parameter to ScraperAPI requests
add_filter('ei_parse_url_scraperapi', 'my_ei_parse_url_scraperapi', 10, 1);
function my_ei_parse_url_scraperapi($url) {
    return add_query_arg('country_code', 'de', $url);
}

// Add country parameter to ScrapingDog requests
add_filter('ei_parse_url_scrapingdog', 'my_ei_parse_url_scrapingdog_country', 10, 1);
function my_ei_parse_url_scrapingdog_country($url) {
    return add_query_arg('country', 'de', $url);
}

// Add dynamic parameter to ScrapingDog requests
add_filter('ei_parse_url_scrapingdog', 'my_ei_parse_url_scrapingdog_dynamic', 10, 1);
function my_ei_parse_url_scrapingdog_dynamic($url) {
    return add_query_arg('dynamic', 'true', $url);
}

// Add premium parameter to ScrapingDog requests
add_filter('ei_parse_url_scrapingdog', 'my_ei_parse_url_scrapingdog_premium', 10, 1);
function my_ei_parse_url_scrapingdog_premium($url) {
    return add_query_arg('premium', 'yes', $url);
}
```

### Importing variations differently for selected stores

The **Variations** import setting applies to all stores. The `ei_variations_import_mode` filter changes it for selected stores. Return one of these values:

* `separate` – separate simple products
* `variable` – one variable product
* `disabled` – don't import variations

`$product->domain` is the store domain in lowercase, without `www.` and subdomains, for example `klintensiv.ro`.

**Separate products for one store only.** The setting stays **As one variable product**; products from `klintensiv.ro` are imported as separate simple products:

```php
add_filter('ei_variations_import_mode', function ($mode, $product, $params) {
    if ($product->domain === 'klintensiv.ro')
        return 'separate';

    return $mode;
}, 10, 3);
```

**Variable products for one store only.** The setting is **As separate simple products**; products from `vetro.ro` are still imported as one variable product:

```php
add_filter('ei_variations_import_mode', function ($mode, $product, $params) {
    if ($product->domain === 'vetro.ro')
        return 'variable';

    return $mode;
}, 10, 3);
```

**Several stores:**

```php
add_filter('ei_variations_import_mode', function ($mode, $product, $params) {
    $separate = array('klintensiv.ro', 'junsun-china.com', 'dynavin.de');

    if (in_array($product->domain, $separate, true))
        return 'separate';

    return $mode;
}, 10, 3);
```

The filter is used when a product is imported. Products imported earlier keep their type. See [Importing variations](https://ei-docs.keywordrush.com/importing-to-woocommerce/importing-variations.md).

### Moving products to new links without checking the old one

With [Existing SKU](https://ei-docs.keywordrush.com/importing-to-woocommerce/general-information.md#when-a-store-changes-its-product-links) enabled, a product is moved to its new link only when the old link returns 404 or 410. If the store answers old links differently (for example, redirects them to the home page), turn the check off:

```php
add_filter('ei_sku_relink_require_gone_url', '__return_false');
```

### Tuning synchronization

These filters change how the background synchronization queue behaves. The defaults suit most sites – the [Sync status](https://ei-docs.keywordrush.com/synchronizing-products/sync-status.md) page will tell you if yours cannot keep up before you reach for these.

```php
// How many products may be queued for updating at once. Kept small so that
// WooCommerce's own background jobs are not stuck behind product updates.
add_filter('ei_sync_queue_window', function ($window) {
    return 50;
});

// How many products from the same store may be updated at the same time.
add_filter('ei_sync_domain_concurrency', function ($limit) {
    return 5;
});

// How often the plugin checks for products that are due, in seconds.
add_filter('ei_sync_dispatch_interval', function ($seconds) {
    return 120;
});

// Daily request limit for one store, overriding the Extractor setting.
add_filter('ei_sync_daily_limit', function ($limit, $domain) {
    return $domain === 'amazon.de' ? 2000 : $limit;
}, 10, 2);

// The daily limit is normally spent gradually through the day. Return false to
// allow it to be used as fast as the queue can go.
add_filter('ei_sync_daily_pacing', '__return_false');

// A product whose update never finishes - a source that hangs until the
// request times out - is paused after this many attempts, and retried no more
// often than the backoff below.
add_filter('ei_sync_max_attempts', function ($attempts) {
    return 10;
});

add_filter('ei_sync_attempt_backoff', function ($seconds) {
    return 2 * HOUR_IN_SECONDS;
});

// Turn scheduled synchronization off entirely without changing the settings.
add_filter('ei_sync_enabled', '__return_false');

// How often the backlog is counted for the admin warning, in seconds. This is
// a scan of every imported product, so it runs in the background twice a day
// rather than while anyone is waiting for a page.
add_filter('ei_sync_backlog_scan_interval', function ($seconds) {
    return 6 * HOUR_IN_SECONDS;
});
```

{% hint style="info" %}
`ei_sync_product_limit` still works and now sets the size of the queue, so existing code that used it keeps behaving sensibly.
{% endhint %}
