From 7ab814ffa951ceeb9b2c0349b19cd81ecb79edb4 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 17 Feb 2014 10:49:55 +0000 Subject: [PATCH] Order status check needs to be inside wc_downloadable_product_permissions so permissions are granted after completion. Closes #4826 --- includes/wc-order-functions.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index fc3cb6c3d21..f2fa2c5f5bb 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -40,9 +40,6 @@ function wc_get_order_id_by_order_key( $order_key ) { function wc_downloadable_file_permission( $download_id, $product_id, $order ) { global $wpdb; - if ( $order->status == 'processing' && get_option( 'woocommerce_downloads_grant_access_after_payment' ) == 'no' ) - return false; - $user_email = sanitize_email( $order->billing_email ); $limit = trim( get_post_meta( $product_id, '_download_limit', true ) ); $expiry = trim( get_post_meta( $product_id, '_download_expiry', true ) ); @@ -97,10 +94,6 @@ function wc_downloadable_file_permission( $download_id, $product_id, $order ) { return $result ? $wpdb->insert_id : false; } -add_action('woocommerce_order_status_completed', 'wc_downloadable_product_permissions'); -add_action('woocommerce_order_status_processing', 'wc_downloadable_product_permissions'); - - /** * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER * @@ -114,6 +107,9 @@ function wc_downloadable_product_permissions( $order_id ) { $order = new WC_Order( $order_id ); + if ( $order->status == 'processing' && get_option( 'woocommerce_downloads_grant_access_after_payment' ) == 'no' ) + return; + if ( sizeof( $order->get_items() ) > 0 ) { foreach ( $order->get_items() as $item ) { $_product = $order->get_product_from_item( $item ); @@ -131,8 +127,10 @@ function wc_downloadable_product_permissions( $order_id ) { update_post_meta( $order_id, '_download_permissions_granted', 1 ); do_action( 'woocommerce_grant_product_download_permissions', $order_id ); - } +add_action( 'woocommerce_order_status_completed', 'wc_downloadable_product_permissions' ); +add_action( 'woocommerce_order_status_processing', 'wc_downloadable_product_permissions' ); + /** * Add a item to an order (for example a line item).