Remove product in the cart using ajax in woocommerce

后端 未结 3 909

I would like to remove the product in the woocommerce cart using ajax without click the link.

If you have encounter this kind of functionality, please help us.

相关标签:
3条回答
  • 2020-12-29 09:53

    Try this one :

    foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $cart_item ) {
    
     if($cart_item['product_id'] == $product_id){
    
      unset($cartdetails->cart_contents[$cart_item_key]);
    
     }
    }
    
    0 讨论(0)
  • 2020-12-29 09:59

    you could use the WC_Cart set_quantity method

    And do as this in your php:

    $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);
    }
    
    0 讨论(0)
  • 2020-12-29 10:05

    use this :

    $cart = $woocommerce->cart;
    
    foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item){
        if($cart_item['product_id'] == $_POST['product_id'] ){
            // Remove product in the cart using  cart_item_key.
            $cart->remove_cart_item($cart_item_key);
        }
    }
    
    0 讨论(0)
提交回复
热议问题