Beschreibung
/**
* =========================================================
* CapturePoint – Kaution 150 €
* Standard = Blacklist (Kaution Pflicht)
* Whitelist = keine Kaution
* =========================================================
*/
add_action(‚woocommerce_before_calculate_totals‘, function ($cart) {
if (is_admin() && !defined(‚DOING_AJAX‘)) return;
if (!$cart || $cart->is_empty()) return;
/* ===============================
* KONFIGURATION
* =============================== */
$config = [
// 🔴 HIER DEINE Kautions-Produkt-ID EINTRAGEN
‚deposit_product_id‘ => 1600, // <-- hier anpassen
> 150,
// ❗ false = 150 € pro Bestellung (nicht pro Kamera)
‚deposit_per_item‘ => false,
// ✅ WHITELIST – keine Kaution
‚whitelist_emails‘ => [
‚testkunde@email.de‘,
‚vip@email.de‘,
],
];
/* ===============================
* EMAIL PRÜFEN
* =============================== */
$email = “;
if (WC()->customer) {
$email = strtolower(trim(WC()->customer->get_billing_email()));
}
$is_whitelisted = in_array($email, $config[‚whitelist_emails‘], true);
/* ===============================
* Kaution aus Warenkorb entfernen
* =============================== */
foreach ($cart->get_cart() as $key => $item) {
if ($item[‚product_id‘] == $config[‚deposit_product_id‘]) {
$cart->remove_cart_item($key);
}
}
/* ===============================
* WHITELIST → KEINE KAUTION
* =============================== */
if ($is_whitelisted) {
return;
}
/* ===============================
* BLACKLIST (STANDARD) → KAUTION
* =============================== */
$qty = 1;
if ($config[‚deposit_per_item‘]) {
foreach ($cart->get_cart() as $item) {
if ($item[‚product_id‘] != $config[‚deposit_product_id‘]) {
$qty += $item[‚quantity‘];
}
}
}
$cart->add_to_cart(
$config[‚deposit_product_id‘],
$qty,
0,
[],
[‚_deposit_lock‘ => true]
);
}, 20);
/* =========================================================
* VERHINDERT ENTFERNEN DER KAUTION
* ========================================================= */
add_filter(‚woocommerce_cart_item_remove_link‘, function ($link, $cart_item_key) {
$item = WC()->cart->get_cart()[$cart_item_key] ?? null;
if (!empty($item[‚_deposit_lock‘])) {
return “;
}
return $link;
}, 10, 2);

