Skip to content

Commit 074316d

Browse files
committed
Patch updates before v1.0.0 major release
1 parent b172d25 commit 074316d

4 files changed

+171
-72
lines changed

README.md

+8-41
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
=== Plugin Name ===
22
Contributors: (this should be a list of wordpress.org userid's)
33
Donate link: https://kgopalkrishna.com
4-
Tags: comments, spam
5-
Requires at least: 3.0.1
6-
Tested up to: 3.4
7-
Stable tag: 4.3
8-
License: GPLv2 or later
9-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
4+
Tags: woocommerce, order, view
5+
Requires at least: 5.0.0
6+
Tested up to: 5.2.3
7+
Stable tag: 1.0
8+
License: GPLv3 or later
9+
License URI: http://www.gnu.org/licenses/gpl-3.0.html
1010

11-
Here is a short description of the plugin. This should be no more than 150 characters. No markup here.
11+
This plugin gives a strict View-Only access to Woocommerce orders for specified user roles.
1212

1313
== Description ==
1414

@@ -39,23 +39,8 @@ you put the stable version, in order to eliminate any doubt.
3939

4040
== Installation ==
4141

42-
This section describes how to install the plugin and get it working.
43-
44-
e.g.
45-
4642
1. Upload `wc-order-view.php` to the `/wp-content/plugins/` directory
4743
1. Activate the plugin through the 'Plugins' menu in WordPress
48-
1. Place `<?php do_action('plugin_name_hook'); ?>` in your templates
49-
50-
== Frequently Asked Questions ==
51-
52-
= A question that someone might have =
53-
54-
An answer to that question.
55-
56-
= What about foo bar? =
57-
58-
Answer to foo bar dilemma.
5944

6045
== Screenshots ==
6146

@@ -68,25 +53,7 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove
6853
== Changelog ==
6954

7055
= 1.0 =
71-
* A change since the previous version.
72-
* Another change.
73-
74-
= 0.5 =
75-
* List versions from most recent at top to oldest at bottom.
76-
77-
== Upgrade Notice ==
78-
79-
= 1.0 =
80-
Upgrade notices describe the reason a user should upgrade. No more than 300 characters.
81-
82-
= 0.5 =
83-
This version fixes a security related bug. Upgrade immediately.
84-
85-
== Arbitrary section ==
86-
87-
You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
88-
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
89-
"installation." Arbitrary sections will be shown below the built-in sections outlined above.
56+
* Initial release.
9057

9158
== A brief Markdown Example ==
9259

admin/class-wc-order-view-admin-list-table.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ function column_cb( $item ) {
311311
function column_order_id( $item ) {
312312

313313
$order_id = "";
314-
$order_id .= '<a href="#" class="order-preview" data-order-id="' . $item[ 'order_id' ] . '" title="Preview">Preview</a>';
315-
$order_id .= '<a href="#" class="order-view"><strong>#' . $item[ 'order_id' ] .' '. $item[ 'name' ] . '</strong></a>';
314+
$order_id .= '<a href="admin.php?page=wc-order-view&action=view&order_id=' . $item[ 'order_id' ] . '" class="order-preview" data-order-id="' . $item[ 'order_id' ] . '" title="Preview">Preview</a>';
315+
$order_id .= '<a href="admin.php?page=wc-order-view&action=view&order_id=' . $item[ 'order_id' ] . '" class="order-view"><strong>#' . $item[ 'order_id' ] .' '. $item[ 'name' ] . '</strong></a>';
316316

317317
return $order_id;
318318

admin/class-wc-order-view-admin.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function wc_order_view_menus() {
132132

133133
$hook = add_menu_page( 'WC Orders', 'WC Orders', 'products_admin', 'wc-order-view', array ( $this, 'wc_order_view_page') , 'dashicons-list-view', 55 );
134134
$hook = add_submenu_page('wc-order-view', 'All Orders', 'All Orders', 'products_admin', 'wc-order-view', array( $this , 'wc_order_view_page' ));
135-
add_submenu_page('wc-order-view', 'Order View - Settings', 'Settings', 'products_admin', 'wc-order-view-settings', array( $this , 'wc_order_view_settings_page' ));
135+
add_submenu_page('wc-order-view', 'Order View - Settings', 'Settings', 'administrator', 'wc-order-view-settings', array( $this , 'wc_order_view_settings_page' ));
136136

137137
add_action( "load-$hook", array( $this, 'screen_option' ) );
138138

@@ -169,6 +169,8 @@ public function wc_order_view_page() {
169169

170170
if( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == "view" ) {
171171

172+
$post = new WP_Post( $_GET[ 'order_id' ] );
173+
172174
$order = new WC_Order( $_GET[ 'order_id' ] );
173175

174176
$user = $order->get_user();

admin/partials/wc-order-view-order-details-display.php

+158-28
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,101 @@
1515
/**
1616
* Objects available in this context.
1717
*
18+
* @var WP_Post $post The wordpress post object of the woocommerce order in this context .
1819
* @var WC_Order $order The woocommerce order object initialized with the current order id.
1920
* @var WP_User $user The wordpress user object initialized with the user associated with the current order.
2021
*/
2122

2223
defined( 'ABSPATH' ) || exit;
2324

25+
$billing_fields = apply_filters(
26+
'woocommerce_admin_billing_fields', array(
27+
'first_name' => array(
28+
'label' => __( 'First name', 'woocommerce' ),
29+
'show' => false,
30+
),
31+
'last_name' => array(
32+
'label' => __( 'Last name', 'woocommerce' ),
33+
'show' => false,
34+
),
35+
'company' => array(
36+
'label' => __( 'Company', 'woocommerce' ),
37+
'show' => false,
38+
),
39+
'address_1' => array(
40+
'label' => __( 'Address line 1', 'woocommerce' ),
41+
'show' => false,
42+
),
43+
'address_2' => array(
44+
'label' => __( 'Address line 2', 'woocommerce' ),
45+
'show' => false,
46+
),
47+
'city' => array(
48+
'label' => __( 'City', 'woocommerce' ),
49+
'show' => false,
50+
),
51+
'postcode' => array(
52+
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
53+
'show' => false,
54+
),
55+
'country' => array(
56+
'label' => __( 'Country', 'woocommerce' ),
57+
'show' => false,
58+
),
59+
'state' => array(
60+
'label' => __( 'State / County', 'woocommerce' ),
61+
'show' => false,
62+
),
63+
'email' => array(
64+
'label' => __( 'Email address', 'woocommerce' ),
65+
),
66+
'phone' => array(
67+
'label' => __( 'Phone', 'woocommerce' ),
68+
),
69+
)
70+
);
71+
72+
$shipping_fields = apply_filters(
73+
'woocommerce_admin_shipping_fields', array(
74+
'first_name' => array(
75+
'label' => __( 'First name', 'woocommerce' ),
76+
'show' => false,
77+
),
78+
'last_name' => array(
79+
'label' => __( 'Last name', 'woocommerce' ),
80+
'show' => false,
81+
),
82+
'company' => array(
83+
'label' => __( 'Company', 'woocommerce' ),
84+
'show' => false,
85+
),
86+
'address_1' => array(
87+
'label' => __( 'Address line 1', 'woocommerce' ),
88+
'show' => false,
89+
),
90+
'address_2' => array(
91+
'label' => __( 'Address line 2', 'woocommerce' ),
92+
'show' => false,
93+
),
94+
'city' => array(
95+
'label' => __( 'City', 'woocommerce' ),
96+
'show' => false,
97+
),
98+
'postcode' => array(
99+
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
100+
'show' => false,
101+
),
102+
'country' => array(
103+
'label' => __( 'Country', 'woocommerce' ),
104+
'show' => false,
105+
),
106+
'state' => array(
107+
'label' => __( 'State / County', 'woocommerce' ),
108+
'show' => false,
109+
),
110+
)
111+
);
112+
24113
if ( WC()->payment_gateways() ) {
25114
$payment_gateways = WC()->payment_gateways->payment_gateways();
26115
} else {
@@ -29,6 +118,8 @@
29118

30119
$payment_method = $order->get_payment_method();
31120

121+
$order_type_object = get_post_type_object( $post->post_type );
122+
32123
$payment_gateway = wc_get_payment_gateway_by_order( $order );
33124
$line_items = $order->get_items( apply_filters( 'woocommerce_admin_order_item_types', 'line_item' ) );
34125
$discounts = $order->get_items( 'discount' );
@@ -112,9 +203,10 @@
112203
<h2 class="woocommerce-order-data__heading">
113204
<h2 class="woocommerce-order-data__heading">
114205
<?php
115-
/* translators: 1: order number */
206+
/* translators: 1: order type 2: order number */
116207
printf(
117-
esc_html__( 'Order #%1$s details', 'wc-order-view' ),
208+
esc_html__( '%1$s #%2$s details', 'wc-order-view' ),
209+
esc_html( $order_type_object->labels->singular_name ),
118210
esc_html( $order->get_order_number() )
119211
);
120212
?>
@@ -156,15 +248,15 @@
156248
</p>
157249
<div class="order_data_column_container">
158250
<div class="order_data_column">
159-
<h3>General</h3>
251+
<h3><?php esc_html_e( 'General', 'wc-order-view' ); ?></h3>
160252
<p class="form-field form-field-wide">
161-
<label for="order_date">Date Created:</label>
162-
<input class="date-picker" type="text" name="order_date" maxlength="10" value="<?php echo $order->get_date_created()->format ('Y-m-d'); ?>" readonly /> @
163-
<input class="hour" type="number" name="order_date_hour" min="0" max="23" step="1" value="<?php echo $order->get_date_created()->format ('H'); ?>" readonly /> :
164-
<input class="minute" type="number" name="order_date_minute" min="0" max="59" step="1" value="<?php echo $order->get_date_created()->format ('i'); ?>" readonly />
253+
<label for="order_date"><?php _e( 'Date created:', 'wc-order-view' ); ?></label>
254+
<input class="date-picker" type="text" name="order_date" maxlength="10" value="<?php echo esc_attr( date_i18n( 'Y-m-d', strtotime( $post->post_date ) ) ); ?>" readonly /> &lrm;
255+
<input class="hour" type="number" name="order_date_hour" min="0" max="23" step="1" value="<?php echo esc_attr( date_i18n( 'H', strtotime( $post->post_date ) ) ); ?>" readonly /> :
256+
<input class="minute" type="number" name="order_date_minute" min="0" max="59" step="1" value="<?php echo esc_attr( date_i18n( 'i', strtotime( $post->post_date ) ) ); ?>" readonly />
165257
</p>
166258
<p class="form-field form-field-wide wc-order-status">
167-
<label for="order_status">Status:</label>
259+
<label for="order_status"><?php _e( 'Status:', 'wc-order-view' ); ?></label>
168260
<input class="" type="text" name="order_status" value="<?php echo ucfirst( $order->get_status() ); ?>" readonly />
169261
</p>
170262
<p class="form-field form-field-wide wc-customer-user">
@@ -174,34 +266,72 @@
174266
</label>
175267
<input class="" type="text" name="order_status" value="<?php echo $user->first_name . ' ' . $user->last_name . ' (#' . $user->ID . ' - ' . $user->user_email . ')' ?>" readonly />
176268
</p>
269+
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>
177270
</div>
178271
<div class="order_data_column">
179-
<h3>Billing</h3>
272+
<h3><?php esc_html_e( 'Billing', 'wc-order-view' ); ?></h3>
180273
<div class="address">
181-
<?php if( ! empty( $order->get_formatted_billing_address() ) ) : ?>
182-
<p><?php echo $order->get_formatted_billing_address(); ?></p>
183-
<?php else : ?>
184-
<p class="none_set"><strong>Address:</strong>No billing address set.</p>
185-
<?php endif; ?>
186-
<p>
187-
<strong>Email Address:</strong>
188-
<a href="mailto:<?php echo $order->get_billing_email(); ?>"><?php echo $order->get_billing_email(); ?></a>
189-
</p>
190-
<p>
191-
<strong>Phone:</strong>
192-
<a href="tel:<?php echo $order->get_billing_phone(); ?>"><?php echo $order->get_billing_phone(); ?></a>
193-
</p>
274+
<?php
275+
// Display values.
276+
if ( $order->get_formatted_billing_address() ) {
277+
echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
278+
} else {
279+
echo '<p class="none_set"><strong>' . __( 'Address:', 'wc-order-view' ) . '</strong> ' . __( 'No billing address set.', 'wc-order-view' ) . '</p>';
280+
}
281+
foreach ( $billing_fields as $key => $field ) {
282+
if ( isset( $field['show'] ) && false === $field['show'] ) {
283+
continue;
284+
}
285+
$field_name = 'billing_' . $key;
286+
if ( isset( $field['value'] ) ) {
287+
$field_value = $field['value'];
288+
} elseif ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
289+
$field_value = $order->{"get_$field_name"}( 'edit' );
290+
} else {
291+
$field_value = $order->get_meta( '_' . $field_name );
292+
}
293+
if ( 'billing_phone' === $field_name ) {
294+
$field_value = wc_make_phone_clickable( $field_value );
295+
} else {
296+
$field_value = make_clickable( esc_html( $field_value ) );
297+
}
298+
if ( $field_value ) {
299+
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
300+
}
301+
}
302+
?>
194303
</div>
304+
<?php do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); ?>
195305
</div>
196306
<div class="order_data_column">
197-
<h3>Shipping</h3>
307+
<h3><?php esc_html_e( 'Shipping', 'wc-order-view' ); ?></h3>
198308
<div class="address">
199-
<?php if( ! empty( $order->get_formatted_shipping_address() ) ) : ?>
200-
<p><?php echo $order->get_formatted_shipping_address(); ?></p>
201-
<?php else : ?>
202-
<p class="none_set"><strong>Address:</strong>No shipping address set.</p>
203-
<?php endif; ?>
309+
<?php
310+
// Display values.
311+
if ( $order->get_formatted_shipping_address() ) {
312+
echo '<p>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
313+
} else {
314+
echo '<p class="none_set"><strong>' . __( 'Address:', 'wc-order-view' ) . '</strong> ' . __( 'No shipping address set.', 'wc-order-view' ) . '</p>';
315+
}
316+
if ( ! empty( $shipping_fields ) ) {
317+
foreach ( $shipping_fields as $key => $field ) {
318+
if ( isset( $field['show'] ) && false === $field['show'] ) {
319+
continue;
320+
}
321+
$field_name = 'shipping_' . $key;
322+
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
323+
$field_value = $order->{"get_$field_name"}( 'edit' );
324+
} else {
325+
$field_value = $order->get_meta( '_' . $field_name );
326+
}
327+
if ( $field_value ) {
328+
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
329+
}
330+
}
331+
}
332+
?>
204333
</div>
334+
<?php do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); ?>
205335
</div>
206336
</div>
207337
<div class="clear"></div>

0 commit comments

Comments
 (0)