Mit kleinen Code-Snippets kannst du WooCommerce ohne zusätzliche Plugins erweitern. Hier sind 10 praktische Snippets, die ich regelmäßig in Kundenprojekten einsetze.
1. Mindestbestellwert festlegen
Setze einen Mindestbestellwert für den Checkout:
add_action('woocommerce_checkout_process', 'wc_minimum_order_amount');
function wc_minimum_order_amount() {
$minimum = 50; // Mindestbestellwert in Euro
if (WC()->cart->total < $minimum) {
wc_add_notice(
sprintf('Der Mindestbestellwert beträgt %s€. Aktueller Warenkorbwert: %s€',
$minimum,
WC()->cart->total
), 'error'
);
}
}
2. Kostenloser Versand ab Betrag X
Zeige dem Kunden, wie viel noch für kostenlosen Versand fehlt:
add_action('woocommerce_before_cart', 'free_shipping_notice');
function free_shipping_notice() {
$min_amount = 75;
$current = WC()->cart->subtotal;
if ($current < $min_amount) {
$remaining = $min_amount - $current;
wc_print_notice(
sprintf('Noch %s€ bis zum kostenlosen Versand!',
number_format($remaining, 2, ',', '.')),
'notice'
);
}
}
3. Verkaufte Menge anzeigen
Zeige wie oft ein Produkt bereits verkauft wurde:
add_action('woocommerce_single_product_summary', 'show_sold_count', 11);
function show_sold_count() {
global $product;
$units_sold = $product->get_total_sales();
if ($units_sold > 0) {
echo '<p class="sold-count">' . $units_sold . 'x verkauft</p>';
}
}
4. Warenkorb-Button Text ändern
add_filter('woocommerce_product_single_add_to_cart_text', 'custom_cart_button_text');
function custom_cart_button_text() {
return 'Jetzt bestellen';
}
5. Automatischer Gutschein bei erstem Kauf
add_action('woocommerce_before_cart', 'apply_first_order_coupon');
function apply_first_order_coupon() {
if (!is_user_logged_in()) return;
$user_id = get_current_user_id();
$order_count = wc_get_customer_order_count($user_id);
if ($order_count == 0) {
$coupon_code = 'WELCOME10';
if (!WC()->cart->has_discount($coupon_code)) {
WC()->cart->apply_coupon($coupon_code);
}
}
}
6. Kategorien auf Produktseite ausblenden
remove_action('woocommerce_single_product_summary',
'woocommerce_template_single_meta', 40);
7. Warenkorb automatisch aktualisieren
add_action('wp_footer', 'cart_auto_update');
function cart_auto_update() {
if (is_cart()) {
?>
<script>
jQuery('div.woocommerce').on('change', 'input.qty', function(){
jQuery("[name='update_cart']").trigger('click');
});
</script>
<?php
}
}
8. Checkout-Felder entfernen
add_filter('woocommerce_checkout_fields', 'remove_checkout_fields');
function remove_checkout_fields($fields) {
unset($fields['billing']['billing_company']);
unset($fields['order']['order_comments']);
return $fields;
}
9. Lagerbestand im Shop anzeigen
add_action('woocommerce_after_shop_loop_item_title', 'show_stock_shop', 10);
function show_stock_shop() {
global $product;
if ($product->is_in_stock()) {
echo '<span class="stock in-stock">✓ Auf Lager</span>';
} else {
echo '<span class="stock out">Ausverkauft</span>';
}
}
10. Thank-You Page personalisieren
add_action('woocommerce_thankyou', 'custom_thankyou_text');
function custom_thankyou_text($order_id) {
$order = wc_get_order($order_id);
echo '<div class="thankyou-custom">';
echo '<h3>Danke, ' . $order->get_billing_first_name() . '!</h3>';
echo '<p>Bestellung #' . $order_id . ' ist eingegangen.</p>';
echo '</div>';
}
Wo einfügen?
Diese Snippets gehören in die functions.php deines Child-Themes oder in ein Code-Snippets Plugin.
Teste Snippets immer erst auf einer Staging-Umgebung!