WooCommerce intercept notice's data

42 views Asked by At

In WooCommerce, is there a way to intercept notice's data array, particularly its key, after removing an item from the cart and do so in cart.php without employing a hook?

enter image description here

1

There are 1 answers

0
Greg Bialowas On

I have come up with a crazy solution for this. In my case, and most likely in every case, the string I needed to get a piece from looked like this and the part that interested me was the value of remove_item:

http://site.local/cart/?remove_item=c995axxxxx52bffyyyyy917f67&_wpnonce=1cddf7f858

so what I did:

  1. Copied woocommerce/templates/notices/success.php in to my child theme.
  2. Exploded parts of string based on = - $part1 = explode( '=', $notice['notice'] );
  3. Exploded second chunk of that array based on & - $part2 = explode( '&', $part1[2] );

$part2[0] is the piece of the string I want. Now $GLOBALS['my_string'] did the rest.

It's rather chisel and hammer, but works like a charm.

    $part1    = explode( '=', $notice['notice'] );
    $part2    = explode( '&', $part1[2] );
    $hashed   = $part2[0];

    $membership_cart_id = WC()->cart->generate_cart_id( MEMBERSHIP_PRODUCT_ID );

    $getRemovedID = $membership_cart_id === $hashed ? true : false;
    $GLOBALS['was_membership_removed_just_now'] = $getRemovedID;