Zum Inhalt springen
Startseite » Woocommerce Snippets » Alles für einen Preis

Alles für einen Preis

Dieses Snippet entfernt alle Instanzen der Schaltfläche „In den Warenkorb“ unabhängig vom Produkttyp (einfach, gruppiert, variabel, extern) und zeigt dann eine neue Schaltfläche sowohl auf den Produkten der Archivschleife als auch auf der einzelnen Produktvorlage mit der Aufschrift „Preis auf Anfrage“ an. Wenn Sie auf diese Schaltfläche klicken, wird ein Hyperlink zu einer benutzerdefinierten Telefonnummer erstellt, die beim Klicken angerufen wird. Dieser Leitfaden ist nützlich, wenn Sie nicht möchten, dass Benutzer die Preise sehen und von ihnen einen Anruf verlangen, anstatt Produkte in den Warenkorb zu legen.

// First, remove all instances of the add to cart button
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

// Show a new 'Call for a price' button on the product archive loop items
function ecommercehints_call_for_a_price_on_product_archive_loop() {
   echo '<a class="button" href="tel:+49216617651">Preis auf Anfrage</a>';	// Telephone number and button text
};
add_action ('woocommerce_after_shop_loop_item', 'ecommercehints_call_for_a_price_on_product_archive_loop', 10, 0);

// Show a new 'Call for a price' button on the single product template
function ecommercehints_call_for_a_price_on_single_product_template() {
   echo '<a class="button" href="tel:+49216617651">Preis auf Anfrage</a>';	// Telephone number and button text
};
add_action ('woocommerce_single_product_summary', 'ecommercehints_call_for_a_price_on_single_product_template', 25, 0);