Order status check needs to be inside wc_downloadable_product_permissions so permissions are granted after completion. Closes #4826
This commit is contained in:
parent
87c5274992
commit
7ab814ffa9
|
@ -40,9 +40,6 @@ function wc_get_order_id_by_order_key( $order_key ) {
|
||||||
function wc_downloadable_file_permission( $download_id, $product_id, $order ) {
|
function wc_downloadable_file_permission( $download_id, $product_id, $order ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( $order->status == 'processing' && get_option( 'woocommerce_downloads_grant_access_after_payment' ) == 'no' )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$user_email = sanitize_email( $order->billing_email );
|
$user_email = sanitize_email( $order->billing_email );
|
||||||
$limit = trim( get_post_meta( $product_id, '_download_limit', true ) );
|
$limit = trim( get_post_meta( $product_id, '_download_limit', true ) );
|
||||||
$expiry = trim( get_post_meta( $product_id, '_download_expiry', 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;
|
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
|
* 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 );
|
$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 ) {
|
if ( sizeof( $order->get_items() ) > 0 ) {
|
||||||
foreach ( $order->get_items() as $item ) {
|
foreach ( $order->get_items() as $item ) {
|
||||||
$_product = $order->get_product_from_item( $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 );
|
update_post_meta( $order_id, '_download_permissions_granted', 1 );
|
||||||
|
|
||||||
do_action( 'woocommerce_grant_product_download_permissions', $order_id );
|
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).
|
* Add a item to an order (for example a line item).
|
||||||
|
|
Loading…
Reference in New Issue