I want to add a new WooCommerce notice when a user removes an item from their cart. I'm using the woocommerce_remove_cart_item hook. However, I can't access the $cart_item array using var_dump
. I have tried to echo a variable $prod_id = $cart_item ['data']->get_id();
but echo doesn't display anything either?
If I add a WooCommerce notice then the variable ($prod_id) does display in the notice correctly.
$remove_notice = __( 'ID - ' . $prod_id );
wc_add_notice( $remove_notice, 'success' );
But I just can't seem to echo, var_dump, or print_r anything on the page using the woocommerce_remove_cart_item
hook. I want to make the custom display message conditional but can't see inside the $cart_item array to see what's going on. Here's my code.
function verify_cart( $cart_item_key, $cart ) {
$cart_item = $cart->get_cart_item( $cart_item_key );
$product = wc_get_product( $cart_item['data'] );
$prod_id = $cart_item ['data']->get_id();
// $remove_notice = __( 'ID - ' . $prod_id );
// wc_add_notice( $remove_notice, 'success' );
var_dump( $cart_item );
}
add_action( 'woocommerce_remove_cart_item', 'verify_cart', 10, 2 );