Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit 5de4834

Browse files
author
Justin Shreve
committed
Overwrites the order details template, to update the admin view order link to point to WordPress.com.
1 parent 0ca1d3f commit 5de4834

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Order details table shown in emails.
4+
*
5+
* This matches version 3.0.0 of the email-order-details template.
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
$text_align = is_rtl() ? 'right' : 'left';
13+
14+
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
15+
16+
<?php if ( ! $sent_to_admin ) : ?>
17+
<h2><?php printf( __( 'Order #%s', 'wc-api-dev' ), $order->get_order_number() ); ?></h2>
18+
<?php else : ?>
19+
<h2><a class="link" href="<?php echo esc_url( wc_api_dev_email_get_wpcom_order_link( $order->get_id() ) ); ?>"><?php printf( __( 'Order #%s', 'wc-api-dev' ), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ); ?>)</h2>
20+
<?php endif; ?>
21+
22+
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
23+
<thead>
24+
<tr>
25+
<th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e( 'Product', 'wc-api-dev' ); ?></th>
26+
<th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e( 'Quantity', 'wc-api-dev' ); ?></th>
27+
<th class="td" scope="col" style="text-align:<?php echo $text_align; ?>;"><?php _e( 'Price', 'wc-api-dev' ); ?></th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<?php echo wc_get_email_order_items( $order, array(
32+
'show_sku' => $sent_to_admin,
33+
'show_image' => false,
34+
'image_size' => array( 32, 32 ),
35+
'plain_text' => $plain_text,
36+
'sent_to_admin' => $sent_to_admin,
37+
) ); ?>
38+
</tbody>
39+
<tfoot>
40+
<?php
41+
if ( $totals = $order->get_order_item_totals() ) {
42+
$i = 0;
43+
foreach ( $totals as $total ) {
44+
$i++;
45+
?><tr>
46+
<th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
47+
<td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td>
48+
</tr><?php
49+
}
50+
}
51+
?>
52+
</tfoot>
53+
</table>
54+
55+
<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Order details table shown in emails.
4+
*
5+
* This matches version 2.5.0 of the email-order-details plain template.
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );
13+
14+
echo strtoupper( sprintf( __( 'Order number: %s', 'wc-api-dev' ), $order->get_order_number() ) ) . "\n";
15+
echo wc_format_datetime( $order->get_date_created() ) . "\n";
16+
echo "\n" . wc_get_email_order_items( $order, array(
17+
'show_sku' => $sent_to_admin,
18+
'show_image' => false,
19+
'image_size' => array( 32, 32 ),
20+
'plain_text' => true,
21+
'sent_to_admin' => $sent_to_admin,
22+
) );
23+
24+
echo "==========\n\n";
25+
26+
if ( $totals = $order->get_order_item_totals() ) {
27+
foreach ( $totals as $total ) {
28+
echo $total['label'] . "\t " . $total['value'] . "\n";
29+
}
30+
}
31+
32+
if ( $sent_to_admin ) {
33+
echo "\n" . sprintf( __( 'View order: %s', 'wc-api-dev' ), wc_api_dev_email_get_wpcom_order_link( $order->get_id() ) ) . "\n";
34+
}
35+
36+
do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email );
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Provides a hotfix that points the admin order URL to WordPress.com instead of wp-admin.
4+
*
5+
* @since 0.8.1
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
function wc_api_dev_email_get_wpcom_order_link( $order_id ) {
13+
$site_slug = preg_replace( '/^https?:\/\//', '', get_site_url() );
14+
return 'https://wordpress.com/store/order/' . $site_slug . '/' . absint( $order_id );
15+
}
16+
17+
function wc_api_dev_email_order_url( $markup, $sent_to_admin, $order ) {
18+
$order_url = $sent_to_admin ? wc_api_dev_email_get_wpcom_order_link( $order->get_id() ) : $order->get_view_order_url();
19+
20+
$markup['url'] = $order_url;
21+
$markup['potentialAction'] = array(
22+
'@type' => 'ViewAction',
23+
'name' => 'View Order',
24+
'url' => $order_url,
25+
'target' => $order_url,
26+
);
27+
28+
return $markup;
29+
}
30+
add_filter( 'woocommerce_structured_data_order', 'wc_api_dev_email_order_url', 10, 3 );
31+
32+
function wc_api_dev_email_order_details_get_template( $located, $template_name, $args, $template_path, $default_path ) {
33+
if ( 'emails/email-order-details.php' === $template_name ) {
34+
return dirname( __FILE__ ) . '/email-templates/email-order-details.php';
35+
}
36+
if ( 'emails/plain/email-order-details.php' === $template_name ) {
37+
return dirname( __FILE__ ) . '/email-templates/plain/email-order-details.php';
38+
}
39+
return $located;
40+
}
41+
add_filter( 'wc_get_template', 'wc_api_dev_email_order_details_get_template', 10, 5 );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This section describes how to install the plugin and get it working.
2727

2828
= 0.8.2 =
2929
* Fix - Don't auto enable the PayPal payment method.
30+
* Fix - Update order link in order details emails.
3031

3132
= 0.8.1 =
3233
* Fix - Fix auto plugin update logic

wc-api-dev.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public function includes() {
131131
if ( defined( 'WC_API_DEV_ENABLE_HOTFIXES' ) && true === WC_API_DEV_ENABLE_HOTFIXES ) {
132132
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-jetpack-hotfixes.php' );
133133
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-email-site-title.php' );
134+
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-email-order-url.php' );
134135
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-cheque-defaults.php' );
135136
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-paypal-defaults.php' );
136137
}

0 commit comments

Comments
 (0)