// Bonus products
$product_1 = '4751';
$product_2 = '4752';
$product_3 = '4753';
// Get cart value in a clean format
$cart_total = WC()->cart->get_cart_subtotal();
$cart_total = html_entity_decode($cart_total, ENT_QUOTES, 'UTF-8');
$cart_total_format = strip_tags($cart_total);
$cart_value = preg_filter("/[^0-9]/", "", $cart_total_format);
$sum_raw = $cart_value;
// Set the sum level
$level3 = '1500';
// Check sum and apply product
if ($sum_raw >= $level3) {
// Cycle through each product in the cart and check for match
$found = 'false';
foreach (WC()->cart->cart_contents as $item) {
global $product;
$product_id = $item['variation_id'];
if ($product_id == $product_3) {
$found = 'true';
}
}
// If product found we do nothing
if ($found == 'true') {}
// else we will add it
else {
//We add the product
WC()->cart->add_to_cart($product_3);
< /code>
Wenn der Kunde entscheidet, Elemente zu entfernen, ist diese Anweisung wahr. [url=viewtopic.php?t=14917]Ich möchte[/url] sie erneut entfernen können.if ($sum_raw < $level3) {
// Trying to remove item
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['variation_id'] == $product_3) {
//remove single product
WC()->cart->remove_cart_item($product_3);
}
}
}
< /code>
Am nicht gelegen, das Produkt aus dem Warenkorb zu entfernen. Irgendwelche Ideen, was hier falsch geht? Ich habe herum gesucht, ohne eine Lösung zu finden, die für mich funktioniert. < /p>
Lösung < /strong> < /p>
Mit Hilfe von @rohil_phpBegglner & @WISDMLABS bin ich zu dieser Lösung gekommen, die den Job für mich erledigte. < /p>
global $woocommerce;
// Check if sum
if ($sum_raw < $level3) {
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['variation_id'] == $product_3) {
//remove single product
$woocommerce->cart->remove_cart_item($cart_item_key);
}
}
}
// Get cart value in a clean format $cart_total = WC()->cart->get_cart_subtotal(); $cart_total = html_entity_decode($cart_total, ENT_QUOTES, 'UTF-8'); $cart_total_format = strip_tags($cart_total); $cart_value = preg_filter("/[^0-9]/", "", $cart_total_format); $sum_raw = $cart_value;
// Set the sum level $level3 = '1500';
// Check sum and apply product if ($sum_raw >= $level3) {
// Cycle through each product in the cart and check for match $found = 'false'; foreach (WC()->cart->cart_contents as $item) { global $product; $product_id = $item['variation_id'];
if ($product_id == $product_3) { $found = 'true'; } }
// If product found we do nothing if ($found == 'true') {} // else we will add it else { //We add the product WC()->cart->add_to_cart($product_3); < /code>
Wenn der Kunde entscheidet, Elemente zu entfernen, ist diese Anweisung wahr. [url=viewtopic.php?t=14917]Ich möchte[/url] sie erneut entfernen können.if ($sum_raw < $level3) {
// Trying to remove item foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) { if ($cart_item['variation_id'] == $product_3) {
//remove single product WC()->cart->remove_cart_item($product_3); } } } < /code>
Am nicht gelegen, das Produkt aus dem Warenkorb zu entfernen. Irgendwelche Ideen, was hier falsch geht? Ich habe herum gesucht, ohne eine Lösung zu finden, die für mich funktioniert. < /p>
Lösung < /strong> < /p>
Mit Hilfe von @rohil_phpBegglner & @WISDMLABS bin ich zu dieser Lösung gekommen, die den Job für mich erledigte. < /p>
global $woocommerce; // Check if sum if ($sum_raw < $level3) { foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['variation_id'] == $product_3) { //remove single product $woocommerce->cart->remove_cart_item($cart_item_key); } } } [/code]
Zuerst möchte ich sagen, dass ich brandneu dazu bin. Bitte verzeihen Sie jede Naivität, die ich möglicherweise habe:
Ich versuche, eine Schaltfläche zu verwenden, um ein WooCommerce-Produkt-SKU (auf...
Zuerst möchte ich sagen, dass ich brandneu dazu bin. Bitte verzeihen Sie jede Naivität, die ich möglicherweise habe:
Ich versuche, eine Schaltfläche zu verwenden, um ein WooCommerce-Produkt-SKU (auf...
Zuerst möchte ich sagen, dass ich brandneu dazu bin. Bitte verzeihen Sie jede Naivität, die ich möglicherweise habe:
Ich versuche, eine Schaltfläche zu verwenden, um ein WooCommerce-Produkt-SKU (auf...