I need to determine if the order is an order that needs shipping of physical goods.
So I can check if the order has physical goods in it or if the order has only digital/virtual products.
How can I do this in the best way?
I get all the items of the order with:
$order = new WC_Order($order_id);
$items = $order->get_items();
You could do something like this. You need to loop through the order items, and get the product ids to use the method WC_Product::is_virtual();
$order = new WC_Order($order_id);
foreach ($order->get_items() as $order_item){
$item = wc_get_product($order_item->get_product_id());
if (!$item->is_virtual()) {
// this order contains a physical product do what you want here or return false
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With