get_shipping_first_name(); $shipping_last_name = $order->get_shipping_last_name(); $shipping_postcode = $order->get_shipping_postcode(); // If any shipping detail is empty, use billing details if (empty($shipping_first_name) || empty($shipping_last_name) || empty($shipping_postcode)) { $first_name = $order->get_billing_first_name(); $last_name = $order->get_billing_last_name(); $postcode = $order->get_billing_postcode(); } else { $first_name = $shipping_first_name; $last_name = $shipping_last_name; $postcode = $shipping_postcode; } $items = $order->get_items(); $total_items = $order->get_item_count(); $roast_date = (new DateTime())->modify("-3 days")->format("d/m/Y"); $gift_message = $order->get_meta("_shipping_gift_message"); $order_subscription_coffees = get_field("coffees", $order_id); $is_new = false; foreach ($items as $item) { $j = 0; // checking if product is a coffee $product_id = $item->get_product_id(); $product_categories = get_the_terms($product_id, "product_cat"); $is_coffee = false; $is_subscription = false; $is_organic = false; if ( !empty($product_categories) && !is_wp_error($product_categories) ) { foreach ($product_categories as $product_category) { if ($product_category->slug == "coffee") { $is_coffee = true; break; } elseif ($product_category->slug == "tasting") { $is_subscription = true; break; } } } $product_name = ''; $roast = ''; if ($is_coffee || $is_subscription) { $brew_method = $item->get_meta("pa_brew-method"); $weight = $item->get_meta("weight"); } else { $product_name = $item->get_name(); } if ($is_coffee) { // Non-subscription order $product_name = $item->get_name(); $roast = get_field("roast_level", $product_id); $is_organic = get_field("is_organic", $product_id); } if ($is_subscription) { $subscriptions = wcs_get_subscriptions_for_order($order_id, [ "order_type" => "any", ]); // TODO log / admin warning if there are >1 subscriptions $subscription = array_pop($subscriptions); $orders = $subscription->get_related_orders("ids", "any"); if (sizeof($orders) == 1) { $is_new = true; } } $quantity = $item->get_quantity(); for ($i = 0; $i < $quantity; $i++) { if ($is_subscription) { if (($order_subscription_coffees !== null) && (is_object($order_subscription_coffees[$i + $j]["coffee"]))){ $coffee = $order_subscription_coffees[$i + $j]["coffee"]; $product_name = $coffee->post_title; $roast = get_field("roast_level", $coffee->ID); $is_organic = get_field("is_organic", $coffee->ID); } } ?>

">

Roast

Roasted on: