Time limited access to digital downloads in MarketPress

I would like to be able to offer time-limited access to digital downloads in MarketPress without needing to use a workaround with Memebership 2 Pro. Ideally, I'd like to offer access to unlimited downloads of a digital product for a set time period with the ability to upsell to a longer period of time - possibly as a product variation/upgrade.

Is this possible with MarketPress. If so, could you provide some assistance with the code?

  • Nahid

    Hey Tony !
    Hope you are having a great day!

    This request has been escalated to the Second Level Support team. They'll be back to us with confirmations if something like this would be achievable within MarketPress in this ticket (or we'll be updating the ticket as soon as we hear back from them internally). Please note that the response time of the Second Level Support team might be a bit delayed than that of the general Support staff. Moreover, as this is a custom request, we cannot assure a workaround from our end just yet without investigation. This might get flagged as a feature request or you might need to consider custom development if this turns out to be undoable from our end. We really appreciate your patience and consideration regarding this.

    Kind regards,
    Nahid

  • Panos

    Hi there Tony ,

    As this is a custom request we can't provide an exact solution. Since this is possible to achieve we can provide a simple snippet which you can use as a guide and modify to meet your needs :slight_smile:

    You can add the following snippet in a mu-plugin :

    function mp_maybe_download_by_date() {
    
    	if (
    		class_exists( 'MP_Public' ) &&
    		MP_Product::get_post_type() == get_query_var( 'post_type' ) &&
    		get_query_var( MP_Product::get_post_type() ) &&
    		$order_id = mp_get_get_value( 'orderid' ) )
    	{
    
    		$MP_Public 		= MP_Public::get_instance();
    		$product_id 	= ( $variation_id = get_query_var( 'mp_variation_id' ) ) ? $variation_id : get_queried_object_id();
    		$order 			= new MP_Order( $order_id );
    		$current_date 	= new DateTime( date( 'Y-m-d' ) );
    		$order_date 	= new DateTime( $order->post_date );
    		$date_diff 		= $order_date->diff( $current_date )->format('%R%a');
    		$allowed_days	= 5;
    
    		if( $date_diff >= $allowed_days ) {
    			wp_die( __( 'Sorry, the link is is not valid anymore' ) );
    			//OR Redirect to a page promoting upsell
    			//wp_redirect( get_permalink( 4059 ) );
    			//exit;
    		}
    
    		$MP_Public->serve_download( $product_id );
    	}
    }
    
    add_action( 'init', function(){
    
    	if( ! class_exists( 'MP_Public' ) ){
    		return;
    	}
    
    	$MP_Public = MP_Public::get_instance();
    	remove_action( 'template_redirect', array( $MP_Public, 'maybe_serve_download' ) );
    	add_action( 'template_redirect', 'mp_maybe_download_by_date' );
    });

    This should allow the download link to work for 5 days after order is made. You can change the number of days in line

    $allowed_days	= 5;

    Instead of displaying a message you could redirect to a page which would promote you up-sell as described in the comment in the snippet.

    Hope this helps :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.