Sequential Subscriptions to the Same Product

Discussion in 'Customization & add-ons' started by unmortal, Oct 18, 2014.

  1. unmortal

    unmortal New Member

    Joined:
    Sep 10, 2006
    Messages:
    25
    I have a membership calendar year of Nov 1st to Nov 1st. All of my products have a fixed start date of Nov 1st.

    I’m trying to work a solution for someone joining in the middle of the year. What we thought of was to create a second record for each product, but set it to a monthly term/cost and allow Quantity. Then invoice the user for x amount of subscriptions to the monthly. So if they joined in June, invoice for 5 monthly subscriptions. They would then expire and be forced to renew into the yearly.

    Is this possible out of the box? I've been messing around with the product options and it always seems to run 5 subscriptions at once. I will add 5 Monthly's to the invoice and it will charge the customer correctly but only give them access for 1 month.

    Am I missing something?
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    The best approach that I see is set duration of product to 1 year and set 'Start Date Calculation' to Fixed Date: 1 Nov for your product. Than you can decrease price of this product each month from admin interface. All subscribers always get access record that begin at 1 Nov with duration of 1 year.
  3. unmortal

    unmortal New Member

    Joined:
    Sep 10, 2006
    Messages:
    25
    I was able to come up with a workaround solution that changes the price automatically, in this case every 3 months. This example also changes the fixed start date for various products and emails the admin every time there is a change. A cron job needs to be configured to run on the important dates, in this case the 1st and 15th of every month.

    Code:
    <?php
    
    // Call date one time, and store in a variable.
    $currentDate = date('Md');
    
    // Print todays Date Similar to Oct08
    echo "Today is ";
    echo $currentDate;
    echo "\r\n<br />";
    
    // Connect to the Database Once
    $con = mysqli_connect("localhost","dbuser","password","database");
    
    // Check connection
    if (mysqli_connect_error()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    } else {
      echo "We are Connected!";
    }
    
    // Lets prepare to email the admin with the results
    $to      = 'webmaster@domain.com';
    $subject = 'aMember Database Automatic Update Alert';
    $message_nov = 'Hello Webmaster, the aMember database has been updated by the /price-changer.php script. New signup prices have been changed to full price. The script also updated the fixed start date for all term products. Please verify this in aMember backend.';
    $message_feb = 'Hello Webmaster, the aMember database has been updated by the /price-changer.php script. New signup prices have been changed to 3/4 price. Please verify this in aMember backend.';
    $message_may = 'Hello Webmaster, the aMember database has been updated by the /price-changer.php script. New signup prices have been changed to half price. Please verify this in aMember backend.';
    $message_aug = 'Hello Webmaster, the aMember database has been updated by the /price-changer.php script. New signup prices have been changed to 1/4 price. Please verify this in aMember backend.';
    $message_tst = 'Hello Webmaster, the /price-changer.php script has run but nothing was updated in the database. Prices have not been changed. Please verify this in aMember backend.';
    $headers = 'From: admin@domain.com' . "\r\n" .
        'Reply-To: admin@domian.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
    // Check to see if it is October 15th
    if ($currentDate == "Oct15") {
      echo "Today is October 15!";
    
      // Perform October Queries, Making all subscriptions full Price
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 55.00 WHERE product_id IN (2, 3, 4, 5)");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 15.00 WHERE product_id = 1");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 30.00 WHERE product_id = 11");
    
      // Lets also update the yearly subscription Start Date, this only happens in October
      $new_fixed_start = date('Y')."-11-01"; 
      mysqli_query($con,"UPDATE am_product SET start_date_fixed = '$new_fixed_start' WHERE product_id IN (1, 2, 3, 4, 5, 6, 7, 10, 11)");
      mysqli_close($con);
    
      echo "\r\n<br />";
      echo "We've executed the October 15th Queries making everything full price!";
     
      // Finally send notification email to the webmaster
      mail($to, $subject, $message_nov, $headers);
    }
    
    // Check to see if it is February 1st
    if ($currentDate == "Feb01") { 
      echo "Today is February 1st!";
    
      // Perform February Queries, Making all subscriptions 3/4 Price
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 41.25 WHERE product_id IN (2, 3, 4, 5)");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 11.25 WHERE product_id = 1");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 22.50 WHERE product_id = 11");
      mysqli_close($con);
    
      echo "\r\n<br />";
      echo "We've executed the February 1st Queries making everything 3/4 price!";
     
      // Finally send notification email to the webmaster
      mail($to, $subject, $message_feb, $headers);
    }
    
    // Check to see if it is May 1st
    if ($currentDate == "May01") { 
      echo "Today is May 1st!";
    
      // Perform May Queries, Making all subscriptions half Price
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 27.50 WHERE product_id IN (2, 3, 4, 5)");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 7.50 WHERE product_id = 1");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 15.00 WHERE product_id = 11");
      mysqli_close($con);
    
      echo "\r\n<br />";
      echo "We've executed the May 1st Queries making everything half price!";
     
      // Finally send notification email to the webmaster
      mail($to, $subject, $message_may, $headers);
    }
    
    // Check to see if it is August 1st
    if ($currentDate == "Aug01") {
      echo "Today is August 1st!";
    
      // Perform August Queries, Making all subscriptions 1/4 Price
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 13.75 WHERE product_id IN (2, 3, 4, 5)");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 3.75 WHERE product_id = 1");
      mysqli_query($con,"UPDATE am_billing_plan SET first_price = 7.5 WHERE product_id = 11");
      mysqli_close($con);
    
      echo "\r\n<br />";
      echo "We've executed the August 1st Queries making everything 1/4 price!";
     
      // Finally send notification email to the webmaster
      mail($to, $subject, $message_aug, $headers);
    }
    
    // This is a template for testing
    // if ($currentDate == "Oct27") {
       echo "Today is October 27th!";
       echo "\r\n<br />";
       echo "Nothing remarkable happened today!";
    
      // Finally send notification email to the webmaster
      mail($to, $subject, $message_tst, $headers);
    // }
    
    ?>

Share This Page