WooCommerce Preise und Warenkorb-Button für Produkte in Kategorie ausblenden

Das folgende Snippet deaktiviert die Anzeige von Preisen und den Warenkorb-Button für Produkte in einer spezifischen Kategorie. In den zwei Funktionen muss jeweils die Variable „$category_slug“ an die von euch gewünschte Kategorie angepasst werden.

				
					function hide_prices_and_add_to_cart_button_in_category() {
    // Define the category slug for which prices and "Add to Cart" button will be hidden
    $category_slug = 'your-category-slug';

    // Check if the current page is a WooCommerce product category
    if (is_product_category($category_slug)) {
        // Hide prices
        remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);

        // Hide "Add to Cart" button
        remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
    }
}
add_action('wp', 'hide_prices_and_add_to_cart_button_in_category');

function hide_price_and_add_to_cart_button() {
    // Get the product categories for the current product
    $categories = get_the_terms(get_the_ID(), 'product_cat');

    // Define the category slug for which the price and "Add to Cart" button will be hidden
    $category_slug = 'your-category-slug';

    // Check if the product belongs to the specified category
    if ($categories && !is_wp_error($categories)) {
        foreach ($categories as $category) {
            if ($category->slug === $category_slug) {
                // Hide price
                remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);

                // Hide "Add to Cart" button
                remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
                break;
            }
        }
    }
}
add_action('woocommerce_before_single_product', 'hide_price_and_add_to_cart_button');
				
			
Kontakt

Bürozeiten:
Montag – Donnerstag: 9:00 – 17:00 Uhr
Freitag: 9:00 – 14:00 Uhr