Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wcfmmp_order_item_commission', function( $item_commission, $vendor_id, $product_id, $variation_id, $item_price, $quantity, $commission_rule, $order_id ) {
- if( isset( $commission_rule['mode'] ) && $commission_rule['mode'] == 'fixed' ) {
- $order = wc_get_order($order_id);
- $items = $order->get_items( 'line_item' );
- $item_total = 0;
- $item_subtotal = 0;
- if( !empty( $items ) ) {
- foreach( $items as $item_id => $item ) {
- $line_item = new WC_Order_Item_Product( $item );
- $item_product_id = $line_item->get_product_id();
- $item_variation_id = $line_item->get_variation_id();
- if( $item_variation_id && $item_variation_id != $variation_id || $item_product_id != $product_id ) continue;
- $item_line_item = $line_item;
- $item_total = $item_line_item->get_total();
- $item_subtotal = $item_line_item->get_subtotal();
- if($item_total == $item_subtotal) {
- return $item_commission; //if no coupon applied commission unchanged
- }
- break;
- }
- }
- if( apply_filters( 'wcfmmp_is_allow_commission_fixed_per_unit', true ) ) {
- $item_commission = (float) $commission_rule['fixed'] * $quantity;
- } else {
- $item_commission = (float) $commission_rule['fixed'];
- }
- $item_commission = ( $item_commission * $item_total ) / $item_subtotal;
- if( (float) $item_price < (float) $item_commission ) {
- $item_commission = $item_price;
- }
- $admin_fee_mode = apply_filters( 'wcfm_is_admin_fee_mode', false );
- if( $admin_fee_mode ) {
- $item_commission = (float) $item_price - (float) $item_commission;
- }
- }
- return $item_commission;
- }, 10, 8);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement