Created
December 6, 2018 12:04
-
-
Save plugin-republic/525acbfc37d91e97091c6823229a1aa3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function prefix_update_existing_cart_item_meta() { | |
$cart = WC()->cart->cart_contents; | |
foreach( $cart as $cart_item_id=>$cart_item ) { | |
$cart_item['new_meta_data'] = 'Your stuff goes here'; | |
WC()->cart->cart_contents[$cart_item_id] = $cart_item; | |
} | |
WC()->cart->set_session(); | |
} |
Thanks @CUBICinfinity i will give this a try and update back here for feedback if any... stay awesome...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, no problem. This is still under development as I work things out. What I'm wanting to do involves manipulating the quantity and I'm storing a side value for quantity that doesn't get altered until I tell it to be altered. I cleaned this up to just what's relevant. There are other functions and line in the snippet not shown here I've been experimenting with.
I've found that if I remove the
write_custom_cart_data
action from the snippet then I lose the previously saved custom data after saving the changes to the snippet. I don't know what happens if I removeWC()->cart->set_session();
. I'm guessing that it won't update the cart and the WC session will act like it hasn't been modified. But I'm still discovering how WooCommerce works. I also am fairly new to the idea of sessions.