Hey everyone! The Maje Media team is currently working on updates for this code and will release something as soon as possible. Thank you for your interest in our work.

 

Request

This question came from Stack Overflow asking, for warranty purposes, how to save a product’s SKU to the order item meta for future discovery.

The problem is that when a product still exists in an installation the SKU is available for reporting, etc. But once that product is deleted the SKU reference is now gone. Saving it to the order item meta is a good idea.

Required Plugins

Code

Result

Image: WooCommerce shopping cart showing code example of order item meta added to cart line item

Image: Display of the database structure with querying for the order item meta after the code example is applied.

Going Further

The above will work only in cases where a product has been added to the cart that doesn’t have any variations. The following will not only save the parent SKU but also the variation SKU to the item meta.

Result

Image: Database query results for above code example using a variation

Image: WooCommerce cart view adding SKU to Order Item Meta based on above example

Disclaimer

Maje Media LLC cannot be held responsible for the functionality of this code. Please make sure you test it on a development site before adding the code to your production website. There is no support available for this (and other) code snippet(s) posted on this website. If you’d like Maje Media to do custom development to help with your custom implementation please send a contact request.

This Post Has 3 Comments
  1. As of 3.0.1, the woocommerce_add_order_item_meta hook has been deprecated and the new hook is woocommerce_new_order_item($item_id, $item, $order_id)

  2. Hi there,

    Any chance you could update this with the new hook 🙂

    I am using https://automatewoo.com/ to push Order Meta to a contact in Active Campaign.

    I’d like to get the SKU of all items in the order, and add them to a custom meta field with all the SKUs separated with commas.

    When https://automatewoo.com/ pushes this field of sku’s separated by commas, it breaks each comma value into it’s own tag for the contact.

Leave a Reply

Your email address will not be published. Required fields are marked *