Useful code snippets
Add Amazon shipping costs to product prices
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:
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.
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.
Last updated