has_file() Closes #1275.

This commit is contained in:
Mike Jolley 2012-07-31 12:58:00 +01:00
parent a322a83a7d
commit 2e96d554ce
5 changed files with 16 additions and 4 deletions

View File

@ -670,11 +670,11 @@ class WC_Order {
/** Gets a downloadable products file url */
function get_downloadable_file_url( $item_id, $variation_id ) {
$download_id = ($variation_id>0) ? $variation_id : $item_id;
$download_id = $variation_id > 0 ? $variation_id : $item_id;
$user_email = $this->billing_email;
return add_query_arg('download_file', $download_id, add_query_arg('order', $this->order_key, add_query_arg('email', $user_email, trailingslashit( home_url() ))));
return add_query_arg( 'download_file', $download_id, add_query_arg( 'order', $this->order_key, add_query_arg( 'email', $user_email, trailingslashit( home_url() ) ) ) );
}
/**

View File

@ -269,6 +269,17 @@ class WC_Product {
if ( $this->downloadable == 'yes' ) return true; else return false;
}
/**
* Checks if a downloadable product has a file attached to it
*/
function has_file() {
if ( ! $this->is_downloadable() )
return false;
if ( apply_filters( 'woocommerce_file_download_path', get_post_meta( $this->id, '_file_path', true ), $this->id ) )
return true;
}
/**
* Checks if a product is virtual (has no shipping)
*/

View File

@ -152,6 +152,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
= 1.6.2 - 20/07/2012 =
* Feature - Added google analytics event tracking for add to cart buttons (thanks to Max Rice)
* Feature - WC_Product::has_file() for detecting if a downloadable product has a file set
* Tweak - Hide admin order comments box if they are disabled
* Tweak - Added mini-cart.php template for the cart widget output
* Tweak - Simplified the product data write panels

View File

@ -28,7 +28,7 @@ foreach ($items as $item) :
echo ($show_sku && $_product->get_sku()) ? ' (#' . $_product->get_sku() . ')' : '';
// File URL
echo ($show_download_links && $_product->exists() && $_product->is_downloadable()) ? '<br/><small>'.__('Download:', 'woocommerce').' <a href="' . $order->get_downloadable_file_url( $item['id'], $item['variation_id'] ) . '" target="_blank">' . $order->get_downloadable_file_url( $item['id'], $item['variation_id'] ) . '</a></small>' : '';
echo ( $show_download_links && $_product->exists() && $_product->is_downloadable() && $_product->has_file() ) ? '<br/><small>' . __( 'Download:', 'woocommerce' ) . ' <a href="' . $order->get_downloadable_file_url( $item['id'], $item['variation_id'] ) . '" target="_blank">' . $order->get_downloadable_file_url( $item['id'], $item['variation_id'] ) . '</a></small>' : '';
// Variation
echo ($item_meta->meta) ? '<br/><small>' . nl2br( $item_meta->display( true, true ) ) . '</small>' : '';

View File

@ -49,7 +49,7 @@ $order = new WC_Order( $order_id );
$item_meta = new order_item_meta( $item['item_meta'] );
$item_meta->display();
if ($_product->exists() && $_product->is_downloadable() && ($order->status=='completed' || (get_option('woocommerce_downloads_grant_access_after_payment')=='yes' && $order->status=='processing'))) :
if ( $_product->exists() && $_product->is_downloadable() && $_product->has_file() && ( $order->status=='completed' || ( get_option( 'woocommerce_downloads_grant_access_after_payment' ) == 'yes' && $order->status == 'processing' ) ) ) :
echo '<br/><small><a href="' . $order->get_downloadable_file_url( $item['id'], $item['variation_id'] ) . '">' . __('Download file &rarr;', 'woocommerce') . '</a></small>';