How can I charge for a subscription immediately?

I am setting up foxycart for a monthly box subscription that ships out on the 15th of every month and charges on the 15th of every month. The charge is for the following month, regardless of the date of initial signup. For example, If someone signs up for a subscription on July 1st they are charged on July 1st upon sign up, their first box is shipped on August 15th, and their next charge is on August 15th where that box is shipped on September 15th; if they sign up for a subscription on July 17th they are charged on July 17th upon initial sign up, their first box is shipped on August 15th, and their next charge is on August 15th where that box is shipped on September 15th. How can I do that? Currently if I set the start date for the 15th then it will not charge for any dates from the 16th-30th/31st. If I set no date then it will charge on the same date as sign up every month.
Comments
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3

    Hi there! Good question. To achieve what you're after there - mixing together a future-dated subscription and an immediate charge, you can make use of 2 products in the cart - one the subscription and the other a normal one-off product. To ensure the customer has to check out with both products, you would also make use of our bundled products functionality - which ties multiple products together so that when one is removed, so is the other.

    As an example, this is what that could look like as a link:
    https://YOURSTORE.foxycart.com/cart?name=Monthly+Box+Subscription&price=15.99&code=boxsub&sub_frequency=1m&sub_startdate=15&2:name=First+Month&2:price=15.99&2:parent_code=boxsub&2:quantity_min=1
    Note how there are two products there, with the second products attributes prepended with 2: to differentiate them from the first. The second one-off product also is linked to the first using the parent_code and then the quantity_min is used to prevent it from being removed on its own.
  • Thank you very much! One more question-if I do it this way and the customer orders before the 15th will they be charged again on the 15th?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Yes they will. Setting the subscription product with a sub_startdate=15 means that the subscription will start on the next 15th of the month. So if they order on the 12th, they'll pay $15.99 today from the one-off product, and $15.99 3 days later on the 15th.

    If someone orders on the 15th - they'll pay for both charges that day for a total of $31.98.
  • Is there any way to prevent it from charging them the second time?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    To confirm - are you referring to if they happen to order on the 15th, that it wouldn't charge both the one-off and the subscription costs? If so - there are two ways you could approach it, both requiring some customisation to your add to cart page.

    One would be to dynamically set the sub_startdate attribute to be an actual full date, that you could calculate serverside or with some javascript. You'd calculate when the next 15th of the month would be, which if it's the 15th today, you'd set it to the 15th of the next month instead.

    The other approach would be similar, but if it's the 15th today, you'd simply not include the second one-off product as part of the add to cart. This would mean the customer would just add the subscription product which would start today.

    Could either of those approaches work?
  • I probably should have mentioned that I use foxyshop for wordpress so I'm not familiar with the customization possibilities with that. Adding a one-off product would work for the end half of the month but then it wouldn't work for the beginning half of the month. Let me see if I can explain what I'd like to do a little better...

    I have a monthly subscription (I'm actually working on migrating it off of cratejoy and onto my own) box that bills on the 15th and ships out on the 15th of every month. All billing and all new subscribers are charged in the previous month, meaning any charges whatsoever (be it brand new customers or customers who have been enrolled for months or years) are for the box shipping out the next month Here is an example using the month of July showing initial first time, new customer enrollment:

    July 1st enrollment pays for the August 15th box shipment
    July 2nd enrollment pays for the August 15th box shipment
    July 3rd enrollment pays for the August 15th box.......
    and so on...July 4th, 5th, 6th.....
    ....July 13th, 14th, 15th....
    ....July 16th, 17th, 18th....
    ....July 29th, 30th, 31st...
    Payment on every single day in July pays for the box shipping out in August.
    I want to somehow charge every single brand new customer for one month's worth of the subscription upon checkout with initial enrollment and then their next billing to be the following month. In this example a payment is collected on the enrollment date and the next payment would be August 15th.

    My problems are:
    Currently anyone who subscribes July 1st-15th will not be paying when they enroll but will be billed on the 15th, which will work fine for my needs. However, if I include a one-off with the enrollment they will be charged the initial payment but will be charged again on the 15th which equals an overcharge...they've paid for August twice.
    Anyone who subscribes July 16th-31st will not be billed until August 15th. This means that while they enroll in July they will not get a box shipped to them in August because they have not paid for it. They won't get a box until September because their first payment won't post until August 15th. I fear I will lose customers because of this due to them not understanding why they have to wait 2 months to receive their first box.

    Now...creating a one-off charge bundled with the subscription will work for anyone who enrolls from July 16th-July 31st but it will not work for anyone who enrolls from July 1st-15th as they will get charged twice but will not receive a July box. The reason why I need a month of prepayment is because the boxes are all customized and different every single month so I need those weeks to procure them. I need that previous month's time to ensure I order enough product to put in the boxes as well as the correct custom products. I can't have someone who enrolls a few days before my shipping date because that is not enough time to prepare their box. I won't have enough inventory to build their box

    Are there any round-about ways to handle this? Is there even a way that I can manually handle it? Would it work to create 2 identical products-one without the one-off charge and one with it, then setting one to private and alternate them according to the 15th of every month? This is the only thing I could think of to do but if there is an easier or better way to handle it I'd prefer that.
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Thanks so much for laying that all out - I better understand now what you're wanting to achieve. So with that in mind, what I'd recommend would be to have the add to cart with a bundled one-time product and a subscription product, but rather than have the subscription start date specified as just 15 to be the next 15th of the month, specify a full date that represents the 15th of the following month. In other words - a subscription would never start in the same month that the customer orders in. Instead the payment for that month would be covered by the one-off payment.

    As an example, any orders placed in July would have a subscription which starts the 15th of August along with a one-off product that charges straight away.

    By taking that approach - your orders will all be consistent in how the customer is charged.

    In terms of how to handle that with FoxyShop - it will require adding a variation for a text input for the sub_startdate. This will be visible on the page in the add to cart, but you can hide it with CSS like this:
    .variation-sub_startdate { display:none; }
    With a blank input for the sub_startdate - the subscription would start straight away. To set the subscription to be the 15th of the next month - you would achieve that with some custom javascript. That could look like this:
    <script>
    jQuery(document).ready(function() {
    var d = new Date();
    d.setDate(15);
    d.setMonth(d.getMonth() + 1);
    jQuery("[name^='sub_startdate']").val(d.getFullYear() + "" + ("0" + (d.getMonth() + 1)).slice(-2) + "" + d.getDate());
    });
    </script>
    This javascript gets todays date (based on the customers computer), sets the day to the 15th, adds a month to it and finally updates that text input with the date. This will get the subscription starting on the 15th of the next month.

    With that set up - paired with the product in FoxyShop that is bundled with the one-time charge, that should hopefully get you the setup you needed. There are a couple parts to it - but should hopefully be easy to set up. Let us know if anything needs clarification.
  • Great! That looks like it may work. We will implement it and post our results here. Thank you very much for your help!
  • I've run into some problems that I need help with because I'm using foxyshop with wordpress...

    You said that I would need to add a variation to the product for the sub-startdate. I assume that can be added on the variations page with all the other product variations, right? Then I need to make it not show on the page with the javascript snippet. Where exactly do I put javascript code to affect variations? I couldn't find a place in the Foxyshop dashboard for "page javascript."

    Then you showed me some sample code for custom javascript to dynamically set the sub-startdate. My question is again -- where does this code actually go?

    Finally, you mention that this will pair with the product bundled with the 1-time charge. That is referring to your code earlier in the thread that shows a product link. With this change, I would remove the sub-startdate from that link -- since it is not being set dynamically. But -- since I'm using the Wordpress plugin FoxyShop, products are set up in the admin panel rather than with custom links.
    Is there a separate place to bundle the products? Or can I still use such a custom link?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Sorry for the confusion there.

    Let's start off with the product first - you will want to create that within the FoxyShop interface, and you'll need to create two products. The first product will be for the 1 time charge - so create the product for that. You don't want people to be able to purchase this one on it's own, so you'll want to check the "Hide This Product From List View" checkbox in the "Product Details" panel in the right hand sidebar.

    Next you'll create the subscription product in FoxyShop as well - configuring it as needed. Within Product Variations when creating the product, you'll create a "Single Line Of Text" field, and give it a name of "sub_startdate". Although FoxyShop's native subscription functionality does support specifying a start date - as there isn't a native way to set it to always be the 15th of next month, we'll use a custom open field.

    Finally - you'll also want to link your 1 time charge product to the subscription product, which you'll do with the bundled products functionality. If you don't see the "Bundled Products" option towards the bottom of the product page, you'll need to enable it from the "Settings" page of the FoxyShop plugin. Under "Product Relation" on the settings page, check "Enable Bundled Products" and save. Then on the product page, within the "Bundled Products" input, start typing the name of your 1 time charge product and select that.

    At this point, you'll have a subscription product that has the 1 time charge attached - but the subscription will be starting instantly, and you'll see the text input for the start date.

    You'll want to hide the text input with the CSS I provided earlier. This would be best included within a stylesheet as part of your theme. If you don't have access to the files that make up your website, or a way to upload changes to your server, you could also edit the stylesheet using the "Appearance > Editor" option within your Wordpress administration. For reference, this is the style you'll need to include:
    .variation-sub_startdate { display:none; }
    The javascript is similar again - you'll want to include that within your website files as a javascript file, and include that as part of your theme. If you don't have access to your website's files - you can use the "Appearance > Editor" option again to edit the files. For the javascript, you could place that within the "footer.php" file of your theme and right before the closing </body> tag, paste the javascript - included again for your reference here:
    <script>
    jQuery(document).ready(function() {
    var d = new Date();
    d.setDate(15);
    d.setMonth(d.getMonth() + 1);
    jQuery("[name^='sub_startdate']").val(d.getFullYear() + "" + ("0" + (d.getMonth() + 1)).slice(-2) + "" + d.getDate());
    });
    </script>
    With all of that completed - your subscription product page should then not show the start date input, and it would be pre-filled with the date for the 15th of next month.

    I hope that helps clear up any confusion! Let us know if you have any further questions.
  • I put in the changes as you said. The bundle, the text field, and the javascript to hide it all work.
    But the javascript to change the date doesn't do anything. The date is always set for today's date.
    I put the <script> section in the footer.html file just above the close body tag.
    I even tried changing the value of the variable to a hardcoded value -- "16"
    jQuery("[name^='sub_startdate']").val("16");
    No change.
    I did try putting an alert at the end of the code just to verify that it was being run. I could get that to show up.
    I also double-checked to make sure that the variable name I made in the variation was sub_startdate -- just like in the javascript.

    Do you have any suggestions to make it work?
  • brettbrett FoxyCart Team
    Hey @dragonfiy3
    Could you whisper us a URL we can take a look? That might make it a lot easier to figure out what's gone wrong.
  • My website is live but the foxycart is not, it's set to private and I can't set it to public right now because it will cause confusion on the live site. The only way to see it is to log in as admin so that won't work. I can post screenshots.
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    While screenshots are generally helpful - in this case it'll be best for us to see the code in action. Would it be possible to add us temporarily as a user for your Wordpress set up? I'll whisper the email address you can use for that if that would be ok.
  • Sorry to revive this thread but I have a new problem related to this. I am now offering a subscription product in which you can add variations that add to the total cost of the subscription (example: add cosmetics to your subscription for +$10.00). Creating the separate 1 time charge that is bundled with the subscription product won't work in this instance because the first time charge will vary depending on the variations that the customer may choose. Is there a way to create the variable one time bundled charge to reflect the variations that the customer chooses?
  • brettbrett FoxyCart Team
    Hi @dragonfiy3. Because this is an old thread, I want to make sure of something real quickly:
    Will the one-time charge be initiated by the customer and paid via the customer going through the checkout? I ask because it's now possible to do charges entirely via the API. I don't think that's what you're after, but I want to make sure.
  • @brett The one time charge is another product that is bundled with the subscription. That one time product is hidden from view in the products list. It's just a way to add a charge for the subscription right away. When a customer adds the subscription to the cart it adds that bundled product in order to charge them the price of the subscription when they order it.
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    To confirm your desired set up here - you currently have a bundled product that sets a subscription to start on the 15th of the next month, and then charges the same amount as the subscription today.

    You're wanting to be able to allow the customer to select variations on the subscription that would increase its price. The issue you're running into then is how to also update the bundled one-off product to ensure it's charging the same amount.

    If that is a correct summary - your best bet would be to dynamically update the bundled products price whenever the subscription is changed with javascript. We'd want to see the form in action though to ensure that would be the best approach.

    We discussed creating a WP user account for us in your other thread too - if you could do that, and confirm for us where we can see the form for this query here, we can take a look for you.
  • Yes that is correct. I created a foxy user account and sent you the info
  • fc_marijafc_marija FoxyCart Team
    Thanks @dragonfiy3 -

    We'll take a look there and see what guidance we can offer.
  • fc_adamfc_adam FoxyCart Team
    edited May 30
    @dragonfiy3,

    Thanks for your patience while we looked into this. I believe I've got a solution for you, to allow bundled products to match the dynamic price of their parent based on their selected variations.

    The solution will require customising the "foxyshop-single-product.php" themefile from the FoxyShop plugin directory. We recommend copying that file into your WP theme folder and editing it there, so any future updates to the FoxyShop plugin won't overwrite your customisations.

    Once you've got it copied, paste the code shown at this link right after the foxyshop_start_form(); line and save the file: https://pastebin.com/raw/4WiuMqtE

    Next, you'll need to make a small edit to your bundled products - as in the products that you are bundled into your other products. You'll want to edit each of those and add a hidden field variation. It should have a name of x:parent_price_match with a value of true.

    Any bundled products that have that specific variation present will have its price dynamically updated to match its parent product, as the customer makes changes to the variations on the product.

    I hope that helps solve the issue you're running into here! Let us know if you have any trouble getting it implemented.
  • Hi, sorry for the super late response. I've been tied up all week and haven't had the chance to test this out until now. I followed your instructions but unfortunately it didn't work. Is there anything else I need to do?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Sorry to hear it didn't work. Looking at your products - specifically the enrolment products that are bundled with the box products, none of those appear to have the "x:parent_price_match" variation added. I've just added that to the "basic" product - and that appears to be working now. If you add that same kind of variation to the other two enrolment products, you should see it working then.

    Let us know if you continue to have issues though and we can take another look.
  • I see, I was adding a custom field variation, not product variation. But I seem to still be having problems. When I open the product page of the main product (that has the "enrollment" product bundled into it) some of the variations are not showing up and when I try to add to cart I get several errors saying that I must choose from the dropdown menu, but there are selections made. It won't add it to the cart.
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Could I confirm with you what variations are missing? I compared the basic box product, and that appeared to have all the variations present, unless I overlooked one.

    For the submit validation errors - for a required select dropdown, FoxyShop assumes that the first option will be an empty "Please select an option" selection. As your dropdowns are just the different options - that means that it's assuming the first default option is that blank option.

    Two approaches you could take there. One would be to add a new line to the start of the select options for something like "Please select an option" or "Choose one" etc. The other would be to uncheck the "required" checkbox - as because you only have the available options in the dropdown, they will always be selecting one of those options anyway.
  • The first 7 variations on the Build your own Basics are missing-a description field and 6 "outfit type" checkboxes.

    For the validation errors-that makes perfect sense, thank you very much!
  • I figured out why the product variations weren't showing up. I had display keys marked in the display key fields when they didn't need them. It's all fixed and all working perfectly now. Thank you so much!!
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Glad you were able to get it working!

    One quick note - I see you're using individual checkbox variations for the multi-select fields. With how the forms work, with form inputs that have the same name, only the last instance of that will be sent. So if you had 6 checkboxes all with the same name, and the customer selects all 6, only the last checkbox will actually be sent with the form.

    To allow a customer to select multiple checkboxes that are all for the same option, you'll need to give each checkbox a unique name. So for example, if the checkbox was for "Type", you could call them "Type 1", "Type 2" etc. Or you could set the name of the checkbox variation to be the value, and the value to just be "Yes".

    For example, let's say you had three checkboxes like this:

    Variation Name: Type, Value: Shirt
    Variation Name: Type, Value: Jumper
    Variation Name: Type, Value: Hat

    You could change it to be like this:

    Variation Name: Shirt, Value: Yes
    Variation Name: Jumper, Value: Yes
    Variation Name: Hat, Value: Yes

    If the customer then selected the Shirt and Hat checkboxes, in their cart it would look like this:

    Shirt: Yes
    Hat: Yes
Sign In or Register to comment.