1.
Paket
auswählen

 

 

 

 

2.
Domain
angeben

 

 

 

 

3.
Screenshots
hochladen

 

 

 

4.
Wir
kümmern
uns darum!

 

Inhaltsverzeichnis

Sie möchten gern eine Promotion für ein spezielles Produkt in Ihrem WooCommerce Onlineshop erstellen. Bei dieser Aktion soll automatisch ein bestimmtes Produkt in den Warenkorb abgelegt werden? Dann haben wir hier die Lösung für Sie…ganz ohne Plugin.

Tipp: Halten Sie die Anzahl der WordPress Plugins so gering wie möglich.

Anleitung: Öffnen Sie die functions.php Datei in Ihrem WordPress Theme / Child Theme und fügen folgenden Code ein. Ersetzen Sie die gewünschte Produkt ID (in Orange) mit Ihrem ProduktI, welches sich später im Warenkorb befinden soll.

// add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 99;
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found )
$woocommerce->cart->add_to_cart( $product_id );
} else {
// if no products in cart, add it
$woocommerce->cart->add_to_cart( $product_id );
}
}
}

Das war’s schon.
Cache leeren und den Warenkorb nochmal neu laden. Dann sollte das Produkt automatisch im Warenkorb erscheinen.