• Resolved dnay76

    (@dnay76)


    Good morning,

    We have our commissions set up to be tiered based on the product category. That way we can, for example, have different commission levels based on physical vs digital products.

    However, we have come upon a situation where we need to give a custom commission rate to one specific affiliate. However, if we set a custom commission rate on the affiliate then it overrides all of the product category based commission rates.

    Is there a way to set a custom commission rate for a specific affiliate or affiliate group by product category?

    Either from the UI configuration or coded in functions.php is fine with me.

    Thank you in advance!

    Darren Nay

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author iova.mihai

    (@iovamihai)

    Hey @dnay76,

    Thank you for reaching out! We currently don’t have this particular feature, so from the UI there’s no way of adding the functionality you’re looking for.

    As for a code snippet, we don’t have this in our collection. Even so, I’d like to see if there’s an easy way to do this via a code snippet.

    Please let me know which eCommerce plugin you’re using (WooCommerce, etc), and based on this I can check if something can be done.

    Thank you and best wishes,

    Mihai

    Thread Starter dnay76

    (@dnay76)

    Thank you for your quick response! Yes, we are using WooCommerce version 8.9.3

    Let me know if there is any other information that you need.

    Darren Nay

    Plugin Author iova.mihai

    (@iovamihai)

    Hey @dnay76,

    Thank you for the confirmation! I’ve been able to put together a code snippet based on the code we already have in the plugin. Here it is:

    function slicewp_custom_calculate_commissions_per_category_per_affiliate( $commission_amount, $amount, $args ) {

    // The ID of the affiliate that has custom rates per category.
    $affiliate_id = 21;

    // The category IDs separated by comma for digital and physical products.
    $product_categories_digital = array( 123, 124 );
    $product_categories_physical = array( 125, 126 );

    // The commission rates for category types.
    $category_commission_rate_type_digital = 'percentage';
    $category_commission_rate_digital = 20;

    $category_commission_rate_type_physical = 'percentage';
    $category_commission_rate_physical = 20;

    // Check that the commission is from WooCommerce
    if ( $args['origin'] != 'woo' ) {
    return $commission_amount;
    }

    // Only sales and subscriptions are treated here
    if ( ! in_array( $args['type'], array( 'sale', 'subscription') ) ) {
    return $commission_amount;
    }

    // Check if the commission rate is per order
    if ( slicewp_is_commission_basis_per_order() ) {
    return $commission_amount;
    }

    if ( empty( $args['affiliate_id'] ) || $args['affiliate_id'] != $affiliate_id ) {
    return $commission_amount;
    }

    // Get the product
    $product_id = absint( $args['product_id'] );
    $product = wc_get_product( $product_id );

    // Get the product categories
    $categories = get_the_terms( $product_id, 'product_cat' );

    if ( ! empty( $categories[0]->term_id ) ) {

    $category_commission_rate_type = '';
    $category_commission_rate = '';

    // Get the product category commission type and rate
    if ( in_array( $categories[0]->term_id, $product_categories_digital ) ) {

    $category_commission_rate_type = $category_commission_rate_type_digital;
    $category_commission_rate = $category_commission_rate_digital;

    }

    if ( in_array( $categories[0]->term_id, $product_categories_physical ) ) {

    $category_commission_rate_type = $category_commission_rate_type_physical;
    $category_commission_rate = $category_commission_rate_physical;

    }

    // Check if the product category commission type and rate are ok
    if ( ! empty( $category_commission_rate_type ) && ! empty( $category_commission_rate ) && is_numeric( $category_commission_rate ) ) {

    // Calculate the commission using the product type and rate
    $commission_amount = ( $category_commission_rate_type == 'percentage' ? round( ( $amount * $category_commission_rate / 100 ), 2 ) : $category_commission_rate );

    return $commission_amount;

    }

    }

    return $commission_amount;

    }
    add_filter( 'slicewp_calculate_commission_amount', 'slicewp_custom_calculate_commissions_per_category_per_affiliate', 20, 3 );

    Please make sure to modify the $affiliate_id variable and set it to the ID of the affiliate you want to have custom rates per product category.

    Then, set the $product_categories_digital and $product_categories_physical variables as the IDs of the product categories in each category type.

    Lastly, set the $category_commission_rate_type_digital, $category_commission_rate_digital, $category_commission_rate_type_physical, $category_commission_rate_physical variables to the rates you wish to reward. The “rate_type” variables accept either “fixed_amount” or “percentage”. The other two accept positive integers. 1 to 100 for the “percentage” type, any other value for “fixed_amount”.

    Please add the code to your website, give it a test and let me know how it goes.

    Thank you and best wishes,

    Mihai

    Thread Starter dnay76

    (@dnay76)

    This is great! Thank you so much for your help!!

    Plugin Author iova.mihai

    (@iovamihai)

    Hey @dnay76,

    Happy I could help you out!

    Wishing you all the best!

    Mihai

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.