bleemboy bleemboy - 8 months ago 42
PHP Question

WC_Order->get_items() not populating `tax_class` field

In Woocommerce,

an order shows an empty field
, but tax classes are defined and assigned correctly to the product.

enter image description here

enter image description here

Here is my code:

array(13) {
string(14) "Nuovo prodotto"
string(9) "line_item"
["item_meta"]=> ...
["item_meta_array"]=> ...
string(1) "1"
string(0) "" <-- this shouldn't be empty
string(2) "54"
string(1) "0"
string(6) "5.8824"
string(6) "5.8824"
string(6) "1.2941"
string(6) "1.2941"
["line_tax_data"]=> ...

What I am doing wrong?


The answer is that is completely normal

Because for a product, when tax class value is set on default the corresponding data stored in the database is 'meta_key' = '_tax_class' => 'meta_value' = ''. So the value is empty.