mont58-theme/wp-content/themes/mont58-coffee/template-order-label.php

245 lines
7.7 KiB
PHP
Raw Permalink Normal View History

2024-05-08 20:27:19 +00:00
<?php
/* Template Name: Coffee Label */
2024-06-10 17:46:24 +00:00
if(!is_user_logged_in()){
auth_redirect();
}
2024-05-08 20:15:09 +00:00
?>
<!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">
2024-05-29 16:21:56 +00:00
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@100..900&display=swap" rel="stylesheet">
2024-05-08 20:15:09 +00:00
<link rel="stylesheet" href="style.css">
<style>
2024-06-29 01:00:33 +00:00
@page {
size: 7cm 7cm;
margin: 0;
}
/* acumin-variable-concept */
@font-face {
font-family: Acumin Variable Concept;
font-style: normal;
font-weight: 400;
src: local("Acumin Variable Concept"), local("AcuminVariableConcept"), url(<?php echo get_theme_file_uri('/fonts/acumin-variable-concept.woff2'); ?>) format("woff2");
}
2024-06-29 01:00:33 +00:00
body {
margin: 0;
}
2024-05-08 20:15:09 +00:00
.container {
display: flex;
flex-wrap: wrap;
}
.label {
2024-06-29 01:00:33 +00:00
width: 6.8cm;
height: 6.8cm;
2024-05-08 20:15:09 +00:00
border-radius: 50%;
2024-06-29 01:00:33 +00:00
margin: 0.05cm;
2024-05-08 20:15:09 +00:00
text-align: center;
display: flex;
justify-content: center;
2024-06-27 15:28:27 +00:00
position: relative;
2024-05-08 20:15:09 +00:00
background: linear-gradient(
0deg,
rgba(255, 255, 255, 1) 28%,
rgba(231, 184, 32, 1) 28%
);
2024-06-29 01:00:33 +00:00
/* border: 1px solid black; */
2024-05-08 20:15:09 +00:00
}
.label .product-details {
2024-06-27 14:35:05 +00:00
font-family: 'Acumin Variable Concept', sans-serif;
2024-06-29 01:00:33 +00:00
letter-spacing: 0.23mm;
2024-05-08 20:15:09 +00:00
text-transform: uppercase;
2024-06-29 01:00:33 +00:00
margin-top: 0.6cm;
2024-06-28 15:47:22 +00:00
font-weight: bold;
font-variation-settings: 'wdth' 58, 'wght' 600;
2024-06-29 01:00:33 +00:00
font-size: 4mm;
2024-05-08 20:15:09 +00:00
}
.label .product-details p {
2024-06-29 01:00:33 +00:00
margin-block: 1.5mm;
2024-05-08 20:15:09 +00:00
}
.label .product-details .origin {
font-size: 4mm; /* so that 20 char names fit on one line */
2024-05-08 20:15:09 +00:00
font-weight: 700;
2024-06-29 01:00:33 +00:00
letter-spacing: calc(0.4 * 4px);
margin-block: 3mm;
min-height: 3mm;
2024-06-28 15:47:22 +00:00
font-variation-settings: 'wdth' 70, 'wght' 600;
2024-07-01 15:54:39 +00:00
margin-inline: auto;
2024-05-08 20:15:09 +00:00
}
.label .product-details .origin.non-coffee {
margin-top: 2.3cm;
2024-05-08 20:15:09 +00:00
}
.label .product-details .weight {
text-transform: lowercase;
font-weight: bold;
2024-06-29 01:00:33 +00:00
font-size: 4mm;
2024-05-08 20:15:09 +00:00
}
.label .product-details .code {
min-height: 6mm;
2024-06-29 01:00:33 +00:00
letter-spacing: calc(0.4 * 10px);
margin-top: 2mm;
font-size: 4mm;
2024-05-08 20:15:09 +00:00
}
.label .order-details {
2024-06-27 15:28:27 +00:00
text-align: center;
2024-06-29 01:00:33 +00:00
width: 100%;
2024-06-28 15:26:30 +00:00
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 2.9mm; /* so that names as long as 50 characters stay on one line */
margin-top: 4.6mm; /* to center text inside white area */
position: absolute;
bottom: 5.9mm; /* Adjust this value to set the distance from the bottom of the label */
left: 0;
right: 0;
2024-07-10 23:48:04 +00:00
}
2024-05-08 20:15:09 +00:00
.label .order-details p {
2024-06-29 01:00:33 +00:00
margin-block: 0.5mm;
2024-05-08 20:15:09 +00:00
}
</style>
</head>
<body>
<div class="container">
2024-06-10 17:46:24 +00:00
<?php
foreach ($_GET["order_ids"] as $order_id) {
2024-05-08 20:27:19 +00:00
$order = wc_get_order($order_id);
// Check if shipping details exist
$shipping_first_name = $order->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;
}
2024-05-08 20:27:19 +00:00
$items = $order->get_items();
$total_items = $order->get_item_count();
2024-05-08 20:27:19 +00:00
$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);
2024-07-04 19:58:29 +00:00
$is_new = false;
2024-05-08 20:27:19 +00:00
foreach ($items as $item) {
2024-07-16 22:23:05 +00:00
$j = 0;
2024-05-08 20:27:19 +00:00
// 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;
2024-07-10 23:48:04 +00:00
$is_organic = false;
2024-05-08 20:27:19 +00:00
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;
}
}
2024-05-08 20:15:09 +00:00
}
2024-07-16 22:23:05 +00:00
$product_name = '';
$roast = '';
2024-05-08 20:15:09 +00:00
if ($is_coffee || $is_subscription) {
$brew_method = $item->get_meta("pa_brew-method");
$weight = $item->get_meta("weight");
} else {
$product_name = $item->get_name();
2024-05-08 20:27:19 +00:00
}
2024-05-08 20:15:09 +00:00
2024-05-08 20:27:19 +00:00
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;
}
}
2024-05-08 20:15:09 +00:00
2024-05-08 20:27:19 +00:00
$quantity = $item->get_quantity();
for ($i = 0; $i < $quantity; $i++) {
if ($is_subscription) {
2024-07-16 22:23:05 +00:00
if (($order_subscription_coffees !== null)
&& (is_object($order_subscription_coffees[$i + $j]["coffee"]))){
2024-07-09 18:20:39 +00:00
$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);
}
} ?>
2024-05-08 20:15:09 +00:00
<div class="label">
<div>
<div class="product-details">
<?php if ($is_coffee || $is_subscription) { ?>
2024-05-08 20:15:09 +00:00
<p class="weight"><?php echo $weight; ?></p>
<?php } ?>
<p class="origin<?php echo ($is_coffee || $is_subscription) ? "" : " non-coffee"; ?>"><?php echo $product_name; ?></p>
<?php if ($is_coffee || $is_subscription) { ?>
2024-05-08 20:15:09 +00:00
<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>
<?php } ?>
2024-05-08 20:27:19 +00:00
<p class="code"><?php
echo $is_new ? "N" : "";
echo $gift_message ? "G" : "";
echo $is_organic ? "O" : "";
?></p>
2024-05-08 20:15:09 +00:00
</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 $total_items; ?></p>
2024-05-08 20:15:09 +00:00
</div>
</div>
</div>
2024-05-08 20:27:19 +00:00
<?php
}
$j++; // increment counter
}
} ?>
2024-05-08 20:15:09 +00:00
</div>
</body>
</html>