Advanced Dynamic Pricing For WooCommerce

WooCommerce B2B Sales Agents

WooCommerce B2B Sales Agents lets sales representatives switch into a customer’s account and place orders on their behalf — including the ability to set custom per-item prices directly in the cart. When a sales agent switches into a customer session and Advanced Dynamic Pricing for WooCommerce is active, two conflicts can surface: the quantity field in the cart may not accept decimal values (breaking B2B fractional quantity workflows), and the cart item price column no longer shows the agent’s editable price input field. Instead, Advanced Dynamic Pricing’s price HTML replaces it, removing the agent’s ability to manually override prices.

This article provides a short compatibility snippet that restores decimal quantity handling and brings back the agent’s custom price input field when a sales agent session is active.


Required Settings Before Adding the Code

Two settings need adjusting before the snippet takes full effect.

Go to Advanced Dynamic Pricing → Settings → Calculation and set “Apply discount on ‘Onsale’ products” to “Discount sale price”. This ensures Advanced Dynamic Pricing applies its rules on top of existing sale prices rather than ignoring them, which keeps pricing consistent during agent-managed sessions.

The standard compatibility settings also apply — make sure “Use prices modified by other plugins” stays ON and “Suppress other pricing plugins in frontend” stays OFF in the same Calculation and System settings pages respectively.


Code Sample

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

Code Explained (for Developers)

Outer guard
ElementDescription
function_exists( 'adp_functions' )Confirms Advanced Dynamic Pricing is active before registering either filter. Both fixes target a conflict that only exists when both plugins run simultaneously, so the guard keeps the snippet clean and inert when Advanced Dynamic Pricing is absent.

Fix 1 — woocommerce_stock_amount_cart_item

ElementDescription
woocommerce_stock_amount_cart_itemA WooCommerce filter that controls how the cart parses and validates the quantity value for each cart item. By default WooCommerce casts quantities to integers via intval(), which truncates decimals.
return floatval( $qty )Casts the quantity to a float instead, preserving decimal values like 1.5 or 2.75. B2B sales agents frequently use fractional quantities for products sold by weight or volume — without this fix those quantities get silently truncated to whole numbers when Advanced Dynamic Pricing processes the cart.

Fix 2 — woocommerce_cart_item_price / b2b_wdp_cmp_edit_price()
ElementDescription
woocommerce_cart_item_priceA WooCommerce filter that controls the HTML output in the price column for each cart row. Advanced Dynamic Pricing hooks into this filter and replaces the price with its own formatted output — which overwrites the B2B Sales Agents custom price input field.
Priority 15Registers the callback after Advanced Dynamic Pricing’s own filter (which typically runs at priority 10 or lower), ensuring this function fires last and can override the price column HTML when an agent session is active.
is_user_logged_in()Checks that a user session exists before attempting to read transient or cookie data. Guests have no agent session, so the function falls through to return the default $price.
get_transient( 'wcb2bsa_switched_' . get_current_user_id() )Reads a transient the B2B Sales Agents plugin sets when a sales agent switches into a customer account. If this transient exists, an active agent session is running.
isset( $_COOKIE['wcb2bsa_switched'] )A secondary check — verifies the agent’s browser cookie is also present, confirming both server-side and client-side session state agree. Both conditions must pass to show the custom price input.
apply_filters( 'wcb2bsa_cart_input', array(...) )Retrieves the input field attributes through the B2B Sales Agents plugin’s own filter, allowing other code to customise the field’s CSS class, minimum value, or step value without modifying this function.
sprintf( '<input type="number" ...>' )Builds the HTML number input that the sales agent uses to set a custom price. The name attribute follows B2B Sales Agents’ expected format (cart[{key}][wcb2bsa_custom_price]) so the plugin captures the value on form submission.
$cart_item['data']->get_price()Populates the input’s value attribute with the current product price — which at this point already reflects any Advanced Dynamic Pricing discount — giving the agent a sensible starting point to edit from.
return $priceFalls through to return the unmodified price HTML for all non-agent cart views, so normal customers see the standard price display.

Key concept: The custom price input only renders when both the transient and the cookie confirm an active agent session. Outside of agent sessions, the filter returns $price unchanged, so the fix has zero impact on regular customer-facing cart display.


How to Apply This Code

  1. Go to Advanced Dynamic Pricing → Settings → Calculation and set “Apply discount on ‘Onsale’ products” to “Discount sale price”. Save the page.
  2. On the same settings page, confirm “Use prices modified by other plugins” is ON.
  3. Go to Advanced Dynamic Pricing → Settings → System and confirm “Suppress other pricing plugins in frontend” is OFF. Save the page.
  4. Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
  5. Paste the full snippet into your child theme’s functions.php or create a new dedicated snippet.
  6. Save the file or snippet.
  7. Log in as a sales agent, switch into a customer account, and open the cart with at least one product.
  8. Verify the price column shows the editable number input rather than a static price string.
  9. If your B2B workflow uses fractional quantities, add a product with a decimal quantity (e.g. 1.5) and confirm the cart accepts and retains it correctly.

⚠️ 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?

This snippet fits whenever your store uses sales agents to manage customer orders and one or both of these problems occur: the cart collapses decimal quantities to whole numbers when Advanced Dynamic Pricing is active, or the agent’s price input field disappears from the cart and gets replaced by a static formatted price string. It also applies when agents need to see the dynamically calculated price as the starting value in their custom price field, rather than the raw database price.

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

Advanced Dynamic Pricing
for WooCommerce
PRO

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