• Hi,

    Just wondering if this custom function I put together will work? I’m trying to set the minimum payout of a tracked affiliate purchase to be $1 if the 10% rate is lower than that.

    if ( defined( 'YITH_WCAF' ) && ! function_exists( 'yith_wcaf_custom_affiliate_rate' ) ) {
        function yith_wcaf_custom_affiliate_rate( $rate, $affiliate, $product ) {
            // Check if the product is a valid instance of WC_Product
            if ( isset( $product ) && $product instanceof WC_Product ) {
                // Calculate the commission based on the product price
                $commission = $product->get_price() * $rate;
    
                // If the calculated commission is less than $1, disable percentage rate and set it to $1
                if ( $commission < 1 ) {
                    add_filter( 'yith_wcaf_use_percentage_rates', '__return_false' );
                    return 1;
                }
            }
    
            // If no specific conditions are met, return the original rate
            return $rate;
        }
    
        add_filter( 'yith_wcaf_affiliate_rate', 'yith_wcaf_custom_affiliate_rate', 10, 3 );
    }
    
Viewing 1 replies (of 1 total)
  • Plugin Support Pablo Pérez

    (@pperez001)

    Hi there,

    The hook you are currently using modifies the rate that will be use to calculate the commission. If you are looking to set a minimum commission you can use the hook “yith_wcaf_line_item_commission“. Here you have an example of setting the minimum amount to all comissions:

    add_filter('yith_wcaf_line_item_commission', 'yith_wcaf_set_min_commisions', 10, 5);
    
    function yith_wcaf_set_min_commisions($amount, $order, $line_item_id, $line_item, $rate){
    	if(1 > $amount){
    		$amount = 1;
    	}
    
    	return $amount;
    }

    In the hook you can retrieve the product and rate above other important data, which you can use to set your conditions.

    I hope this is what you were looking for.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Function Question’ is closed to new replies.