Advertisement
wclovers

Untitled

Jul 3rd, 2023
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. add_filter( 'woocommerce_product_get_price', 'wcfm_update_product_price', 50, 2);
  2. add_filter( 'woocommerce_product_get_regular_price', 'wcfm_update_product_price', 50, 2);
  3. add_filter( 'woocommerce_product_get_sale_price', 'wcfm_update_product_price', 50, 2);
  4.  
  5. function wcfm_update_product_price( $price, $product ) {
  6.     global $WCFMmp;
  7.    
  8.     $vendor_id = wcfm_get_vendor_id_by_post( $product->get_id() );
  9.     if( $vendor_id && !wcfm_is_vendor() ) {
  10.         $commisson_rule = $WCFMmp->wcfmmp_product->wcfmmp_get_product_commission_rule( $product->get_id() );
  11.         $total_commission = 0;
  12.         $price = (float)$price;
  13.         if( !empty( $commisson_rule ) && is_array( $commisson_rule ) && isset( $commisson_rule['percent'] ) ) {
  14.             $price += ( $price * ((float)$commisson_rule['percent']/100) );
  15.         }
  16.         if( !empty( $commisson_rule ) && is_array( $commisson_rule ) && isset( $commisson_rule['fixed'] ) ) {
  17.             $price += (float)$commisson_rule['fixed'];
  18.         }
  19.  
  20.         $price += $total_commission;
  21.     }
  22.  
  23.     return $price;
  24. }
  25.  
  26. add_filter( 'wcfmmp_order_item_commission', function( $item_commission, $vendor_id, $product_id, $variation_id, $item_price, $quantity, $commission_rule, $order_id ) {
  27.     $seller_listing_price = ($item_price - (float) $commission_rule['fixed']) / (1 + ((float) $commission_rule['percent']/100));
  28.     $item_commission = $seller_listing_price;  
  29.     return $item_commission;
  30. }, 50, 8 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement