initial commit

This commit is contained in:
Aadil Ayub 2024-05-02 08:02:12 +00:00
commit ffb77dc3c4
3 changed files with 163 additions and 0 deletions

42
mont58-coffee-label.php Normal file
View File

@ -0,0 +1,42 @@
<?php
/**
* Plugin Name: Mont58 Coffee Label
* Plugin URI: https://example.com/
* Description: A plugin for displaying coffee labels.
* Version: 1.0.0
* Author: Autonomic Co-op
* Author URI: https://autonomic.zone/
* License: GPL2
*/
// Add a sidepanel on WooCommerce order pages
add_action('add_meta_boxes', 'mont58_coffee_label_add_sidepanel');
function mont58_coffee_label_add_sidepanel() {
add_meta_box(
'mont58_coffee_label_sidepanel',
'Order Label',
'mont58_coffee_label_render_sidepanel',
'shop_order',
'side',
'high'
);
}
function mont58_coffee_label_render_sidepanel($post) {
// Render the content of the sidepanel here
$order_id = $post->ID;
echo '<a href="/coffee-label?order_id=' . $order_id . '" class="button button-primary">View Label</a>';
}
// Load custom template
function load_custom_template($template) {
if (is_page('coffee-label')) {
return plugin_dir_path(__FILE__) . 'template-order-label.php';
}
return $template;
}
add_filter('template_include', 'load_custom_template');

120
template-order-label.php Normal file
View File

@ -0,0 +1,120 @@
<?php /* Template Name: Coffee Label */
$order_id = sanitize_text_field($_GET['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();
?>
<!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;
}
.label {
width: 400px;
height: 400px;
border-radius: 50%;
padding: 2rem;
margin-inline: 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;
}
.label .product-details .weight {
text-transform: lowercase;
font-weight: bold;
font-family: sans-serif;
font-weight: 18px;
}
.label .product-details .code {
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 ($items as $item) {
$quantity = $item->get_quantity();
$product_name = $item->get_name();
$brew_method = $item->get_meta('pa_brew-method');
$weight = $item->get_meta('weight');
$product_id = $item->get_product_id();
$roast = get_field('roast_level', $product_id);
for ($i = 0; $i < $quantity; $i++) { ?>
<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>31/03/2024</span></p>
<p class="code">NGO</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 }
} ?>
</div>
</body>
</html>

1
todo.txt Normal file
View File

@ -0,0 +1 @@
- Use query param to get order id : '/wp-content/plugins/awesomeplugin/label.php?order_id=1234'