• 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?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m trying to figure out something similar.

    When do you need this information to be used?

    Do you have some experience programming against WooCommerce hooks and filters? It should be possible to change the “cart_item” contents at the time it goes into the cart in the first place. Maybe I can find that information…

    Otherwise, you’ll have to edit each of the templates that displays the cart_item, and there are a lot of them…

    Thread Starter Friday Next

    (@caseyfriday)

    Basically, I need it to store the dynamically generated SKU for that order, into perpetuity. I want that SKU to be able to be passed to ShipStation, and in order for that to happen, it has to look like it was the product’s SKU all along.

    So it’s not just that I want to display a different SKU – I can do that pretty easily – but I want to set the SKU as the dynamically generated value I create, and keep it like that for each specific order ID I come across.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set SKU Dynamically During Checkout’ is closed to new replies.