This should work. That is the correct usage (assuming that $item[‘product_id’] is a valid product id). What specifically is happening?
Well nothing. If I turn on debugging, I only get this:
Notice: The “woocommerce_get_product_attributes” hook uses out of date data structures and is deprecated since version 3.0.0! Use woocommerce_product_get_attributes instead. in /home/homejungles/public_html/wp-includes/functions.php on line 3829
This is my code (short version) if you want to take a look:
https://pastebin.com/0rT66WXZ
UPDATE: It does work with non-variable products, but not with the variations…
See if $item[‘product_id’] is set. Item is an object so it has getters too usually.
Solved, it was some kind of error with quantity getting, it affected rest of the code (it wasn’t in the example).
So, if you are interested to know what it is:
This won’t work (but it worked before):
$product_info = $item['item_meta'];
$quantity = $product_info['_qty'][0];
And this works instead:
$quantity = $item['qty'];
-
This reply was modified 7 years, 8 months ago by Nikola Tomic.
What about $item->get_quantity();
Yep, that could also work