function disable_emojis() { remove_action(‘wp_head’, ‘print_emoji_detection_script’, 7); remove_action(‘admin_print_scripts’, ‘print_emoji_detection_script’); remove_action(‘wp_print_styles’, ‘print_emoji_styles’); remove_action(‘admin_print_styles’, ‘print_emoji_styles’); remove_filter(‘the_content_feed’, ‘wp_staticize_emoji’); remove_filter(‘comment_text_rss’, ‘wp_staticize_emoji’); remove_filter(‘wp_mail’, ‘wp_staticize_emoji_for_email’); } add_action(‘init’, ‘disable_emojis’);
Kategorie: Snippets
Versandkostenfrei für Stammkunden aktivieren
add_filter(‘woocommerce_shipping_free_shipping_threshold’, ‘free_shipping_for_returning_customers’); function free_shipping_for_returning_customers($threshold) { if (is_user_logged_in() && current_user_can(‘customer_group’)) { $threshold = 0; // Versandkostenfrei für Stammkunden } return $threshold; }
Warenkorb automatisch leeren, wenn ein Produkt hinzugefügt wird
add_action(‘woocommerce_add_to_cart’, ’empty_cart_on_add’); function empty_cart_on_add() { WC()->cart->empty_cart(); }
Benutzerdefinierte Registerkarten auf der Produktseite erstellen
add_filter(‘woocommerce_product_tabs’, ‘custom_product_tabs’); function custom_product_tabs($tabs) { $tabs[‘custom_tab’] = array( ‘title’ => __(‘Zusätzliche Informationen’, ‘woocommerce’), ‘priority’ => 50, ‘callback’ => ‘custom_product_tab_content’ ); return $tabs; } function custom_product_tab_content() { echo ‘<h2>Zusätzliche Informationen</h2>’; echo ‘<p>Hier finden Sie weitere Informationen zu diesem Produkt.</p>’; }
Gutscheincode-Feld aus dem Warenkorb entfernen
add_action(‘init’, ‘remove_coupon_field_from_cart’); function remove_coupon_field_from_cart() { remove_action(‘woocommerce_before_cart’, ‘woocommerce_coupon_form’, 10); }
Versandkosten abhängig von der Anzahl der Artikel ändern
add_filter(‘woocommerce_package_rates’, ‘adjust_shipping_based_on_item_count’, 10, 2); function adjust_shipping_based_on_item_count($rates, $package) { $item_count = WC()->cart->get_cart_contents_count(); if ($item_count > 5) { foreach ($rates as $rate_id => $rate) { $rates[$rate_id]->cost += 2.00; // Zusätzliche Versandkosten ab 6 Artikeln } } return $rates; }
Preisnachlass für Produkte in der Kategorie “Sale”
add_filter(‘woocommerce_product_get_price’, ‘discount_sale_category_products’, 10, 2); function discount_sale_category_products($price, $product) { $sale_category = ‘sale’; // Name der Verkaufskategorie if (has_term($sale_category, ‘product_cat’, $product->get_id())) { $price = $price * 0.8; // 20% Rabatt für Produkte in der Verkaufskategorie } return $price; }
Benutzerdefinierte Meldung für ausverkaufte Produkte
add_filter(‘woocommerce_get_availability’, ‘custom_out_of_stock_message’, 1, 2); function custom_out_of_stock_message($availability, $product) { if (!$product->is_in_stock()) { $availability[‘availability’] = __(‘Leider ausverkauft – Bitte kontaktieren Sie uns für weitere Informationen.’, ‘woocommerce’); } return $availability; }
Benutzerdefiniertes Textfeld im Kassenformular hinzufügen
add_action(‘woocommerce_after_checkout_billing_form’, ‘custom_checkout_form_field’); function custom_checkout_form_field($checkout) { echo ‘<div id=”custom_checkout_field”><h2>’ . __(‘Zusätzliche Informationen’) . ‘</h2>’; woocommerce_form_field(‘custom_field’, array( ‘type’ => ‘text’, ‘class’ => array(‘form-row-wide’), ‘label’ => __(‘Benutzerdefiniertes Feld’), ‘placeholder’ => __(‘Geben Sie hier Ihre Informationen ein.’), ‘required’ => false, ), $checkout->get_value(‘custom_field’)); echo ‘</div>’; }
Zusätzliche Versandgebühr basierend auf dem Land hinzufügen
add_filter(‘woocommerce_cart_calculate_fees’, ‘add_additional_shipping_fee’); function add_additional_shipping_fee() { $shipping_country = WC()->customer->get_shipping_country(); if ($shipping_country == ‘US’) { WC()->cart->add_fee(‘Zusätzliche Versandgebühr’, 10.00); } }