Remove item with $product_id - Woocommerce

前端 未结 2 960
礼貌的吻别
礼貌的吻别 2020-12-16 12:28

Made a function where the customer get a product added to the cart when they reach a specific amount.

Example of when customer reaches level 3 and get the

相关标签:
2条回答
  • 2020-12-16 12:54

    I think you're using remove_cart_item incorrectly. If you go through the documentation, you will find that it accepts cart_item_key as parameter (as wisdmLabs mentioned in comment).

    You are using it like so:

    WC()->cart->remove_cart_item($product_3);
    

    Try this instead:

    WC()->cart->remove_cart_item($cart_item_key);
    

    After updating that line, I think you will able to remove product.

    0 讨论(0)
  • 2020-12-16 13:11

    Use this for latest versions of WooCommerce:

    $cartId = WC()->cart->generate_cart_id( 'PRODUCT ID' );
    $cartItemKey = WC()->cart->find_product_in_cart( $cartId );
    WC()->cart->remove_cart_item( $cartItemKey );
    

    replace PRODUCT ID with yours.

    0 讨论(0)
提交回复
热议问题