• Hello,
    I have a question about this plugin. Suppose, I sell physical and digital both types of products on my WooCommerce website. I want to give a 10% commission on physical products and a 30% commission for digital goods. or different categories base different commission rates.

    Is it possible to set multiple commission rates for different categories?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hello there,

    Thanks for contacting us and we hope you’re doing well ??

    About your request, is necessary to apply a custom code in order to get your goal.

    if ( defined( 'YITH_WCAF' ) && ! function_exists( 'yith_wcaf_custom_affiliate_rate' ) ) {
     function yith_wcaf_custom_affiliate_rate( $rate, $affiliate, $product ) {
    
     if (isset($product) && $product instanceof WC_Product){
     $exceptions = array(
     36 => 20,
     39 => 50,
     );
    
     if('variation' == $product->get_type()) {
     $parent_id = $product->get_parent_id();
     $product = wc_get_product($parent_id);
     }
    
     $categories = $product->get_category_ids();
    
     foreach( $categories as $category ) {
    
     if ( isset( $exceptions[ $category ] ) ) {
     return $exceptions [$category];
     }
    
                }
            }
    
     return $rate;
     }
    
        add_filter( 'yith_wcaf_affiliate_rate', 'yith_wcaf_custom_affiliate_rate', 10, 3 );
    }

    You can put your rate by category, adding in variable $exceptions, category_id => rate, how many you want:

    $exceptions = array(
     category_id => rate,
     category_id => rate,
     );

    In the code I send you the following example:

    $exceptions = array(
     36 => 20,
     39 => 50,
     );

    In this way, the products with category id 36, will take a rate of 20% and category id 39, will take a rate of 50%.

    If a product has more than one category, it will take the rate of the first one.

    About to make a different commission rate for the same product but make a difference between digital and physical, you can check the product type and set two different $exeptions based on product type.

    We hope it helps you.

    Please, try it and let us know.

    Have a good day.

    Thread Starter Jalis Mahmud Nabil

    (@jmnabil)

    Thank you so much. It’s working successfully.

    I have another problem with this plugin.

    I am from Bangladesh and our country doesn’t support PayPal. I want to pay affiliates through other local methods. Therefore, I would like to take input a phone number instead of the payment email in the affiliate registration & payment field.

    Is there any provision to take a payment phone number input instead of the affiliate payment email?

    Thanks and Regards

    Plugin Author YITHEMES

    (@yithemes)

    Hello there,

    hope you are doing well! ??

    You can disable the payment email in the affiliate registration form adding this custom code in the functions.php of your active theme:

    add_filter( 'yith_wcaf_payment_email_required', '__return_false' );

    You can show the phone field, adding this custom code in the functions.php of your active theme:

    if( defined( 'YITH_WCAF' ) ){
     if( ! function_exists( 'yith_wcaf_add_custom_fields' ) ){
     function yith_wcaf_add_custom_fields(){
     $billing_phone = !empty($_POST['reg_billing_phone']) ? $_POST['yith_wcaf_bank_number'] : '' ;
    
     $fields = "<p class='form-row form-row-wide'>
                   <label for='reg_billing_phone'>Phone <span class='required'>*</span></label>
                   <input type='text' class='input-text' name='reg_billing_phone' id='reg_billing_phone' value='$billing_phone' required />
                   </p>
                   ";
     echo $fields;
     }
          add_action( 'yith_wcaf_register_form', 'yith_wcaf_add_custom_fields' );
     }
    
     if( ! function_exists( 'yith_wcaf_add_custom_fields_on_settings' ) ){
     function yith_wcaf_add_custom_fields_on_settings(){
     $user = get_current_user_id();
    
     if( $user ) {
    
     $reg_billing_phone =   get_user_meta( $user, 'billing_phone', true );
    
     $fields = "<p class='form-row form-row-wide'>
                   <label for='reg_billing_phone'>Phone:</label>
                   <input type='text' class='input-text' name='reg_billing_phone' id='reg_billing_phone' value='$reg_billing_phone' required />
                   </p>
                   ";
     echo $fields;
     }
          }
          add_action( 'yith_wcaf_settings_form_after_payment_email', 'yith_wcaf_add_custom_fields_on_settings' );
     }
    
     if (!function_exists('yith_wcaf_register_custom_field')) {
     function yith_wcaf_register_custom_field($id)
          {
     $affiliate = YITH_WCAF_Affiliate_Handler()::get_instance()->get_affiliate_by_id($id);
     if (isset($_REQUEST['reg_billing_phone'])) {
                update_user_meta($affiliate['user_id'], 'billing_phone', sanitize_text_field($_REQUEST['reg_billing_phone']));
     }
          }
    
          add_action('yith_wcaf_new_affiliate', 'yith_wcaf_register_custom_field');
     }
    
     if (!function_exists('yith_wcaf_register_custom_field_settings')) {
     function yith_wcaf_register_custom_field_settings($change, $id)
          {
    
     if (isset($_REQUEST['reg_billing_phone'])) {
                update_user_meta($id, 'billing_phone', sanitize_text_field($_REQUEST['reg_billing_phone']));
     }
          }
    
          add_action('yith_wcaf_save_affiliate_settings', 'yith_wcaf_register_custom_field_settings', 10, 2);
     }
    }

    Let us know.

    Have a great day!

    Thread Starter Jalis Mahmud Nabil

    (@jmnabil)

    Thank you very much.
    I am grateful to you. You have helped me a lot. Your codes have worked successfully.

    But it only worked at the front end.

    Whenever I open the YITH Affiliates list from my WordPress admin panel, there are not showing any payment option for those affiliates who registered with mobile numbers instead of payment email.

    you can see it Here

    there is only an account email. Payment phone numbers are not displayed.

    Payment: N/A

    I can’t find their affiliate payment number. How can I get their payment phone number from my WordPress admin panel?

    Thanks and regards

    Thread Starter Jalis Mahmud Nabil

    (@jmnabil)

    Can anyone help me?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Coustom Commission rate’ is closed to new replies.