In the woocommerce cart, when the user presses the REMOVE ITEM button on the cart I am trying to retrieve some post meta from an item in the cart. Something like:
$removed_stock = get_post_meta( $product_id, 'more_info_data', 'x' );
To do that I am adding an action:
function ss_cart_updated( $item_id ) {
print "<pre>";
print_r (WC()->cart->get_cart());
print "</pre>";
exit;
};
// add the action
add_action( 'woocommerce_cart_item_removed', 'ss_cart_updated' );
Unfortunately this only list all the products in the cart that have been not removed. The item that has not been removed it is not listed anymore.
I tried "woocommerce_get_remove_url" and "woocommerce_cart_item_remove_link" they dont seem to do anything for me.
Thanks so much!
I think you need to use the woocommerce_remove_cart_item
which runs just before the item is actual unset from the cart contents array. woocommerce_cart_item_removed
happens after the item is removed, so as you have found out there's no way to get any information about the product. Untested, but try this:
function ss_cart_updated( $cart_item_key, $cart ) {
print "<pre>";
$product_id = $cart->cart_contents[ $cart_item_key ]['product_id'];
print_r(get_post_meta( $product_id, 'more_info_data', true ));
print "</pre>";
exit;
};
add_action( 'woocommerce_remove_cart_item', 'ss_cart_updated', 10, 2 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With