// === WooCommerce kortingen toepassen op subsites met thema 'svmshop' === add_action('woocommerce_before_calculate_totals', function ($cart) { if (is_admin() || !is_multisite() || is_main_site() || did_action('woocommerce_before_calculate_totals') >= 2) return; $theme = wp_get_theme(); if ($theme->get_stylesheet() !== 'svmshop') return; switch_to_blog(1); $rules = get_site_option('multistore_discounts_rules', []); restore_current_blog(); $weekday = strtolower(date('l')); $today = date('Y-m-d'); foreach ($cart->get_cart() as $cart_item_key => $item) { $product = $item['data']; $name = $product->get_name(); $categories = wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'slugs']); foreach ($rules as $rule) { if (!empty($rule['start_date']) && $today < $rule['start_date']) continue; if (!empty($rule['end_date']) && $today > $rule['end_date']) continue; if (!empty($rule['weekdays']) && is_array($rule['weekdays']) && !in_array($weekday, $rule['weekdays'])) continue; $match = false; if ($rule['type'] === 'product' && !empty($rule['target_product']) && strcasecmp($name, $rule['target_product']) === 0) { $match = true; } elseif ($rule['type'] === 'category' && !empty($rule['target_category']) && in_array($rule['target_category'], $categories)) { $match = true; } if (!$match || $rule['mode'] !== 'percentage') continue; $discount = floatval($rule['discount']); if ($discount > 0 && $discount < 100) { wc_add_notice("✅ Korting van {$discount}% toegepast op: $name", 'success'); $price = $product->get_price(); $product->set_price($price * (1 - ($discount / 100))); } } } }, 20, 1); // === BOGO toepassen via negatieve fee === add_action('woocommerce_cart_calculate_fees', function ($cart) { if (is_admin() || !is_multisite() || is_main_site()) return; $theme = wp_get_theme(); if ($theme->get_stylesheet() !== 'svmshop') return; switch_to_blog(1); $rules = get_site_option('multistore_discounts_rules', []); restore_current_blog(); $weekday = strtolower(date('l')); $today = date('Y-m-d'); foreach ($rules as $rule) { if ($rule['mode'] !== 'bogo') continue; if (!empty($rule['start_date']) && $today < $rule['start_date']) continue; if (!empty($rule['end_date']) && $today > $rule['end_date']) continue; if (!empty($rule['weekdays']) && is_array($rule['weekdays']) && !in_array($weekday, $rule['weekdays'])) continue; $buy = intval($rule['bogo_qty']); $free = intval($rule['bogo_free']); if ($buy <= 0 || $free <= 0) continue; foreach ($cart->get_cart() as $cart_item_key => $item) { $product = $item['data']; $name = $product->get_name(); $categories = wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'slugs']); $match = false; if ($rule['type'] === 'product' && !empty($rule['target_product']) && strcasecmp($name, $rule['target_product']) === 0) { $match = true; } elseif ($rule['type'] === 'category' && !empty($rule['target_category']) && in_array($rule['target_category'], $categories)) { $match = true; } if (!$match) continue; $quantity = $item['quantity']; $multiplier = floor($quantity / $buy); if ($multiplier < 1) continue; $free_product_name = $rule['free_product'] ?? ''; $product_id = null; if (!empty($free_product_name)) { $post = get_page_by_title($free_product_name, OBJECT, 'product'); if ($post) $product_id = $post->ID; } else { $product_id = $product->get_id(); } if (!$product_id) continue; $gift_product = wc_get_product($product_id); if (!$gift_product) continue; $gift_price = $gift_product->get_price() * $free * $multiplier; $cart->add_fee(__('Gratis product (BOGO)', 'multistore-discounts'), -$gift_price); } } }, 30); https://staging.slagerijvanmelik.nl/corio/post-sitemap.xml 2021-08-13T08:16:03+00:00 https://staging.slagerijvanmelik.nl/corio/page-sitemap.xml 2025-06-12T10:10:19+00:00 https://staging.slagerijvanmelik.nl/corio/product-sitemap.xml 2025-09-15T14:06:17+00:00 https://staging.slagerijvanmelik.nl/corio/category-sitemap.xml 2021-08-13T08:16:03+00:00 https://staging.slagerijvanmelik.nl/corio/product_cat-sitemap.xml 2025-09-15T14:06:17+00:00 https://staging.slagerijvanmelik.nl/corio/product_tag-sitemap.xml 2025-09-10T09:30:40+00:00