Set SKU Dynamically During Checkout
-
I’m working on a store that with all of the possible combinations of products, it has over 16,000 possible variations. Rather than create a variation for every possible product outcome, I want to systematically create an SKU during checkout that will only hold for that order session.
The SKU will be generated based on the attributes of the product, so it will always be the same when the same attributes are selected. I can take care of that part.
But how do I actually apply the SKU to the product in that cart session and get it to stick for that order? I’ve tried doing:
global $woocommerce; if( $cart_contents = $woocommerce->cart->get_cart() ) { foreach( $cart_contents as $cart_item_key => $cart_item ) { echo $cart_item_key; //getting the cart key $cart_item['data']->sku = 'SMTHGNEW'; echo $cart_item['data']->sku; } }
And although when I echo $cart_item[‘data’]->sku, it does change the SKU from what it normally is to ‘SMTHGNEW’, that doesn’t stick throughout the order. How can I set it so that for that cart_item_key, or cart ‘session’ or something, the SKU I generate is saved as that product’s SKU?
- The topic ‘Set SKU Dynamically During Checkout’ is closed to new replies.