/**
 * Automatische Set-Up Gebühr für Kürbisfest-Werbepakete
 * 
 * Fügt die Set-Up Gebühr automatisch hinzu, sobald mindestens ein Kürbisfest-Paket
 * im Warenkorb liegt. Entfernt sie wieder, sobald kein Kürbisfest-Paket mehr
 * im Warenkorb liegt.
 */

add_action('woocommerce_before_calculate_totals', 'cremondi_auto_setup_fee_product_for_kuerbisfest', 20, 1);

function cremondi_auto_setup_fee_product_for_kuerbisfest($cart) {
    if (is_admin() && !defined('DOING_AJAX')) {
        return;
    }

    if (!$cart || $cart->is_empty()) {
        return;
    }

    // Produkt-IDs der Kürbisfest-Werbepakete
    $kuerbis_product_ids = array(
        12858, // Riesen-Kürbis
        12866, // Kronen-Kürbis
        12874, // Butternut-Kürbis
        12870  // Hokkaido-Kürbis
    );

    // Produkt-ID der Kürbisfest Set-Up Gebühr
    $setup_product_id = 12902;

    $has_kuerbis_product = false;
    $setup_cart_key = false;

    foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
        $product_id = (int) $cart_item['product_id'];

        if (in_array($product_id, $kuerbis_product_ids, true)) {
            $has_kuerbis_product = true;
        }

        if ($product_id === $setup_product_id) {
            $setup_cart_key = $cart_item_key;
        }
    }

    // Set-Up Gebühr hinzufügen, wenn Kürbisfest-Paket vorhanden ist
    if ($has_kuerbis_product && !$setup_cart_key) {
        $cart->add_to_cart($setup_product_id, 1);
    }

    // Set-Up Gebühr entfernen, wenn kein Kürbisfest-Paket mehr vorhanden ist
    if (!$has_kuerbis_product && $setup_cart_key) {
        $cart->remove_cart_item($setup_cart_key);
    }

    // Set-Up Gebühr immer auf Menge 1 setzen
    if ($has_kuerbis_product && $setup_cart_key) {
        $cart->set_quantity($setup_cart_key, 1, false);
    }
}


/**
 * Menge der Set-Up Gebühr im Warenkorb fix auf 1 setzen.
 */

add_filter('woocommerce_cart_item_quantity', 'cremondi_disable_setup_fee_quantity_field', 10, 3);

function cremondi_disable_setup_fee_quantity_field($product_quantity, $cart_item_key, $cart_item) {
    $setup_product_id = 12902; // Kürbisfest Set-Up Gebühr

    if ((int) $cart_item['product_id'] === $setup_product_id) {
        return '<span>1</span>';
    }

    return $product_quantity;
}


/**
 * Entfernen-Link für die Set-Up Gebühr ausblenden.
 */

add_filter('woocommerce_cart_item_remove_link', 'cremondi_hide_remove_link_for_setup_fee', 10, 2);

function cremondi_hide_remove_link_for_setup_fee($link, $cart_item_key) {
    $setup_product_id = 12902; // Kürbisfest Set-Up Gebühr

    if (!WC()->cart) {
        return $link;
    }

    $cart_item = WC()->cart->get_cart_item($cart_item_key);

    if ($cart_item && (int) $cart_item['product_id'] === $setup_product_id) {
        return '';
    }

    return $link;
}<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//cremondi.de/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://cremondi.de/page-sitemap.xml</loc>
		<lastmod>2026-05-26T22:12:20+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://cremondi.de/product-sitemap.xml</loc>
		<lastmod>2026-05-26T22:44:20+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://cremondi.de/product_cat-sitemap.xml</loc>
		<lastmod>2026-05-26T22:44:20+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://cremondi.de/pa_plott-sitemap.xml</loc>
		<lastmod>2025-12-17T07:50:40+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://cremondi.de/local-sitemap.xml</loc>
		<lastmod>2026-05-26T22:48:06+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->