From c247ca0bb727a3a9da62bfa54a842627cfbea584 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Sun, 10 Mar 2013 16:24:04 +0000 Subject: [PATCH] Show download file names when linking. Shortens links and therefore closes #2631. cc @coenjacobs --- classes/class-wc-order.php | 4 ++- readme.txt | 1 + templates/emails/email-order-items.php | 20 ++++++++++----- templates/order/order-details.php | 35 +++++++++++++++----------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/classes/class-wc-order.php b/classes/class-wc-order.php index 4d6e384d792..710375f61d4 100644 --- a/classes/class-wc-order.php +++ b/classes/class-wc-order.php @@ -1159,7 +1159,9 @@ class WC_Order { $file_urls = array(); foreach ( $results as $result ) { if ( $_product->has_file( $result->download_id ) ) { - $file_urls[] = add_query_arg( array( 'download_file' => $download_file, 'order' => $this->order_key, 'email' => $user_email, 'key' => $result->download_id ), trailingslashit( home_url() ) ); + + $file_urls[ $_product->get_file_download_path( $result->download_id ) ] = add_query_arg( array( 'download_file' => $download_file, 'order' => $this->order_key, 'email' => $user_email, 'key' => $result->download_id ), trailingslashit( home_url() ) ); + } } diff --git a/readme.txt b/readme.txt index 636125520d7..27b60b72581 100644 --- a/readme.txt +++ b/readme.txt @@ -174,6 +174,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Tweak - WC_START in checkout json requests to prevent notices breaking checkout. * Tweak - Add filters to product images and thumbnails. * Tweak - IPN email mismatch puts order on-hold. +* Tweak - Download file links show filename as part of link. * Fix - Samoa -> Western Samoa * Fix - Re-applied image setting tooltips * Fix - Post code ranges (taxes) on insert. diff --git a/templates/emails/email-order-items.php b/templates/emails/email-order-items.php index 0acc4222ac4..214b951cc78 100644 --- a/templates/emails/email-order-items.php +++ b/templates/emails/email-order-items.php @@ -4,7 +4,7 @@ * * @author WooThemes * @package WooCommerce/Templates/Emails - * @version 1.6.4 + * @version 2.0.3 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -32,17 +32,25 @@ foreach ($items as $item) : echo ($show_sku && $_product->get_sku()) ? ' (#' . $_product->get_sku() . ')' : ''; // File URLs - if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) : + if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) { + $download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item ); - foreach ( $download_file_urls as $i => $download_file_url ) : + + $i = 0; + + foreach ( $download_file_urls as $file_url => $download_file_url ) { echo '
'; + if ( count( $download_file_urls ) > 1 ) { echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 ); } elseif ( $i == 0 ) echo __( 'Download:', 'woocommerce' ); - echo ' ' . $download_file_url . ''; - endforeach; - endif; + + echo ' ' . basename( $file_url ) . ''; + + $i++; + } + } // Variation echo ($item_meta->meta) ? '
' . nl2br( $item_meta->display( true, true ) ) . '' : ''; diff --git a/templates/order/order-details.php b/templates/order/order-details.php index 68abd77e34f..67fc256aa62 100755 --- a/templates/order/order-details.php +++ b/templates/order/order-details.php @@ -4,7 +4,7 @@ * * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 2.0.3 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -35,9 +35,9 @@ $order = new WC_Order( $order_id ); get_items())>0) : + if (sizeof($order->get_items())>0) { - foreach($order->get_items() as $item) : + foreach($order->get_items() as $item) { $_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] ); @@ -50,26 +50,33 @@ $order = new WC_Order( $order_id ); $item_meta = new WC_Order_Item_Meta( $item['item_meta'] ); $item_meta->display(); - if ( $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) : + if ( $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) { $download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item ); - foreach ( $download_file_urls as $i => $download_file_url ) : - echo '
' . sprintf( __( 'Download file %s →', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? $i + 1 : '' ) ) . ''; - endforeach; - endif; + $i = 0; + $links = array(); + + foreach ( $download_file_urls as $file_url => $download_file_url ) { + + $links[] = '' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? ' ' . ( $i + 1 ) . ': ' : ': ' ) ) . basename( $file_url ) . ''; + + $i++; + } + + echo implode( '
', $links ); + } echo '' . $order->get_formatted_line_subtotal( $item ) . ''; // Show any purchase notes - if ($order->status=='completed' || $order->status=='processing') : - if ($purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) : + if ($order->status=='completed' || $order->status=='processing') { + if ($purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) echo '' . apply_filters('the_content', $purchase_note) . ''; - endif; - endif; + } - endforeach; - endif; + } + } do_action( 'woocommerce_order_items_table', $order ); ?>