如何从“ woocommerce_cart_item_removed”找到产品ID钩? [英] How to find out product id from "woocommerce_cart_item_removed" hook?

查看:63
本文介绍了如何从“ woocommerce_cart_item_removed”找到产品ID钩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码

add_action( 'woocommerce_cart_item_removed', 'after_remove_product_from_cart' );
function after_remove_product_from_cart($removed_cart_item_key, $instance) {
    $product_id = $removed_cart_item_key['product_id'];
}

我想找到一种获取产品ID或实际产品对象本身的方法使用$ removed_cart_item_key。你怎么做呢?我找不到任何引用,谢谢。

I want to find out a way to get product id or actual product object itself using $removed_cart_item_key. How do you do it? I cannot find any references, thanks.

推荐答案

应该是这样的……

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' ];
}

这篇关于如何从“ woocommerce_cart_item_removed”找到产品ID钩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆