Skip to content

Instantly share code, notes, and snippets.

View mholubowski's full-sized avatar

Mike Holubowski mholubowski

  • PLY Technologies
  • California
View GitHub Profile
@mholubowski
mholubowski / solid_affiliate_custom_commission_calculator.php
Last active February 18, 2024 19:34
solid_affiliate_custom_commission_calculator
/**
*
* Goal of this custom snippet:
*
* Override all commission calculations with a fixed value.
* The value should be the value of \SolidAffiliate\Lib\Settings::KEY_REFERRAL_RATE
* Ensure that only affiliate referred orders receive a commission.
* Make sure to catch any errors
*
* Add a note to the Settings > General page to inform the user of this change.
@mholubowski
mholubowski / snippet.php
Last active February 9, 2024 19:17
Solid Affiliate - Commission Cap
/**
* Applies a maximum cap to the commission amount.
*
* @param float $total The calculated total commission for the order.
* @param \SolidAffiliate\Models\Affiliate $affiliate The affiliate object for whom the commission is calculated.
* @param \SolidAffiliate\Lib\VO\OrderDescription $order_description The order description object containing details about the order.
* @return float The possibly adjusted commission total, ensuring it does not exceed the maximum cap.
*/
function set_max_commission_cap(float $total, \SolidAffiliate\Models\Affiliate $affiliate, \SolidAffiliate\Lib\VO\OrderDescription $order_description): float {
// Set the maximum commission amount
@mholubowski
mholubowski / snippet.php
Created December 21, 2022 19:13
Solid Affiliate - James CodeWP
<?php
// James wants to limit recurring referrals to 1 or 6 periods depending on the product.
// 'solid_affiliate/should_skip_referral_creation_for_order' is the filter to use.
// The filter is passed a tuple [bool, string[]] where the bool is whether or not to skip the referral creation and the string[] is the reasons why.
// The filter is also passed the OrderDescription object. Using the OrderDescriptions, we need to determine whether or not the order is a recurring order, and if so, how many months it is recurring for.
add_filter(
'solid_affiliate/should_skip_referral_creation_for_order',
/**
* @param array{0: bool, 1: string[]} $tuple
* @param OrderDescription $order_description
@mholubowski
mholubowski / psalm.xml
Created August 30, 2022 23:56
Solid Affiliate's psalm.xml
<?xml version="1.0"?>
<!-- See https://psalm.dev/docs/running_psalm/configuration/#projectfiles -->
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
phpVersion="5.6.20"
errorLevel="1"
resolveFromConfigFile="true"
@mholubowski
mholubowski / solid-affiliate-snippet-get_user_id_of_affiliate_who_referred_the_current_visitor.php
Last active March 22, 2022 10:06
solid-affiliate-snippet-get_user_id_of_affiliate_who_referred_the_current_visitor.php
<?php
/**
* This function will attempt to find the Affiliate who referred the current visitor,
* and then return the user id of that affiliate.
*
* Example:
* $id = get_user_id_sld (); defaults user id to "1"
* $id = get_user_id_sld ( 2 ); defaults user id to "2"
*
* @param integer $user_id_to_return_if_no_affiliate_found
@mholubowski
mholubowski / delete-old-visits.php
Created February 26, 2022 05:45
Solid Affiliate Delete Old Visits
$ids = \SolidAffiliate\Models\Visit::select_ids([
'referral_id' => 0,
'created_at' => [
'operator' => '<',
'value' => \SolidAffiliate\Lib\Utils::date_picker_time('-30 days')
]
]);
foreach ($ids as $id) {
\SolidAffiliate\Models\Visit::delete($id, false);
@mholubowski
mholubowski / solid-affiliate-snippet-cookies-1.php
Created January 11, 2022 20:32
Snippet which will make Solid Affiliate (v1.0.20) change it's cookie days based on the affiliate
add_filter(
'solid_affiliate/settings/get',
function ($val, $key) {
$id_of_affiliate_which_should_have_1_day_cookie = 1;
if ($key === \SolidAffiliate\Lib\Settings::KEY_COOKIE_EXPIRATION_DAYS) {
$maybe_affiliate = \SolidAffiliate\Lib\VisitTracking::_affiliate_from_request($_REQUEST);
if ($maybe_affiliate && ($maybe_affiliate->id === $id_of_affiliate_which_should_have_1_day_cookie)) {
return 1;
@mholubowski
mholubowski / emails-4.html
Created December 10, 2021 06:44
Solid Affiliate Email (Affiliate - Referral Notification)
<table id="bodyTable" style="border-collapse: collapse; height: 100%; margin: 0; padding: 0; width: 100%; background-color: #fafbff;" border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td id="bodyCell" style="height: 100%; margin: 0; padding: 60px 0; width: 100%;" align="center" valign="top">
<table style="width: 600px;" border="0" width="600" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="width: 600px;" align="center" valign="top" width="600">
<table class="templateContainer" style="border-collapse: collapse; border: 1px solid #d9e1ec; max-width: 600px !important;" border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
@mholubowski
mholubowski / emails-3.html
Created December 10, 2021 06:43
Solid Affiliate Email (Affiliate - Application Accepted)
<table id="bodyTable" style="border-collapse: collapse; height: 100%; margin: 0; padding: 0; width: 100%; background-color: #fafbff;" border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td id="bodyCell" style="height: 100%; margin: 0; padding: 60px 0; width: 100%;" align="center" valign="top">
<table style="width: 600px;" border="0" width="600" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="width: 600px;" align="center" valign="top" width="600">
<table class="templateContainer" style="border-collapse: collapse; border: 1px solid #d9e1ec; max-width: 600px !important;" border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
@mholubowski
mholubowski / emails-2.html
Created December 10, 2021 06:42
Solid Affiliate Email (Affiliate Manager - Referral Notification)
<table id="bodyTable" style="border-collapse: collapse; height: 100%; margin: 0; padding: 0; width: 100%; background-color: #fafbff;" border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td id="bodyCell" style="height: 100%; margin: 0; padding: 60px 0; width: 100%;" align="center" valign="top">
<table style="width: 600px;" border="0" width="600" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="width: 600px;" align="center" valign="top" width="600">
<table class="templateContainer" style="border-collapse: collapse; border: 1px solid #d9e1ec; max-width: 600px !important;" border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>