add_action('woocommerce_before_calculate_totals', 'custom_multi_discount_rules', 9999); function custom_multi_discount_rules( $cart ) { if ( is_admin() && ! defined('DOING_AJAX') ) return; foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { if ( empty($cart_item['data']) ) continue; $product = $cart_item['data']; $product_id = (int) $cart_item['product_id']; $variation_id = !empty($cart_item['variation_id']) ? (int)$cart_item['variation_id'] : 0; $qty = (int) $cart_item['quantity']; // Basispreis frisch holen $base_id = $variation_id ? $variation_id : $product_id; $fresh_product = wc_get_product($base_id); if ( !$fresh_product ) continue; $base_price = (float) $fresh_product->get_price(); // ===================================== // REGEL 1: Polster polyester ab 3 Stück // ===================================== if ( isset($cart_item['variation']['attribute_pa_polster']) && strtolower($cart_item['variation']['attribute_pa_polster']) === 'polyester' && $qty >= 3 ) { $product->set_price( max($base_price - 4, 0) ); continue; } // ===================================== // REGEL 2: Fototasse ID 189 // ab 3 Stück mit gleicher Nummer // ===================================== if ( $product_id === 189 ) { $bildnummer = ''; if ( isset($cart_item['product_extras']['groups']) ) { foreach ( $cart_item['product_extras']['groups'] as $group ) { foreach ( $group as $field ) { if ( !empty($field['value']) ) { if ( preg_match('/(\d{7})/', $field['value'], $matches) ) { $bildnummer = $matches[1]; break 2; } } } } } if ( !empty($bildnummer) && $qty >= 3 ) { // aktueller Preis inkl. Add-ons $current_price = (float) $product->get_price(); $new_price = max( $current_price - 4, 0 ); $product->set_price( $new_price ); continue; } } // ===================================== // REGEL 3: Schlüsselanhänger ID 322 // ab 3 Stück mit gleicher Nummer // ===================================== if ( $product_id === 322 ) { $bildnummer = ''; if ( isset($cart_item['product_extras']['groups']) ) { foreach ( $cart_item['product_extras']['groups'] as $group ) { foreach ( $group as $field ) { if ( !empty($field['value']) ) { if ( preg_match('/(\d{7})/', $field['value'], $matches) ) { $bildnummer = $matches[1]; break 2; } } } } } if ( !empty($bildnummer) && $qty >= 3 ) { // aktueller Preis inkl. Add-ons $current_price = (float) $product->get_price(); $new_price = max( $current_price - 4, 0 ); $product->set_price( $new_price ); continue; } } } } // ===================================== // Rabatt-Hinweis anzeigen // ===================================== add_filter('woocommerce_get_item_data', 'custom_discount_notice_cart_multi', 10, 2); function custom_discount_notice_cart_multi($item_data, $cart_item) { $qty = isset($cart_item['quantity']) ? (int)$cart_item['quantity'] : 0; $product_id = (int)$cart_item['product_id']; // Polster if ( $qty >= 3 && isset($cart_item['variation']['attribute_pa_polster']) && strtolower($cart_item['variation']['attribute_pa_polster']) === 'polyester' ) { $item_data[] = array( 'name' => 'Rabatt', 'value' => 'Mengenrabatt (-4€ pro Stück)' ); } // Fototasse if ( $product_id === 189 && $qty >= 3 ) { $item_data[] = array( 'name' => 'Rabatt', 'value' => 'Fototassen-Rabatt (-4€ pro Stück)' ); } // Schlüsselanhänger if ( $product_id === 322 && $qty >= 3 ) { $item_data[] = array( 'name' => 'Rabatt', 'value' => 'Schlüsselanhänger-Rabatt (-4€ pro Stück)' ); } return $item_data; } https://www.nachbestellen.at/wp-sitemap-posts-page-1.xmlhttps://www.nachbestellen.at/wp-sitemap-posts-product-1.xmlhttps://www.nachbestellen.at/wp-sitemap-posts-x-portfolio-1.xmlhttps://www.nachbestellen.at/wp-sitemap-taxonomies-product_cat-1.xmlhttps://www.nachbestellen.at/wp-sitemap-taxonomies-portfolio-tag-1.xmlhttps://www.nachbestellen.at/wp-sitemap-taxonomies-portfolio-category-1.xmlhttps://www.nachbestellen.at/wp-sitemap-users-1.xml