Creating Commissions based on Products
-
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)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Creating Commissions based on Products’ is closed to new replies.