• Resolved fkarimi

    (@fkarimi)


    Hi,

    Is there a possible way to automatically calculate and include commission to a vendors sale price for a product.

    e. g

    Product A price = $ 200
    Commission = 10%

    Product sale price = $ 220

    This way the vendor can always get what he/she sets for the product.

    Thanks.

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

    (@wclovers)

    Kindly add this snippet to your site for the purpose-

    add_filter( 'woocommerce_product_get_price', function( $price, $product ) {
    	global $WCFM, $WCFMmp, $post, $blog_id;
    	
    	$vendor_id = wcfm_get_vendor_id_by_post( $product->get_id() );
    	if( $vendor_id && !wcfm_is_vendor() ) {
    		$commisson_rule = $WCFMmp->wcfmmp_product->wcfmmp_get_product_commission_rule( $product->get_id() );
    		if( !empty( $commisson_rule ) && is_array( $commisson_rule ) && isset( $commisson_rule['percent'] ) ) {
    			$price += ( $price * ((float)$commisson_rule['percent']/100) );
    		}
    		if( !empty( $commisson_rule ) && is_array( $commisson_rule ) && isset( $commisson_rule['fixed'] ) ) {
    			$price += (float)$commisson_rule['fixed'];
    		}
    	}
    	return $price;
    }, 50, 2 );
    
    add_filter( 'wcfmmp_order_item_commission', function( $item_commission, $vendor_id, $product_id, $variation_id, $item_price, $quantity, $commission_rule, $order_id ) {
    	$seller_listing_price = ($item_price - (float) $commission_rule['fixed']) / (1 + ((float) $commission_rule['percent']/100));
    	$item_commission = $seller_listing_price;	
    	return $item_commission;
    }, 50, 8 );

    Add custom code(s) to your child theme’s functions.php
    In case you do not have child theme then add those using this plugin –?https://www.ads-software.com/plugins/code-snippets/

    Thread Starter fkarimi

    (@fkarimi)

    Thank you. The code works.

    However, the new price (Commission + vendors price) only shows on the admin side of the site but when a customer is on the site, the price doesn’t include the commission,instead it only shows the vendors price.

    How can I fix this so that the new price (commission + vendors price) shows on the customers side of the site.

    Thanks.

    Plugin Author WC Lovers

    (@wclovers)

    only shows on the admin side of the site but when a customer is on the site

    – Is this customer also a vendor user?

    Please check as non-logged in user or a customer user.

    Thread Starter fkarimi

    (@fkarimi)

    Thank you.

    It has worked.

    Much appreciated for your help.

    Plugin Author WC Lovers

    (@wclovers)

    Welcome ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Automatically include commission to a vendors sale price’ is closed to new replies.