Kaution – Sicherheitsleistung (rückerstattbar)

add_action(‚woocommerce_before_calculate_totals‘, ‚cp_handle_mandatory_deposit‘); add_filter(‚woocommerce_cart_item_remove_link‘, ‚cp_disable_deposit_removal‘, 10, 2); function cp_handle_mandatory_deposit($cart) { if (is_admin() && !defined(‚DOING_AJAX‘)) return; if ($cart->is_empty()) return; $deposit_product_id = 1599; // 🔴 HIER die Produkt-ID der Kaution eintragen $has_deposit = false; foreach ($cart->get_cart() as $cart_item) { if ($cart_item[‚product_id‘] == $deposit_product_id) { $has_deposit = true; } } if (!$has_deposit) { $cart->add_to_cart($deposit_product_id); } } function cp_disable_deposit_removal($link, $cart_item_key)…

Category:

Beschreibung

add_action(‚woocommerce_before_calculate_totals‘, ‚cp_handle_mandatory_deposit‘);
add_filter(‚woocommerce_cart_item_remove_link‘, ‚cp_disable_deposit_removal‘, 10, 2);

function cp_handle_mandatory_deposit($cart) {
if (is_admin() && !defined(‚DOING_AJAX‘)) return;
if ($cart->is_empty()) return;

$deposit_product_id = 1599; // 🔴 HIER die Produkt-ID der Kaution eintragen
$has_deposit = false;

foreach ($cart->get_cart() as $cart_item) {
if ($cart_item[‚product_id‘] == $deposit_product_id) {
$has_deposit = true;
}
}

if (!$has_deposit) {
$cart->add_to_cart($deposit_product_id);
}
}

function cp_disable_deposit_removal($link, $cart_item_key) {
$deposit_product_id = 123; // 🔴 gleiche Produkt-ID wie oben

$cart_item = WC()->cart->get_cart()[$cart_item_key];
if ($cart_item[‚product_id‘] == $deposit_product_id) {
return “; // ❌ Entfernen-Button ausblenden
}
return $link;
}