Phone Orders For WooCommerce

Wholesale For WooCommerce , by wpexperts.io

Wholesale For WooCommerce by wpexperts.io adds role-based wholesale pricing to WooCommerce, storing per-role price rules in each product’s meta data. When a sales agent creates a backend order in Phone Orders for WooCommerce, the plugin builds its cart independently from the WooCommerce storefront session — which means Wholesale For WooCommerce’s pricing rules don’t fire automatically for cart items added through the Phone Orders interface.

This article provides two filter hooks that inject wholesale pricing into the Phone Orders cart at the point where each product is added and prepared, so the prices the agent sees and the prices written to the order always reflect the selected customer’s wholesale tier.


Code Sample

Add the following snippet to your child theme’s functions.php or the Code Snippets plugin:

Code Explained (for Developers)

The snippet contains two filters that work at different points in the Phone Orders cart lifecycle — the first when a product gets added, the second when its price data gets prepared for display and order writing.


Filter 1 — wpo_get_item_by_product

This filter fires when Phone Orders first resolves a product into a cart item object. It sets the initial item_cost to the customer’s wholesale price so the correct value appears in the cart immediately.

ElementDescription
wpo_get_item_by_productA Phone Orders filter that fires when a product is converted into a cart item. Returns the $item array that Phone Orders stores for the product.
$_REQUEST["cart"]["customer"]["id"]Reads the currently selected customer’s user ID from the Phone Orders AJAX request payload. Returns empty if no customer is selected yet — the snippet exits early in that case.
$product->get_meta("wholesale_multi_user_pricing")Reads the wholesale pricing meta stored by Wholesale For WooCommerce on each product. Returns null if no wholesale rules exist for this product.
get_current_user_role_id()A Wholesale For WooCommerce helper function that returns the current user’s wholesale role ID. The snippet uses this to look up the correct pricing tier for the selected customer’s role.
Variation checkIf the product is a variation and the rule data contains a variation-specific entry keyed by product ID, the snippet uses that variation’s wholesaleprice and qty values instead of the parent rule’s values.
Fixed vs percentage branchFor discount_type == "fixed", item_cost gets set directly to the wholesale price. For percentage discounts, the wholesale price value represents the discount percentage — the snippet calculates the final price as regular_price × (100 - wholesale_price%) / 100.

Filter 2 — wpo_prepare_item

This filter fires when Phone Orders prepares the full discount breakdown for a cart item — populating the wpo_item_discount array that drives both the cart display and the order line item data written to the database.

ElementDescription
wpo_prepare_itemA Phone Orders filter that fires during cart item preparation. The $item array here carries the full discount breakdown structure Phone Orders uses for display and order writing.
@$item['cost_updated_manually']Checks whether the agent manually overrode the item price through the Phone Orders UI. If they did, the snippet returns early and preserves the agent’s manual price — wholesale pricing doesn’t override a deliberate agent edit.
Default price initialisationBefore applying any wholesale logic, the snippet sets item_cost, discounted_price, and original_price all to $product->get_price() and discount to 0. This ensures clean defaults if none of the wholesale conditions pass.
Minimum quantity checkif ( isset( $rule['qty'] ) && ( $item['qty'] < $rule['qty'] ) ) — if the wholesale rule carries a minimum quantity threshold and the cart item quantity falls below it, the snippet returns the item at regular price. Wholesale pricing only kicks in at or above the minimum.
wpo_item_discount array populationFills discount_type, discount, discounted_price, and original_price with the calculated values. Phone Orders reads this array to display the discount breakdown in the cart UI and to write accurate line item data when the order creates.
Fixed vs percentage branchFor fixed wholesale prices, the discount amount is original_price − wholesale_price. For percentage discounts, the discount amount is original_price × wholesale_percentage / 100, and the discounted price is original_price − discount.

How to Apply This Code

  1. Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
  2. Paste the full snippet into your child theme’s functions.php or create a new dedicated snippet.
  3. Save the file or snippet.
  4. Open Phone Orders and create a test order, selecting a customer whose role has wholesale pricing configured in Wholesale For WooCommerce.
  5. Add a product that carries a wholesale price rule for that role and verify the cart shows the correct wholesale price rather than the regular retail price.
  6. Also test with a product that requires a minimum quantity and confirm the wholesale price only applies once you meet or exceed the threshold.

⚠️ Always use a child theme or Code Snippets rather than editing the parent theme’s functions.php directly — parent theme files get overwritten on theme updates.


When Should You Use This Fix?

This snippet applies when your store uses Wholesale For WooCommerce to manage role-based wholesale pricing and your sales agents create backend orders through Phone Orders PRO. Without it, agents see and enter retail prices for wholesale customers in the Phone Orders cart — the resulting orders carry the wrong prices and require manual correction. With the snippet active, Phone Orders automatically applies the correct wholesale tier for the selected customer’s role, including minimum quantity thresholds and variation-specific pricing.

Have questions? Please submit a support request. We're always happy to help!

Phone Orders
for WooCommerce
PRO

From $120
Buy
✓ 30-day money-back guarantee