Wholesale Suite – WooCommerce Wholesale Prices & B2B Plugin, by Rymera Web Co
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//Wholesale Suite – WooCommerce Wholesale Prices & B2B Plugin add_filter("wpo_prepare_item", function($item,$product){ if( @$item['cost_updated_manually'] ) return $item;// edited via UI ? $item["item_cost"] = $item["wpo_item_discount"]["discounted_price"] = $item["wpo_item_discount"]["original_price"] = $product->get_price(); // set default cost $item["wpo_item_discount"]["discount"] = 0; // no discount! $user_id = $_REQUEST["cart"]["customer"]["id"]; if( !$user_id ) return $item; // customer not selected $user = get_userdata( $user_id ); $user_role = reset($user->roles); $ww_price = get_post_meta($product->get_id(),$user_role ."_wholesale_price", true); $ww_minqty = get_post_meta($product->get_id(),$user_role ."_wholesale_minimum_order_quantity",true); if( $ww_minqty AND $item['qty'] < $ww_minqty OR empty($ww_price) ) return $item; // too few items or price is not set $item["wpo_item_discount"]["discount_type"] = "fixed"; $item["wpo_item_discount"]["discount"] = $item["wpo_item_discount"]["original_price"] - $ww_price; $item["item_cost"] = $item["wpo_item_discount"]["discounted_price"] = $ww_price; return $item; },10,2); |