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 / 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 / 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 / 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.