Skip to content

Commit 4b726bb

Browse files
authored
Merge pull request #182 from TycheSoftwares/custom_development
Custom work
2 parents 46c6531 + f678058 commit 4b726bb

File tree

6 files changed

+553
-6
lines changed

6 files changed

+553
-6
lines changed

woocommerce-delivery-notes/includes/class-wcdn-print.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ public function __construct() {
169169
'type' => 'default',
170170
'path' => WooCommerce_Delivery_Notes::$plugin_path . 'templates/print-order/',
171171
'url' => WooCommerce_Delivery_Notes::$plugin_url . 'templates/print-order/',
172+
),
173+
array(
174+
'name' => __( 'Custom template', 'woocommerce-delivery-notes' ),
175+
'type' => 'new_template',
176+
'path' => WooCommerce_Delivery_Notes::$plugin_path . 'templates/new-template/',
177+
'url' => WooCommerce_Delivery_Notes::$plugin_url . 'templates/new-template/',
172178
)
173179
);
174180

@@ -315,10 +321,17 @@ public function parse_request( $wp ) {
315321
* Build the template locations
316322
*/
317323
public function build_template_locations() {
318-
$wc_template_directory = WC_TEMPLATE_PATH . 'print-order/';
319-
320324
// Get the paths for custom styles.
321-
$settings_type = get_option( 'wcdn_template_style' );
325+
$settings_type = get_option( 'wcdn_template_style', '' );
326+
if ( 'default' === $settings_type || '' === $settings_type ) {
327+
$wc_template_directory = WC_TEMPLATE_PATH . 'print-order/';
328+
$plugin_path = self::$template_styles[0]['path'];
329+
$plugin_url = self::$template_styles[0]['url'];
330+
} elseif ( 'new_template' === $settings_type ) {
331+
$wc_template_directory = WC_TEMPLATE_PATH . 'new-template/';
332+
$plugin_path = self::$template_styles[1]['path'];
333+
$plugin_url = self::$template_styles[1]['url'];
334+
}
322335
$settings_path = null;
323336
$settings_url = null;
324337
if ( isset( $settings_type ) && 'default' !== $settings_type ) {
@@ -349,11 +362,10 @@ public function build_template_locations() {
349362
),
350363

351364
'plugin' => array(
352-
'path' => self::$template_styles[0]['path'],
353-
'url' => self::$template_styles[0]['url'],
365+
'path' => $plugin_path,
366+
'url' => $plugin_url,
354367
),
355368
);
356-
357369
return $locations;
358370
}
359371

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
<?php
2+
/**
3+
* Print order content. Copy this file to your themes
4+
* directory /woocommerce/print-order to customize it.
5+
*
6+
* @package WooCommerce Print Invoice & Delivery Note/Templates
7+
*/
8+
9+
if ( ! defined( 'ABSPATH' ) ) {
10+
exit;
11+
}
12+
?>
13+
<table class = 'order_info'>
14+
<thead></thead>
15+
<tbody>
16+
<tr>
17+
<td class='order-id' ><?php esc_attr_e( '#', 'woocommerce-delivery-notes' ); ?><?php esc_attr_e( $order->get_id(), 'woocommerce-delivery-notes' ); ?></td>
18+
<td class="order-billing-name"><span><?php esc_attr_e( $order->get_formatted_billing_full_name(), 'woocommerce-delivery-notes' ); ?></span></td>
19+
</tr>
20+
<tr>
21+
<td class="order-time">
22+
<?php
23+
$order_post = get_post( $order->get_id() );
24+
$wdn_order_order_date = $order_post->post_date;
25+
$order_time = strtotime( $wdn_order_order_date );
26+
$order_time = date( 'H:i', $order_time );
27+
?> &nbsp;
28+
<span><?php esc_attr_e( $order_time, 'woocommerce-delivery-notes' ); ?></span>
29+
</td>
30+
<td class='order-phone'>
31+
<span><?php esc_attr_e( 'Phone number', 'woocommerce-delivery-notes' ); ?></span>
32+
<span><?php esc_attr_e( $order->get_billing_phone(), 'woocommerce-delivery-notes' ); ?></span>
33+
</td>
34+
</tr>
35+
</tbody>
36+
</table>
37+
<br>
38+
<hr>
39+
<h2>Item Details</h2>
40+
<div>
41+
<table class="product-table">
42+
<thead>
43+
<tr style="border:1px solid black;" >
44+
<th style = 'min-width: 1em;'></th>
45+
<th style = 'max-width: 2.25em;'><?php esc_attr_e( 'Quantity', 'woocommerce-delivery-notes' ); ?></th>
46+
<th><span><?php esc_attr_e( 'Items', 'woocommerce-delivery-notes' ); ?></span></th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
<?php
51+
52+
if ( count( $order->get_items() ) > 0 ) :
53+
?>
54+
<?php foreach ( $order->get_items() as $item ) : ?>
55+
56+
<?php
57+
58+
$product = apply_filters( 'wcdn_order_item_product', $item->get_product(), $item );
59+
if ( ! $product ) {
60+
continue;
61+
}
62+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
63+
$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
64+
} else {
65+
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
66+
}
67+
?>
68+
<tr style="border:1px solid black;">
69+
<td style = 'max-width: 1px;'><input type ='checkbox'></td>
70+
<td style = 'max-width: 6px;' >
71+
<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
72+
<span> <b>&#215;</b> <span>
73+
</td>
74+
<td class="product-name">
75+
<?php do_action( 'wcdn_order_item_before', $product, $order, $item ); ?>
76+
<span class="name">
77+
<?php
78+
79+
$addon_name = $item->get_meta( '_wc_pao_addon_name', true );
80+
$addon_value = $item->get_meta( '_wc_pao_addon_value', true );
81+
$is_addon = ! empty( $addon_value );
82+
83+
if ( $is_addon ) { // Displaying options of product addon.
84+
$addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';
85+
86+
echo wp_kses_post( $addon_html );
87+
} else {
88+
89+
$product_id = $item['product_id'];
90+
$prod_name = get_post( $product_id );
91+
$product_name = $prod_name->post_title;
92+
93+
echo wp_kses_post( apply_filters( 'wcdn_order_item_name', $product_name, $item ) );
94+
?>
95+
</span>
96+
97+
<?php
98+
99+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
100+
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
101+
$variation = wc_get_product( $item['product_id'] );
102+
foreach ( $item['item_meta'] as $key => $value ) {
103+
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
104+
if ( is_array( $value ) ) {
105+
continue;
106+
}
107+
$term_wp = get_term_by( 'slug', $value, $key );
108+
$attribute_name = wc_attribute_label( $key, $variation );
109+
if ( isset( $term_wp->name ) ) {
110+
echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
111+
} else {
112+
echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
113+
}
114+
}
115+
}
116+
} else {
117+
foreach ( $item['item_meta'] as $key => $value ) {
118+
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
119+
if ( is_array( $value ) ) {
120+
continue;
121+
}
122+
echo '<br>' . wp_kses_post( $key . ':' . $value );
123+
}
124+
}
125+
}
126+
} else {
127+
$item_meta_new = new WC_Order_Item_Meta( $item['item_meta'], $product );
128+
$item_meta_new->display();
129+
130+
}
131+
?>
132+
<br>
133+
<dl class="extras">
134+
<?php if ( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
135+
136+
<dt><?php esc_attr_e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
137+
<dd>
138+
<?php
139+
// translators: files count.
140+
printf( esc_attr_e( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) );
141+
?>
142+
</dd>
143+
144+
<?php endif; ?>
145+
146+
<?php
147+
wcdn_print_extra_fields( $item );
148+
$fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order, $item );
149+
150+
foreach ( $fields as $field ) :
151+
?>
152+
153+
<dt><?php echo esc_html( $field['label'] ); ?></dt>
154+
<dd><?php echo esc_html( $field['value'] ); ?></dd>
155+
156+
<?php endforeach; ?>
157+
</dl>
158+
<?php } ?>
159+
<?php do_action( 'wcdn_order_item_after', $product, $order, $item ); ?>
160+
</td>
161+
</tr>
162+
<?php endforeach; ?>
163+
<?php endif; ?>
164+
</tbody>
165+
</table>
166+
</div>
167+
<?php
168+
if ( class_exists( 'WC_Local_Pickup_Plus_Orders' ) ) {
169+
?>
170+
<div class="pickup-info">
171+
<span><?php esc_attr_e( 'Pickup Information:', 'woocommerce-delivery-notes' ); ?></span>
172+
<span>
173+
<?php
174+
$cdn_local_pickup_object = new WC_Local_Pickup_Plus_Orders();
175+
$local_pickup = wc_local_pickup_plus();
176+
$cdn_local_pickup_locations = $cdn_local_pickup_object->get_order_pickup_data( $order );
177+
$cdn_local_pickup__shipping_object = $local_pickup->get_shipping_method_instance();
178+
foreach ( $cdn_local_pickup_locations as $pickup_meta ) {
179+
foreach ( $pickup_meta as $label => $value ) {
180+
if ( 'Pickup Date' === $label ) {
181+
$timestamp = strtotime( $value );
182+
$day = date( 'l', $timestamp );
183+
$pickup_date = $value;
184+
}
185+
if ( 'Pickup Time' === $label ) {
186+
$pickup_time = $value;
187+
}
188+
}
189+
}
190+
$pickup_time_date = $pickup_date . ',' . $day . ' ' . $pickup_time;
191+
echo esc_attr_e( $pickup_time_date, 'woocommerce-delivery-notes' );
192+
?>
193+
</span>
194+
</div>
195+
<div class ="delivery-info">
196+
<span><?php esc_attr_e( 'Packed By: ______', 'woocommerce-delivery-notes' ); ?></span>
197+
&nbsp;&nbsp;
198+
<span><?php esc_attr_e( 'Delivered By: ______', 'woocommerce-delivery-notes' ); ?></span>
199+
</div>
200+
<?php
201+
}
202+
?>
203+
<br>
204+
<br>
205+
<center>
206+
<div class="order-branding">
207+
<div class="company-logo">
208+
<?php
209+
if ( wcdn_get_company_logo_id() ) :
210+
?>
211+
<?php wcdn_company_logo(); ?><?php endif; ?>
212+
</div>
213+
214+
<div class="company-info">
215+
<?php
216+
if ( ! wcdn_get_company_logo_id() ) :
217+
?>
218+
<h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
219+
<div class="company-address"><?php wcdn_company_info(); ?></div>
220+
</div>
221+
222+
<?php do_action( 'wcdn_after_branding', $order ); ?>
223+
</div>
224+
</center>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Print order footer
4+
*
5+
* @package WooCommerce Print Invoice & Delivery Note/Templates
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
?>
12+
13+
</div><!-- #page -->
14+
15+
<?php
16+
// wcdn_head hook.
17+
do_action( 'wcdn_after_page' );
18+
?>
19+
20+
</div><!-- #container -->
21+
22+
</body>
23+
</html>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Print order header
4+
*
5+
* @package WooCommerce Print Invoice & Delivery Note/Templates
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
?>
12+
13+
<!DOCTYPE html>
14+
<html>
15+
16+
<head>
17+
<meta charset="utf-8">
18+
<title><?php wcdn_document_title(); ?></title>
19+
20+
<?php
21+
// wcdn_head hook.
22+
do_action( 'wcdn_head' );
23+
?>
24+
</head>
25+
26+
<body class="<?php echo esc_attr( wcdn_get_template_type() ); ?>">
27+
28+
<div id="container">
29+
30+
<?php
31+
// wcdn_head hook.
32+
do_action( 'wcdn_before_page' );
33+
?>
34+
35+
<div id="page">
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Print order template. This is the main file. Most
4+
* probably it is easier to edit one of the content by
5+
* copying it to your theme /woocommerce/print
6+
*
7+
* @package WooCommerce Print Invoice & Delivery Note/Templates
8+
*/
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit;
12+
}
13+
?>
14+
15+
<?php
16+
// wcdn_before_template hook.
17+
do_action( 'wcdn_before_template' );
18+
?>
19+
20+
<?php wcdn_get_template_content( 'print-header.php' ); ?>
21+
22+
<?php
23+
// wcdn_before_content hook.
24+
do_action( 'wcdn_before_content' );
25+
?>
26+
27+
<?php
28+
$orders = wcdn_get_orders();
29+
if ( $orders ) :
30+
?>
31+
32+
<?php
33+
// wcdn_before_loop hook.
34+
do_action( 'wcdn_before_loop' );
35+
?>
36+
37+
<?php foreach ( $orders as $order_obj ) : ?>
38+
39+
<article class="content">
40+
41+
<?php do_action( 'wcdn_loop_content', $order_obj, wcdn_get_template_type() ); ?>
42+
43+
</article><!-- .content -->
44+
45+
<?php endforeach; ?>
46+
47+
<?php
48+
// wcdn_after_loop hook.
49+
do_action( 'wcdn_after_loop' );
50+
?>
51+
52+
<?php endif; ?>
53+
54+
<?php
55+
// wcdn_after_content hook.
56+
do_action( 'wcdn_after_content' );
57+
?>
58+
59+
<?php wcdn_get_template_content( 'print-footer.php' ); ?>
60+
61+
<?php
62+
// wcdn_after_template hook.
63+
do_action( 'wcdn_after_template' );
64+
?>

0 commit comments

Comments
 (0)