From 0d8bac003bf71b755352271d11443e4c5bc0acd0 Mon Sep 17 00:00:00 2001 From: Aadil Ayub Date: Thu, 2 May 2024 08:32:41 +0000 Subject: [PATCH] only render labels for coffees --- template-order-label.php | 60 +++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/template-order-label.php b/template-order-label.php index 7733d44..5da30db 100644 --- a/template-order-label.php +++ b/template-order-label.php @@ -8,6 +8,7 @@ $postcode = $order->get_billing_postcode(); $items = $order->get_items(); $order_date = $order->get_date_created()->date('d/m/Y'); + ?> @@ -89,32 +90,47 @@ $order_date = $order->get_date_created()->date('d/m/Y');
get_quantity(); - $product_name = $item->get_name(); - $brew_method = $item->get_meta('pa_brew-method'); - $weight = $item->get_meta('weight'); + // checking if product is a coffee $product_id = $item->get_product_id(); - $roast = get_field('roast_level', $product_id); + $product_categories = get_the_terms($product_id, 'product_cat'); + $is_coffee = 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; + } + } + } - for ($i = 0; $i < $quantity; $i++) { ?> -
-
-
-

-

-

-

Roast

-

Roasted on:

-

NGO

-
-
-

-

-

+ if ($is_coffee) { + $quantity = $item->get_quantity(); + $product_name = $item->get_name(); + $brew_method = $item->get_meta('pa_brew-method'); + $weight = $item->get_meta('weight'); + $roast = get_field('roast_level', $product_id); + + for ($i = 0; $i < $quantity; $i++) { ?> +
+
+
+

+

+

+

Roast

+

Roasted on:

+

NGO

+
+
+

+

+

+
-
-