Skip to content
Advertisement

Add random string to WooCommerce order items based on product SKU

I have set up variable products within WooCommerce.

Each variation has a unique SKU. My mission is to inspect the SKU within the cart, then according to the SKU, generate a number of random strings (16alphanumeric characters).

  • If item (1) in the cart is SKU ‘ABC’, then (x) number of unique strings are generated and stored for the respective order.

  • If item (2) in the cart is SKU ‘DEF’, then (y) number of unique strings are generated and stored for the respective order.

I have had a look at woocommerce_add_order_item_meta hook but I can’t seem to be able to access the item product data within the function I create associated with this hook?

I am now using

JavaScript

But I am lost trying to get the product SKU from this point. I cannot var_dump() within the function to see the $values etc?

Advertisement

Answer

Explanation / functions used

So you get:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement