public static function woocommerce_get_price($price, $product) { global $post, $woocommerce; $baseprice = $price; $result = $baseprice; if ($post == null || !is_admin()) { if ($product->is_type('variation')) { $commission = WRP_Variations_Admin::get_commission($product, $product->variation_id); } else { $commission = self::get_commission($product); } if ($commission) { $baseprice = $product->get_regular_price(); if ($product->get_sale_price() != $product->get_regular_price() && $product->get_sale_price() == $product->price) { if (get_option("wrp-baseprice", "regular") == "sale") { $baseprice = $product->get_sale_price(); } } $product_price = $baseprice; $type = get_option("wrp-method", "rate"); $result = 0; if ($type == "rate") { // if rate and price includes taxes if ($product->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') { $_tax = new WC_Tax(); $tax_rates = $_tax->get_shop_base_rate($product->tax_class); $taxes = $_tax->calc_tax($baseprice, $tax_rates, true); $product_price = $_tax->round($baseprice - array_sum($taxes)); } $result = self::bcmul($product_price, $commission, WOO_ROLE_PRICING_DECIMALS); if ($product->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') { $_tax = new WC_Tax(); $tax_rates = $_tax->get_shop_base_rate($product->tax_class); $taxes = $_tax->calc_tax($result, $tax_rates, false); // important false $result = $_tax->round($result + array_sum($taxes)); } } else { $result = self::bcsub($product_price, $commission, WOO_ROLE_PRICING_DECIMALS); } } } return $result; }
$method = get_option("wrp-method", "rate"); foreach ($roles as $role) { $temp_com = self::get_commission($product, $variation_id, $role); if ($method == "rate") { // if rate: lower discount is higher commission if ($commission == null || $temp_com > $commission) { $commission = $temp_com; $result = $role; } } else { if ($commission == null || $temp_com < $commission) { $commission = $temp_com; $result = $role; } } } break; case 'last': $result = $roles[sizeof($roles) - 1]; break; default: case 'first': $result = $roles[0]; break; } } return $result; } } WRP_Variations_Admin::init();