Skip to content

Instantly share code, notes, and snippets.

remove_filter( 'woocommerce_default_address_fields', 'get_default_address_fields', 10, 1 );
add_filter( 'woocommerce_default_address_fields', 'updated_get_default_address_fields', 10, 1 );
function updated_get_default_address_fields() {
global $woocommerce;
$fields = array(
'first_name' => array(
'label' => __( 'First Name', 'woocommerce' ),
'required' => true,
'class' => array( 'form-row-first' ),
),
@ScottDeLuzio
ScottDeLuzio / UserForm
Created February 18, 2016 20:23
Software Licensing for Excel Add-In Populate UserForm
Private Sub userform_initialize()
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
license.Value = .Cells(1, 1).Value
Label2.Caption = "Your license key is " & .Cells(3, 1).Value & " and has " & .Cells(4, 1).Value & " activations remaining."
End With
End Sub
@ScottDeLuzio
ScottDeLuzio / Module1
Created February 18, 2016 20:28
Software Licensing API URL
http://YOURSITE.com/?edd_action={request type}&item_name=EDD+Product+Name&license=cc22c1ec86304b36883440e2e84cddff
@ScottDeLuzio
ScottDeLuzio / Module1
Created February 18, 2016 20:47
Software Licensing for Excel Add-In Check License Status
'json response from Software Licensing in the following format
'{"success":true,"license":"valid","item_name":"Download Product Name","expires":"lifetime","payment_id":"54224","customer_name":"John Doe","customer_email":"[email protected]","license_limit":1,"site_count":1,"activations_left":0}
Sub httpRequestCheck()
'use to check license once when workbook opens
Dim oRequest As Object
Const cUrl As String = "https://yoursite.com/?edd_action=check_license&item_name=Name of the Download Product&license="
URL = cUrl & ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
@ScottDeLuzio
ScottDeLuzio / Module1
Last active February 18, 2016 21:15
Software Licensing for Excel Add-In Activate License
Sub httpRequestActivate()
'Run the httpRequestCheck to see if the license has used up all of the activations it had available.
'If it has we add in_use to cell A5 so that we can avoid allowing the license to be activated on more computers than our license allows.
'Note after the first activation, the license will return as valid before the end of the license expiration even if it has been deactivated so we need to check for remaining activations this way as well.
httpRequestCheck
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
If .Cells(4, 1).Value = 0 Then
'Cells(4, 1).Value is the number of activations remaining. In my case there will only be 1 or 0 but even if you allow more than one activation, 0 is where we should stop allowing it to be activated.
'This indicates that the license is in use on as many computers as the license will allow. We will check for this later.
.Cells(5, 1).Value = "in_use"
@ScottDeLuzio
ScottDeLuzio / Module1
Created February 18, 2016 20:59
Software Licensing for Excel Add-In Deactivate License
Sub httpRequestDeactivate()
'Use to deactivate license. Mostly the same as httpRequestActivate but without the check for if the max number of activations has been reached.
Dim oRequest As Object
Const cUrl As String = "https://yoursite.com/?edd_action=deactivate_license&item_name=Name of the Download Product&license="
URL = cUrl & ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", URL
oRequest.Send
@ScottDeLuzio
ScottDeLuzio / Module1
Created February 18, 2016 21:04
Software Licensing for Excel Add-In Workbook Activation/Open
Sub Activate_License()
'Show the license key activation UserForm (mine is creatively named LicenseKey)
LicenseKey.Show
End Sub
@ScottDeLuzio
ScottDeLuzio / ThisWorkbook
Created February 18, 2016 21:12
Software Licensing for Excel Add-In Check License on Startup
Private Sub Workbook_Open()
httpRequestCheck
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
' the And .Cells(4, 1) = 0 is probably redundant, and if you are allowing more than one activation per license key you should remove that part.
If .Cells(3, 1).Value = "valid" And .Cells(4, 1) = 0 And .Cells(5, 1) <> "in_use" Then
'call your add-in here
Else
'if the license is not valid, the number of activations remaining is greater than 0, and it is not in use elsewhere we should display the license activation UserForm.
Activate_License
End If
@ScottDeLuzio
ScottDeLuzio / UserForm
Created February 18, 2016 22:33
Software Licensing for Excel Add-In UserForm Activate
Private Sub LicenseKeyActivate_Click()
'license.Value is what the user entered into the text box on the UserForm.
If license.Value = "" Then
MsgBox "Please enter a license key.", vbExclamation, "Input Data"
Exit Sub
Else
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
.Cells(1, 1).Value = license.Value
@ScottDeLuzio
ScottDeLuzio / UserForm
Created February 18, 2016 22:35
Software Licensing for Excel Add-In UserForm Deactivate
Private Sub LicenseKeyDeactivate_Click()
If license.Value = "" Then
MsgBox "Please enter a license key.", vbExclamation, "Input Data"
Exit Sub
Else
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
.Cells(1, 1).Value = license.Value