Benutzerdefiniertes Feld für Produkte hinzufügen

add_action(‘woocommerce_product_options_general_product_data’, ‘add_custom_product_field’); function add_custom_product_field() { woocommerce_wp_text_input(array( ‘id’ => ‘custom_field’, ‘label’ => __(‘Benutzerdefiniertes Feld’, ‘woocommerce’), ‘placeholder’ => __(‘Geben Sie hier Informationen ein.’), ‘desc_tip’ => ‘true’, )); } add_action(‘woocommerce_process_product_meta’, ‘save_custom_product_field’); function save_custom_product_field($post_id) { $custom_field = $_POST[‘custom_field’]; if (!empty($custom_field)) { update_post_meta($post_id, ‘custom_field’, esc_attr($custom_field)); } }  

Lesen Sie Mehr

Versandoptionen basierend auf dem Warenkorbinhalt ausblenden

add_filter(‘woocommerce_package_rates’, ‘hide_shipping_based_on_cart_content’, 10, 2); function hide_shipping_based_on_cart_content($rates, $package) { $cart_contains_digital_products = false; foreach ($package[‘contents’] as $item) { $product = $item[‘data’]; if ($product->is_downloadable()) { $cart_contains_digital_products = true; break; } } if ($cart_contains_digital_products) { foreach ($rates as $rate_id => $rate) { if (‘flat_rate’ === $rate->method_id) { unset($rates[$rate_id]); // Flat Rate Versand entfernen } } } return $rates; } […]

Lesen Sie Mehr

Produkte aus bestimmten Kategorien auf der Shop-Seite ausblenden

add_action(‘pre_get_posts’, ‘exclude_products_from_categories’); function exclude_products_from_categories($query) { if (is_shop() && $query->is_main_query()) { $excluded_categories = array(7, 8, 9); // Kategorien, die ausgeschlossen werden sollen $query->set(‘tax_query’, array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘id’, ‘terms’ => $excluded_categories, ‘operator’ => ‘NOT IN’, ), )); } }  

Lesen Sie Mehr

Produktpreis basierend auf Benutzerstandort ändern

add_filter(‘woocommerce_product_get_price’, ‘adjust_price_by_user_location’, 10, 2); function adjust_price_by_user_location($price, $product) { $user_country = WC()->customer->get_billing_country(); if ($user_country == ‘US’) { $price = $price * 1.1; // 10% Aufschlag für US-Kunden } return $price; }  

Lesen Sie Mehr

Gutscheincode basierend auf Produktkategorie anwenden

add_action(‘woocommerce_before_cart’, ‘apply_coupon_based_on_category’); function apply_coupon_based_on_category() { $coupon_code = ‘CATEGORYCODE’; // Gutscheincode für bestimmte Kategorie $target_category = ‘sale’; // Name der Kategorie $cart = WC()->cart; $coupon_applied = false; foreach ($cart->get_cart() as $cart_item) { $product = $cart_item[‘data’]; if (has_term($target_category, ‘product_cat’, $product->get_id())) { $coupon_applied = true; break; } } if (!$coupon_applied) { $cart->apply_coupon($coupon_code); } }  

Lesen Sie Mehr

Versandkosten basierend auf dem Gewicht der Produkte ändern

add_filter(‘woocommerce_package_rates’, ‘adjust_shipping_costs_by_weight’, 10, 2); function adjust_shipping_costs_by_weight($rates, $package) { $total_weight = WC()->cart->get_cart_contents_weight(); if ($total_weight > 10) { foreach ($rates as $rate_id => $rate) { $rates[$rate_id]->cost += 7.00; // Zusätzliche Versandkosten für schwere Pakete } } return $rates; }  

Lesen Sie Mehr

Produkte in der Kategorie “Ausverkauf” ausblenden

add_action(‘pre_get_posts’, ‘exclude_sale_category_products’); function exclude_sale_category_products($query) { if (is_shop() && $query->is_main_query()) { $query->set(‘tax_query’, array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => ‘sale’, ‘operator’ => ‘NOT IN’, ), )); } }  

Lesen Sie Mehr

Versandkostenfrei ab einem bestimmten Betrag

add_filter(‘woocommerce_shipping_free_shipping_is_available’, ‘free_shipping_above_threshold’, 10, 2); function free_shipping_above_threshold($is_available, $package) { $free_shipping_threshold = 75; // Betrag, ab dem der Versand kostenlos ist $cart_total = WC()->cart->get_cart_contents_total(); if ($cart_total >= $free_shipping_threshold) { $is_available = true; } return $is_available; }  

Lesen Sie Mehr