> 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/customization/useful-code-snippets.md).

# Useful code snippets

### Add Amazon shipping costs to product prices

```php
add_filter('cegg_view_data_prepare', 'add_amazon_shipping', 10, 4);

function add_amazon_shipping($data, $module_id, $post_id, $params)
{
    // Check if the module is related to Amazon
    if (strpos($module_id, 'Amazon') === false) {
        return $data;
    }

    // Loop through the items and add shipping cost
    foreach ($data as $key => $item) {
        $shipping = calculate_amazon_shipping($item); // Custom function to calculate shipping
        $data[$key]['price'] += $shipping; // Add shipping cost to the price
        $data[$key]['shipping_cost'] = $shipping; // Store shipping cost in data array
    }

    return $data;
}


function calculate_amazon_shipping($item)
{
    // Example price-based shipping rates (adjust as necessary)
    $price = isset($item['price']) ? $item['price'] : 0;
    
    if ($price >= 29) {
        // Free shipping for orders over €29
        return 0;
    } elseif ($price >= 10) {
        // Standard shipping rate for orders between €10 and €29
        return 2.99;
    } else {
        // Higher shipping rate for orders under €10
        return 4.99;
    }
}
```

### Disable or rename the group of imported products

To disable (or rename) the group name for products imported with Import Tools, use the following code:

```php
add_filter( 'cegg_import_product_group', function( $group ) {
    return '';
});
```

### Available modules per post type

Content Egg settings decide on which post types the plugin is used. This snippet goes one step further and decides which modules are offered on each of them — feed modules on your product post type, affiliate and Offer modules on deals, and so on. Post types you don't list keep all their modules.

```php
add_filter('content_egg_metabox_modules', function ($module_ids, $post_id = 0) {

    // Post type => modules available there.
    $map = array(
        'product' => array('Feed__1', 'Feed__2', 'Amazon'),
        'deals'   => array('Amazon', 'Ebay', 'Offer'),
        'post'    => array('CjLinks', 'Offer'),
    );

    $post_type = $post_id ? get_post_type($post_id) : get_post_type();

    if (!$post_type || !isset($map[$post_type])) {
        return $module_ids;
    }

    // Every module named in the map above.
    $controlled = array_unique(call_user_func_array('array_merge', array_values($map)));

    // Keep a module if you never listed it, or if it is allowed here. Modules of
    // other families (coupons, images, videos) are left untouched this way.
    return array_values(array_filter($module_ids, function ($id) use ($map, $post_type, $controlled) {
        return !in_array($id, $controlled, true)
            || in_array($id, $map[$post_type], true);
    }));

}, 10, 2);
```

A module's ID is the last part of its settings page URL: `admin.php?page=content-egg-modules--Amazon` means the ID is `Amazon`. Feed modules are `Feed__1`, `Feed__2` and so on.

{% hint style="info" %}
This affects the editor only. Which modules update their data is decided by each module's own settings and by the autoupdate keywords saved in the post, and the Prefill tool has its own module selection. See [Filter: Available Modules per Post](/customization/fordevelopers.md#filter-available-modules-per-post).
{% endhint %}
