How to find out product id from “woocommerce_cart_item_removed” hook?

天大地大妈咪最大 提交于 2019-12-07 00:47:26

should be something like this...

add_action( 'woocommerce_cart_item_removed', 'after_remove_product_from_cart', 10, 2 );
function after_remove_product_from_cart($removed_cart_item_key, $cart) {
    $line_item = $cart->removed_cart_contents[ $removed_cart_item_key ];
    $product_id = $line_item[ 'product_id' ];
}
LoicTheAztec

Because it happen before the cart item is removed, you need to use woocommerce_remove_cart_item instead of woocommerce_cart_item_removed, to retrieve this product item.

add_action( 'woocommerce_remove_cart_item', 'after_remove_product_from_cart', 10, 2 );
function after_remove_product_from_cart($removed_cart_item_key, $cart) {
    $product_id = $cart->cart_contents[ $removed_cart_item_key ]['product_id'];
}

See this source from helgatheviking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!