172 lines
5.1 KiB
PHP
172 lines
5.1 KiB
PHP
|
<?php /* Template Name: Coffee Label */
|
||
|
?>
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Coffee Label</title>
|
||
|
<link rel="preconnect" href="https://api/fonts.coollabs.io">
|
||
|
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@100..900&display=swap" rel="stylesheet">
|
||
|
<link rel="stylesheet" href="style.css">
|
||
|
<style>
|
||
|
.container {
|
||
|
display: flex;
|
||
|
flex-wrap: wrap;
|
||
|
}
|
||
|
|
||
|
.label {
|
||
|
width: 400px;
|
||
|
height: 400px;
|
||
|
border-radius: 50%;
|
||
|
padding: 2rem;
|
||
|
margin: 2rem;
|
||
|
text-align: center;
|
||
|
border: 1px solid gray;
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
justify-content: center;
|
||
|
background: linear-gradient(
|
||
|
0deg,
|
||
|
rgba(255, 255, 255, 1) 28%,
|
||
|
rgba(231, 184, 32, 1) 28%
|
||
|
);
|
||
|
}
|
||
|
|
||
|
.label .product-details {
|
||
|
font-family: 'Roboto Condensed';
|
||
|
font-size: 21px;
|
||
|
letter-spacing: 2px;
|
||
|
text-transform: uppercase;
|
||
|
margin-top: 2.5em;
|
||
|
margin-bottom: 2em;
|
||
|
font-weight: 500;
|
||
|
}
|
||
|
|
||
|
.label .product-details p {
|
||
|
margin-block: 0.5em;
|
||
|
}
|
||
|
|
||
|
.label .product-details .origin {
|
||
|
font-size: 28px;
|
||
|
font-weight: 700;
|
||
|
letter-spacing: 4px;
|
||
|
margin-block: 1.2em 0.8em;
|
||
|
min-height: 33px;
|
||
|
}
|
||
|
|
||
|
.label .product-details .weight {
|
||
|
text-transform: lowercase;
|
||
|
font-weight: bold;
|
||
|
font-family: sans-serif;
|
||
|
font-weight: 18px;
|
||
|
}
|
||
|
|
||
|
.label .product-details .code {
|
||
|
min-height: 20px;
|
||
|
letter-spacing: 10px;
|
||
|
margin-top: 1.5em;
|
||
|
font-size: 16px;
|
||
|
}
|
||
|
|
||
|
.label .order-details {
|
||
|
padding-bottom: 1em;
|
||
|
font-weight: 17px;
|
||
|
}
|
||
|
|
||
|
.label .order-details p {
|
||
|
margin-block: 0.4em;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="container">
|
||
|
<?php
|
||
|
foreach ($_GET['order_ids'] as $order_id) {
|
||
|
$order = wc_get_order($order_id);
|
||
|
$first_name = $order->get_billing_first_name();
|
||
|
$last_name = $order->get_billing_last_name();
|
||
|
$postcode = $order->get_billing_postcode();
|
||
|
$items = $order->get_items();
|
||
|
$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);
|
||
|
|
||
|
$j = 0; // Count order items
|
||
|
foreach ($items as $item) {
|
||
|
// 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;
|
||
|
|
||
|
if (!empty($product_categories) && !is_wp_error($product_categories)) {
|
||
|
foreach ($product_categories as $product_category) {
|
||
|
if ($product_category->slug == 'coffee') {
|
||
|
$is_coffee = true;
|
||
|
break;
|
||
|
} else if ($product_category->slug == 'tasting') {
|
||
|
$is_subscription = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ((!$is_coffee) && (!$is_subscription)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$brew_method = $item->get_meta('pa_brew-method');
|
||
|
$weight = $item->get_meta('weight');
|
||
|
|
||
|
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, array( '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) {
|
||
|
$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);
|
||
|
} ?>
|
||
|
<div class="label">
|
||
|
<div>
|
||
|
<div class="product-details">
|
||
|
<p class="weight"><?php echo $weight; ?></p>
|
||
|
<p class="origin"><?php echo $product_name; ?></p>
|
||
|
<p class="bean-type"><?php echo $brew_method; ?></p>
|
||
|
<p class="roast"><?php echo $roast; ?> Roast</p>
|
||
|
<p class="date">Roasted on: <span><?php echo $roast_date; ?></span></p>
|
||
|
<p class="code"><?php echo $is_new ? 'N' : '' ?><?php echo $gift_message ? 'G' : '' ?><?php echo $is_organic ? 'O' : '' ?></p>
|
||
|
</div>
|
||
|
<div class="order-details">
|
||
|
<p class="customer-name"><?php echo "$first_name $last_name"; ?></p>
|
||
|
<p class="purchase-code"><?php echo $postcode; ?></p>
|
||
|
<p class="quantity"><?php echo $quantity; ?></p>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<?php }
|
||
|
$j++; // increment counter
|
||
|
}
|
||
|
}?>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|