Jquery-Trigger zum Entfernen des Produkts aus dem WooCommerce-Warenkorb Ajax

Lesezeit: 1 Minute

Ich möchte eine jQuery ausführen, wenn ein Produkt in WooCommerce aus dem Warenkorb entfernt wird. Ich dachte, das würde es tun, aber es passiert nicht.

Irgendwelche Ideen?

jQuery( document.body ).on( 'updated_wc_div', function(){
//magic
});

  • Mögliches Duplikat von Run jQuery after WooCommerce AJAX cart update

    – Dhaval Shah

    2. Januar 2018 um 7:20 Uhr

Benutzeravatar von Avag Sargsyan
Avag Sargsjan

Es kann auch ausgelöst werden updated_cart_totals Ereignis, wenn der Warenkorb aktualisiert wurde. Sie können also die folgende Problemumgehung verwenden, da es kein globales Ereignis gibt, das ausgelöst wird, wenn der Einkaufswagen aktualisiert wird:

jQuery( document.body ).on( 'updated_wc_div', do_magic );
jQuery( document.body ).on( 'updated_cart_totals', do_magic );

function do_magic() {
    // do magic
}

Mit diesem Code können Sie das Produkt aus dem Warenkorb entfernen:

main.js

 $.ajax({
    type: "POST",
    url: 'http://localhost/your_site/wp-admin/admin-ajax.php',
    data: {action : 'remove_item_from_cart','product_id' : '4'},
    success: function (res) {
        if (res) {
            alert('Removed Successfully');
        }
    }
});

Funktionen.php

function remove_item_from_cart() {
$cart = WC()->instance()->cart;
$id = $_POST['product_id'];
$cart_id = $cart->generate_cart_id($id);
$cart_item_id = $cart->find_product_in_cart($cart_id);

if($cart_item_id){
   $cart->set_quantity($cart_item_id, 0);
   return true;
} 
return false;
}

add_action('wp_ajax_remove_item_from_cart', 'remove_item_from_cart');
add_action('wp_ajax_nopriv_remove_item_from_cart', 'remove_item_from_cart');

  • Frage ist zu Abzug jQuery-Aktion wann jedes Element wird entfernt aus Warenkorb nicht wie man einen Artikel aus dem Warenkorb entfernt.

    – Dhaval Shah

    2. Januar 2018 um 7:16 Uhr


Benutzeravatar von Gopika
Gopika

Geben Sie diesen Codesatz in Ihre js-Datei ein

jQuery(document.body)
  .on(
    'removed_from_cart updated_cart_totals',
    function() {
      // your code...
    }
  );

1437770cookie-checkJquery-Trigger zum Entfernen des Produkts aus dem WooCommerce-Warenkorb Ajax

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy