generated from autonomic-cooperative/wordpress-starter
Run prettier
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
<?php /* Template Name: Coffee Label */
|
||||
<?php
|
||||
/* Template Name: Coffee Label */
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@ -81,70 +82,74 @@
|
||||
</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');
|
||||
<?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);
|
||||
$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;
|
||||
$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 (
|
||||
!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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$is_coffee) && (!$is_subscription)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$brew_method = $item->get_meta('pa_brew-method');
|
||||
$weight = $item->get_meta('weight');
|
||||
if (!$is_coffee && !$is_subscription) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
$brew_method = $item->get_meta("pa_brew-method");
|
||||
$weight = $item->get_meta("weight");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
$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);
|
||||
} ?>
|
||||
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) {
|
||||
$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">
|
||||
@ -153,7 +158,11 @@
|
||||
<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>
|
||||
<p class="code"><?php
|
||||
echo $is_new ? "N" : "";
|
||||
echo $gift_message ? "G" : "";
|
||||
echo $is_organic ? "O" : "";
|
||||
?></p>
|
||||
</div>
|
||||
<div class="order-details">
|
||||
<p class="customer-name"><?php echo "$first_name $last_name"; ?></p>
|
||||
@ -162,10 +171,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php }
|
||||
$j++; // increment counter
|
||||
}
|
||||
}?>
|
||||
<?php
|
||||
}
|
||||
$j++; // increment counter
|
||||
}
|
||||
} ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user