From 8f0fce893e6b504de115f34dba316abd05fc5367 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 6 Dec 2012 15:39:59 +0000 Subject: [PATCH] Fix download links and post_status checks. Closes #1903. --- classes/abstracts/abstract-wc-product.php | 1 + classes/class-wc-customer.php | 2 +- classes/class-wc-order.php | 4 ++++ woocommerce-functions.php | 6 +++--- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/classes/abstracts/abstract-wc-product.php b/classes/abstracts/abstract-wc-product.php index 8521c3ec6fa..03bddb3f766 100644 --- a/classes/abstracts/abstract-wc-product.php +++ b/classes/abstracts/abstract-wc-product.php @@ -293,6 +293,7 @@ abstract class WC_Product { function get_file_download_path( $download_id ) { $file_paths = isset( $this->product_custom_fields['_file_paths'][0] ) ? $this->product_custom_fields['_file_paths'][0] : ''; + $file_paths = maybe_unserialize( $file_paths ); $file_paths = apply_filters( 'woocommerce_file_download_paths', $file_paths, $this->id, null, null ); if ( ! $download_id && count( $file_paths ) == 1 ) { diff --git a/classes/class-wc-customer.php b/classes/class-wc-customer.php index 75d478e3f2e..c34c40daedb 100644 --- a/classes/class-wc-customer.php +++ b/classes/class-wc-customer.php @@ -589,7 +589,7 @@ class WC_Customer { } // order exists and downloads permitted? - if ( ! $order->id || ! $order->is_download_permitted() || $order->status != 'publish' ) continue; + if ( ! $order->id || ! $order->is_download_permitted() || $order->post_status != 'publish' ) continue; if ( ! $_product || $_product->id != $result->product_id ) : // new product diff --git a/classes/class-wc-order.php b/classes/class-wc-order.php index b6b653d944b..8da2f2815fb 100644 --- a/classes/class-wc-order.php +++ b/classes/class-wc-order.php @@ -146,6 +146,9 @@ class WC_Order { /** @var string */ var $formatted_shipping_address; + /** @var string */ + var $post_status; + /** * Get the order if ID is passed, otherwise the order is new and empty. * @@ -196,6 +199,7 @@ class WC_Order { $this->order_date = $result->post_date; $this->modified_date = $result->post_modified; $this->customer_note = $result->post_excerpt; + $this->post_status = $result->post_status; $this->order_custom_fields = get_post_custom( $this->id ); // Define the data we're going to load: Key => Default value diff --git a/woocommerce-functions.php b/woocommerce-functions.php index 90b55936dbc..2f72467eadd 100644 --- a/woocommerce-functions.php +++ b/woocommerce-functions.php @@ -822,7 +822,7 @@ function woocommerce_cancel_order() { $order = new WC_Order( $order_id ); - if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed')) && $woocommerce->verify_nonce('cancel_order', '_GET')) : + if ( $order->id == $order_id && $order->order_key == $order_key && in_array( $order->status, array( 'pending', 'failed' ) ) && $woocommerce->verify_nonce( 'cancel_order', '_GET' ) ) : // Cancel the order + restore stock $order->cancel_order( __('Order cancelled by customer.', 'woocommerce' ) ); @@ -832,7 +832,7 @@ function woocommerce_cancel_order() { do_action( 'woocommerce_cancelled_order', $order->id ); - elseif ($order->status!='pending') : + elseif ( $order->status != 'pending' ) : $woocommerce->add_error( __( 'Your order is no longer pending and could not be cancelled. Please contact us if you need assistance.', 'woocommerce' ) ); @@ -915,7 +915,7 @@ function woocommerce_download_product() { if ( $order_id ) { $order = new WC_Order( $order_id ); - if ( ! $order->is_download_permitted() || $order->status != 'publish' ) + if ( ! $order->is_download_permitted() || $order->post_status != 'publish' ) wp_die( __( 'Invalid order.', 'woocommerce' ) . ' ' . __( 'Go to homepage →', 'woocommerce' ) . '' ); }