• Resolved elaaf

    (@elaaf)


    Good Afternoon,

    I am trying to setup different commissions based on product types for specific products. The default commission is 5%. I have 3 products that I want to set commissions for differently with a rate for each as per the following:

    • Product ID: 4537. commission 50%
    • Product ID: 4540, commission 20%
    • Product ID: 4542, commission 35%

    Here is the code that I have added to my functions.php in the child theme. The site is still using the default commission rate.

    <?php
    add_filter( 'yith_wcaf_commission_rate', 'custom_yith_wcaf_commission_rate', 99, 3 );
    
    function custom_yith_wcaf_commission_rate( $rate, $affiliate_id, $context ) {
        // Get the global WC Cart
        global $woocommerce;
        
        // Iterate through each cart item
        foreach($woocommerce->cart->cart_contents as $cart_item_key => $cart_item) {
            
            // Get the product ID
            $product_id = $cart_item['product_id'];
            
            // Set the commission rate based on the product ID
            switch($product_id) {
                case 4537:
                    $rate = 50; // 50% commission
                    break;
                case 4540:
                    $rate = 20; // 20% commission
                    break;
                case 4542:
                    $rate = 35; // 35% commission
                    break;
            }
        }
        
        // Return the commission rate
        return $rate;
    }
    ?>

    What could be the issue?

    Regards,

    Aziz

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello Aziz,
    we hope you’re doing well!

    The correct filter to use is yith_wcaf_affiliate_rate.

    Try it and tell us about any news, please.

    Best regards.

    Thread Starter elaaf

    (@elaaf)

    Hi Juan,

    I have replaced the hook as advised but the default commission is still being used.

    Regards,

    Aziz

    Thread Starter elaaf

    (@elaaf)

    Hi,

    I am sosrry, just verified it again and it is working fine. Thank you so much.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Creating Commissions based on Products’ is closed to new replies.