Skip to content

Instantly share code, notes, and snippets.

@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
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: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":"john@sample.com","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
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 / 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
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 / functions.php
Created August 14, 2015 23:24
WooCommerce checkout field hook and change default fields
<?php
// WooCommerce Checkout Fields Hook
add_filter( 'woocommerce_checkout_fields' , 'custom_wc_checkout_fields' );
// Change order comments placeholder and label, and set billing phone number to not required.
function custom_wc_checkout_fields( $fields ) {
$fields['order']['order_comments']['placeholder'] = 'Enter your placeholder text here.';
$fields['order']['order_comments']['label'] = 'Enter your label here.';
$fields['billing']['billing_phone']['required'] = false;
return $fields;
@ScottDeLuzio
ScottDeLuzio / functions.php
Created August 14, 2015 23:21
Add custom field to order emails
<?php
/**
* Add the field to order emails
**/
add_filter( 'woocommerce_email_order_meta_keys', 'some_order_meta_keys' );
function some_order_meta_keys() {
if (get_post_meta( get_the_ID(), 'Some Field')) {
echo 'This is the custom information you entered in Some Field: ' . get_post_meta( get_the_ID(), 'Some Field', true) . '<br />';
}
@ScottDeLuzio
ScottDeLuzio / functions.php
Created August 14, 2015 23:20
Update order meta with custom field value
<?php
/**
* Update the order meta with field value
*/
add_action( 'woocommerce_checkout_update_order_meta', 'some_custom_checkout_field_update_order_meta' );
function some_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['some_field_name'] ) ) {
update_post_meta( $order_id, 'Some Field', sanitize_text_field( $_POST['some_field_name'] ) );
}
@ScottDeLuzio
ScottDeLuzio / functions.php
Created August 14, 2015 23:19
Process custom field in checkout
<?php
/**
* Process the checkout
*/
add_action('woocommerce_checkout_process', 'some_custom_checkout_field_process');
function some_custom_checkout_field_process() {
// Check if the field is set, if not then show an error message.
if ( ! $_POST['some_field_name'] )
wc_add_notice( __( 'Please enter something here.' ), 'error' );