Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards!

Share Coupon Discount

WCMp Core

Resolved
Viewing 21 reply threads
  • Author
    Posts
    • #128710
      MaxenceTP
      Participant

      Hello,

      I don’t quite understand how the “Share Coupon Discount” option works: https://prnt.sc/1v1nr37
      I would like the coupon to be fully charged to the seller and the admin commission to remain unchanged. Here is an example to be clearer:
      The product is at 10€; the seller earns 75% per sale

      In normal time he would earn 7,5€ per sale
      If I subtract a 2€ discount, I would like the seller to earn (7,5 – 2) = 5,5€ for the sale.

      How can I do this?

    • #128761

      Hi, thank you for getting in touch with us.
      Kindly note that whenever you are creating a coupon and enabling the option of Share Coupon Discount, vendor’s commission will get calculated deducting the coupon’s price.
      For example, if a product price is 500$,coupon discount is 20% and vendor’s commission is 75%.
      It means after applying the coupon the amount will get deducted i.e, 500$ – 20% =400$
      Vendor’s commission will be calculated on 400$, i.e, 75% of 400$= 300$
      Note that this commission is calculated including coupon discount.

      However if you do not enable “Share Coupon Discount”, then vendor will get the commission on the actual price of the product, ,i.e, vendor will receive 75% of 500$ = 375
      Note that this commission is calculated excluding the coupon discount.

    • #128769
      MaxenceTP
      Participant

      Yes, that’s what I understood during my tests.
      How can I make it so that the vendor handles all the discount? Like the example I gave above

    • #128802

      Hi,
      I understand your requirement that you want coupon amount to be deducted from vendor’s commission.
      The default flow of the plugin does not support this, since other marketplace do not follow this rule of calculating coupon amount.
      However if you wish you can do custom code to modify the admin’s commision on coupon amount.
      If you have any hook filter do let us know.

    • #128825
      MaxenceTP
      Participant

      If you can help me with that, it would be really nice 🙂

    • #128936

      We would love to help you out @MaxenceTP. Generally, as you know, our team does give code snippets, but if that requires a small amount of coding.

      Now the flow you are looking for requires a good amount of codes. So If you have any developer, ask them to contact us so we can help you out with the coding procedure.
      Alternatively, you may hire our service team (https://multivendorx.com/custom-development/) so they can add this feature in your site.

    • #128941
      MaxenceTP
      Participant

      Can you tell me which files and/or functions I need to change?

    • #129023

      Hi, our team will look into this, kindly provide them some time.

      p.s. Our office is closed due to holidays (12th to 17th Oct). Hence, the response might get delayed.

    • #129044
      MaxenceTP
      Participant

      Ok I’m waiting for your answer 🙂

    • #129168

      Hi,
      As per your requirement you have to add custom doe using below filter

      apply_filters('wcmp_get_commission_line_total', $line_total, $product_id, $variation_id, $item, $order_id, $item_id);
      Copy

      Regards,

    • #129253
      MaxenceTP
      Participant

      I made some modifications in the class-wcmp-calculate-commission.php that seem to be correct: https://prnt.sc/1wpwo3h

      However how can I integrate this into the apply_filters so I don’t directly modify the plugin files? Or else can you make an update to WCMP to add this functionality in a setting?

    • #129350

      Hi,
      other marketplace do not follow this rule of calculating coupon amount. So you have to add code using filter and hooks kindly use below filter to override and change the code

      apply_filters('wcmp_get_commission_line_total', $line_total, $product_id, $variation_id, $item, $order_id, $item_id);
      Copy

      and

      apply_filters('vendor_commission_amount', $amount, $product_id, $variation_id, $item, $order_id, $item_id);
      Copy

      Regards,

    • #129252
      MaxenceTP
      Participant

      I made some modifications in the class-wcmp-calculate-commission.php that seem to be correct: https://prnt.sc/1wpwo3h

      However how can I integrate this into the apply_filters so I don’t directly modify the plugin files? Or else can you make an update to WCMP to add this functionality in a setting?

      Here is my code: https://pastebin.com/Yf2mAvSb

    • #129241
      MaxenceTP
      Participant

      I made some modifications in the class-wcmp-calculate-commission.php that seem to be correct: https://prnt.sc/1wpwo3h

      However how can I integrate this into the apply_filters so I don’t directly modify the plugin files? Or else can you make an update to WCMP to add this functionality in a setting?

      Here is my code: https://pastebin.com/Yf2mAvSb

    • #129441
      MaxenceTP
      Participant

      Wow, why did my answers get duplicated :d

      I don’t see how to do this with only filters. For example on my screenshot I modify line 547, how could I do that?
      Or else can I overwrite the whole get_item_commission function in my theme? And if yes, how?

      Sorry for the inconvenience, and thanks in advance for the help

    • #129467

      Hi,
      You can’t override the whole function or not override our core file.
      You have to use above filter.
      Kindly hire a developer for this custom work.

      Regards,

    • #129470
      MaxenceTP
      Participant

      Well what I did works, the only problem is that I have to re-modify the file at each update since I can’t do that in my child-theme.
      I don’t see how another developer would be useful.

      How do you think you can do with the filter? I don’t see how to get the right result by modifying the code only in this place.
      Can you give me an example in a few words? Or in a few lines?

    • #129539

      can you provide us with the coding overview

    • #129568
      MaxenceTP
      Participant

      As I said, here is what I would like to change in the code : https://prnt.sc/1wpwo3h
      And this is the code of the screenshot : https://pastebin.com/Yf2mAvSb

    • #129659

      Hi,
      Please add this code in the function.php of the current active theme and test:

      add_filter('vendor_commission_amount', 'wcmp_vendor_commission_amount_modification', 99, 6);
      function wcmp_vendor_commission_amount_modification( $amount, $product_id, $variation_id, $item, $order_id, $item_id) {
          global $WCMp;
          $order = wc_get_order($order_id);
          $amount = 0;
          $commission = array();
          $commission_rule = array();
          $product_value_total = 0;
          // Check order coupon created by vendor or not
          $order_counpon_author_is_vendor = false;
          if ($order->get_coupon_codes()) {
              foreach( $order->get_coupon_codes() as $coupon_code ) {
                  $coupon = new WC_Coupon($coupon_code);
                  $order_counpon_author_is_vendor = $coupon && is_user_wcmp_vendor( get_post_field ( 'post_author', $coupon->get_id() ) ) ? true : false;
              }
          }
      
          $line_discount = 0;
          if (isset($WCMp->vendor_caps->payment_cap['commission_include_coupon'])) {
              //$line_total = $order->get_item_total($item, false, false) * $item['qty'];
              $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
              $line_discount = ($order->get_item_subtotal($item, false, false) - $order->get_item_total($item, false, false)) * $item['qty'];
      
              /*if (isset($WCMp->vendor_caps->payment_cap['admin_coupon_excluded']) && !$order_counpon_author_is_vendor) {
                  $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
              }*/
          } else {
              $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
          }
      
          // Filter the item total before calculating item commission.
          $line_total = apply_filters('wcmp_get_commission_line_total', $line_total, $product_id, $variation_id, $item, $order_id, $item_id);
      
          if ($product_id) {
              $vendor_id = wc_get_order_item_meta($item_id, '_vendor_id', true);
              if ($vendor_id) {
                  $vendor = get_wcmp_vendor($vendor_id);
              } else {
                  $vendor = get_wcmp_product_vendors($product_id);
              }
              if ($vendor) {
                  $commission = $WCMp->commission->get_commission_amount($product_id, $vendor->term_id, $variation_id, $item_id, $order);
                  $commission = apply_filters('wcmp_get_commission_amount', $commission, $product_id, $vendor->term_id, $variation_id, $item_id, $order);
                  if (!empty($commission)) {
                      if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage') {
                          $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 ) + (float) $commission['commission_fixed'];
                      } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage_qty') {
                          $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 ) + ((float) $commission['commission_fixed'] * $item['qty']);
                      } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'percent') {
                          $amount = (float) $line_total * ( (float) $commission['commission_val'] / 100 );
                      } else if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed') {
                          $amount = (float) $commission['commission_val'] * $item['qty'];
                      } elseif ($WCMp->vendor_caps->payment_cap['commission_type'] == 'commission_by_product_price') {
                          $amount = $WCMp->commission->wcmp_get_commission_as_per_product_price($product_id, $line_total, $item['qty'], $commission_rule);
                      } elseif ($WCMp->vendor_caps->payment_cap['commission_type'] == 'commission_by_purchase_quantity') {
                          $amount = $WCMp->commission->wcmp_get_commission_rule_by_quantity_rule($product_id, $line_total, $item['qty'], $commission_rule);
                      }
                      if (isset($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'])) {
                          if ($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'] == 'admin') {
                              $amount = (float) $line_total - (float) $amount - (float) $line_discount;
                              if ($amount < 0) {
                                  $amount = 0;
                              }
                          }
                      }
                      if ($variation_id == 0 || $variation_id == '') {
                          $product_id_for_value = $product_id;
                      } else {
                          $product_id_for_value = $variation_id;
                      }
      
                      $product_value_total += $item->get_total();
                      if ( apply_filters('wcmp_admin_pay_commission_more_than_order_amount', true) && $amount > $product_value_total) {
                          $amount = $product_value_total;
                      }
                      return $amount;
                  }
              }
          }
          return $amount;
      }
      Copy

      Regards,

    • #129675
      MaxenceTP
      Participant

      Thank you! The overwrite works 🙂
      This is solved

    • #129681

      I hope you are satisfied with our assistance and plugin. A 5/5 review here- https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/reviews/#new-post , would be a great way to share your experience with others.

      This motivates us to continue providing the best experience possible and also helps others know how WC-Marketplace can make their life easier.

Viewing 21 reply threads

The topic ‘Share Coupon Discount’ is closed to new replies.