We use WooCommerce Subscriptions to setup payment plans for our products. Deposits was our first choice but it only sent “Invoices” for future payments and did not auto charge the credit card used at initial purchase. Not ok as our products are very expensive and people tended to ignore those invoices.
We also need to limit these purchase to one per customer. Easier said than done. I found a WooCommerce extension that would do the trick but we already pay so much a year for extensions we need I try to avoid that for simple functionality.
This won’t work for my needs. The option on a subscription product only limits users from having multiple subscriptions to that particular product. We only want one subscript for ANY product.
My solution works for one shopping cart session. I’m working on preventing others which shouldn’t be too hard by just checking the database at checkout time for active subscriptions to that user.
The Hook & Function
I went with woocommerce_add_to_cart_validation after going through quite a few other hooks and filters. The hardest thing about finding a solution is finding what all hooks and filters are available. Takes some serious google-fu to find the right one quickly.
This filter allows you to run a function before an item is validated and sent to the cart. We tell our add_filter that we need two of the parameters so we can get the product id as well as the validity of the admission. This is done with the 4th parameter we set to “2.”
Detect Variations Too
If you are using variable Subscriptions you will need to plan ahead that some items in the cart may be variations. These have a separate class. We must first detect if the product being added is an instance of WC_Product_Subscription which is a “Simple Subscription” in WooCommerce. Or is an instance of WC_Product_Variable_Subscription which is like it says a version of a subscription product with variations.
The odd part that caught me off guard is when we are checking items already in the cart. We check for WC_Product_Subscription like normal but once in the cart the product is of the WC_Product_Subscription_Variation class meaning it’s just a variation of a product and not the full product variable class.
Say you have an image of a face in your app. There are multiple quadrants you want a user to be able to select. When they select, it should highlight that area. You want the user to have the ability to select any combination of these quadrants.
Stacking Images In AbsoluteLayout
Let’s go over the xml layout first. I accomplished this task using an AbsoluteLayout with four Image views inside it like so.
Notice I set the width to 100% but not height. In my full code the height is set in a GridLayout for row 3, but you can set height to 100% or a pixel amount.
I placed a plain face photo as the background for the AbsoluteLayout. Then I have four images for different quadrants of the face. These have their absolute position set to 0px top and 0px left. My overlaying images are the exact same size as the background image of my AbsoluteLayout so I want them to fit exactly over top.
When the page is loaded I set my initial variables in pageData then turn that Observable into the binding data for the page. So initially all images will be collapsed (turned off).
Next I set gesture detection to my AbsoluteLayout that has been given the id “main-layout” and attached to the variable “quad.” I measure where the touch took place then if it’s in an images quadrant it toggles the collapsed/visible state. The images are all positioned absolutely so they layer on top of each other.
My wife took this pic and I love it so figured I’d share!
Here’s my first affiliate linking post thingy ever. I want you to sign up for hosting with SiteGround and I want you to do it through my link so I get some referral money: https://www.siteground.com/index.htm?afcode=29a69d074161ca9f9de2a9796e5229a8
Now, let me tell you why I love these guys.
SSL Through Let’s Encrypt
I found out while poking around in my admin that I can install a FREE Let’s Encrypt SSL certificate with a click of a button. Go to cPanel, scroll down to the Security section and hit the Let’s Encrypt icon. Fuck yea.
SiteGround is setup to work great with WordPress. It has easy installs and is configured perfectly with all correct file permissions and so on. I had five sites on my own linode.com server slice and they were constantly getting hacked. I moved them over even with some shitty hacked up themes & plugins on a couple of them. Haven’t been hacked a single time.
I had one issue with support that wasn’t very pleasant. But when I replied with my frustration it was escalated to a higher support person and handled immediately and gracefully.
I have five accounts with SiteGround for various clients and myself. My primary job’s website had a huge surge in traffic. Expanding memory temporarily was an easy click, done.
Beyond all these perks, the sites are fast and always up. I’ve had 0 down time. I can’t say enough about finally finding a host I’m going to stick with for everything.
BUY SITEGROUND HOSTING THROUGH MY AFFILIATE LINK 🙂
Once WooCommerce sends an invoice there’s no real way to send out mass invoice reminders unless you do them one at a time. I needed something better than that.
Woo Deposits & Follow Up Emails
My company needed a way to have people pay for our more expensive products over four months. I saw Woo Deposits had a payment plan capability so we bought it, installed it and I setup the plans. I screwed up though.
It’s not clear unless you carefully read through the whole plugin description/FAQ that it invoices for each payment and does not do recurring charges. I should have noticed this and made sure but I didn’t.
Well, we realized a couple months after turning on and we had around 50 unpaid invoices. I installed Follow Up Emails and sadly it doesn’t have a way to invoice pending payments.
Some Code To Send Reminders
So here’s a function you can run to resend the invoice to anyone who is pending payment. I have the timestamp set to send 7 days after missed payment.
You won’t want to run this all the time so maybe set to a cron job every 7 days or so.
Since the css linear-gradient isn’t part of NativeScript core yet I went looking for the ability to do this online. I found a git conversation over at https://github.com/NativeScript/NativeScript/issues/539 that discussed and shared some code.
The code doesn’t work on iOS as expected. There were some typos in the code that need to be adjusted and wrong variables. I’ve made those adjustments and you can copy below a functioning version.
var gradients = require("~/grad-bg.js");
Import the function via the require method. Then in your page loaded function call the function on your view. Make sure to set the view’s id in your xml file and use that id here as the second parameter: