I’m not able to access the individual products for an order before the order is deleted.
add_action('before_delete_post', 'removeCheckDetail', 99, 2 );
function removeCheckDetail( $order_id ) {
global $woocommerce;
global $wpdb;
// $order = new WC_Order($order_id);
$order = wc_get_order( $order_id ); // This Works
error_log("Starting " .$order->get_id());
$order_items = $order->get_items();
error_log("Count: " .count($order_items)); // Returns 0
// Loop through order line items
foreach( $order_items as $item_id => $item ) {
error_log("CartItemKey: " .$item->get_name()); // No Loops
}
}