Writing a function for WooCommerce that produce a XML with information. Having problem receiving my SKU number from different item
My code to read data is something like this
// Query order data
$order = new WC_Order( $order_id );
$items = $order->get_items();
$counter = 1000;
// Retrive Loop data
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_qty = $item['qty'];
$product_variation_id = $item['variation_id'];
// Output Loop data
$this->xml->writeElement('Description', $product_name); // etc..
The problem is when it comes to receiving the SKU number on every item. Have been trying several way to do this without success, My latest was
$sku = $product->get_sku();
Whitin the Loop but it just throw me
Call to a member function get_sku() on a non-object
Anyone one that have a clue how to manage to receive and write out SKU within the loop on my custom XML plugin ?
how did you declare
$product
??try
$product = new WC_Product($item['product_id']);
before you do
$sku = $product->get_sku();
this will make
get_sku()
available…