Wholesale Suite – WooCommerce Wholesale Prices & B2B Plugin, by Rymera Web Co
Wholesale Suite by Rymera Web Co stores role-specific wholesale prices as product meta fields using the pattern {role_slug}_wholesale_price. When a sales agent creates a backend order in Phone Orders for WooCommerce, the session runs as the logged-in admin rather than the selected customer, so Wholesale Suite’s pricing never fires for the customer’s wholesale role — the agent sees and records the retail price instead.
This snippet hooks into the Phone Orders cart item preparation cycle and reads the wholesale price directly from product meta for the selected customer’s role, applying it with a correct discount breakdown.
Code Sample
|
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); |
Code Explained (for Developers)
| Element | Description |
|---|---|
wpo_prepare_item | A Phone Orders filter that fires during cart item preparation. Sets price and discount data the plugin uses for display and order writing. |
@$item['cost_updated_manually'] | Checks whether the agent already edited this item’s price manually in the UI. If so, the snippet exits and preserves the manual value. |
$_REQUEST["cart"]["customer"]["id"] | Reads the selected customer’s user ID from the Phone Orders AJAX request. Returns empty when no customer is selected yet — the snippet exits cleanly in that case. |
reset( $user->roles ) | Retrieves the customer’s primary WordPress role slug. Wholesale Suite stores prices per role using this slug as part of the meta key. |
{role}_wholesale_price meta | The product meta key Wholesale Suite uses for role-specific prices. The snippet reads this directly via get_post_meta() using the customer’s role slug. |
{role}_wholesale_minimum_order_quantity meta | The minimum quantity threshold for the wholesale price to apply. If the cart item quantity falls below this value, the snippet returns the item at regular price. |
wpo_item_discount array | Phone Orders’ internal structure for discount breakdown. Filling discount_type, discount, original_price, and discounted_price ensures the UI and the saved order both reflect the correct wholesale price and discount amount. |
How to Apply This Code
- Open Appearance → Theme File Editor or the Code Snippets plugin.
- Paste the snippet into your child theme’s
functions.phpor create a new dedicated snippet. - Save and open Phone Orders with a customer whose role has a wholesale price configured in Wholesale Suite.
- Add a product with a wholesale price for that role and verify the cart shows the correct wholesale price and discount breakdown.
- Test the minimum quantity threshold by adding fewer items than the minimum and confirming the retail price applies.
⚠️ Always use a child theme or Code Snippets — parent theme files get overwritten on theme updates.
When Should You Use This Fix?
This fix applies whenever your store uses Wholesale Suite for role-based pricing and agents create backend orders through Phone Orders PRO. Without it, agents see retail prices for wholesale customers and the resulting orders carry incorrect prices.