Title: Custom Function Question
Last modified: November 27, 2023

---

# Custom Function Question

 *  [tommmoe](https://wordpress.org/support/users/tommmoe/)
 * (@tommmoe)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/custom-function-question/)
 * 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.
 *     ```wp-block-code
       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](https://wordpress.org/support/users/pperez001/)
 * (@pperez001)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/custom-function-question/#post-17242142)
 * 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:
 *     ```wp-block-code
       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.

 * ![](https://ps.w.org/yith-woocommerce-affiliates/assets/icon.svg?rev=3053144)
 * [YITH WooCommerce Affiliates](https://wordpress.org/plugins/yith-woocommerce-affiliates/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yith-woocommerce-affiliates/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yith-woocommerce-affiliates/)
 * [Active Topics](https://wordpress.org/support/plugin/yith-woocommerce-affiliates/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yith-woocommerce-affiliates/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yith-woocommerce-affiliates/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Pablo Pérez](https://wordpress.org/support/users/pperez001/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/custom-function-question/#post-17242142)
 * Status: not resolved