Liebe woocommerce Profis!
Ich möchte meinen Kunden von http://www.kernoelpepi.com ab einem Mindestbestellwert von 80€ ein Geschenk machen.
Dafür möchte ich automatisch ein Gratis Produkt in den Warenkorb legen, wenn der Mindestbestellwert von 80€ erreicht wurde.
Das habe ich bereits mit einem snippet von hier: Link geschafft.
Allerdings besteht nun noch der Schönheitsfehler, dass das Produkt nicht mehr aus dem Warenkorb verschwindet, wenn dieser wieder unter 80€ sinkt.
Bzw. kann man das gratis Produkt nicht mehr aus dem Warenkorb entfernen, wenn man es nicht in Anspruch nehmen möchte.
Habt Ihr Tipps für mich, wie ich dieses Verhalten erzwingen kann?
Hier noch der Code, den ich in meiner functions.php vom childtheme eingesetzt habe:
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 2527;
$found = false;
$cart_total > 79;
if( $woocommerce->cart->total >= $cart_total ) {
//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 );
}
}
}
}
Alles anzeigen
Vielen Dank!
Liebe Gruesse, Pepi