Advanced Dynamic Pricing For WooCommerce

Paypal for WooCommerce, by Angelleye

PayPal for WooCommerce by Angell EYE adds PayPal Express Checkout and other PayPal payment methods to WooCommerce. When a customer initiates Express Checkout, the PayPal plugin stores session data about the current cart. The problem arises when Advanced Dynamic Pricing for WooCommerce recalculates cart prices — its internal process temporarily empties and rebuilds the cart, which triggers WooCommerce’s woocommerce_cart_emptied hook. PayPal’s session handler listens on that hook and clears its Express Checkout session data in response, losing the customer’s PayPal context mid-checkout.

This article provides a two-action fix that prevents PayPal’s session handler from firing during Advanced Dynamic Pricing’s cart recalculation cycle.


Required Settings Before Adding the Code

Before applying the snippet, confirm these two Advanced Dynamic Pricing settings are correct.

Go to Advanced Dynamic Pricing → Settings → Calculation and turn “Use prices modified by other plugins” to ON. Then go to Advanced Dynamic Pricing → Settings → System and turn “Suppress other pricing plugins in frontend” to OFF. Save both pages before continuing.


Code Sample

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

 Code Explained (for Developers)

The fix uses the same scoped hook pattern seen elsewhere in Advanced Dynamic Pricing compatibility code — temporarily detaching a conflicting callback before the plugin runs, then reattaching it immediately after. Here both actions target the PayPal Express Checkout session handler on woocommerce_cart_emptied.

ElementDescription
wdp_before_apply_to_wc_cartAn Advanced Dynamic Pricing action that fires just before the plugin starts applying pricing rules to the WooCommerce cart. Using this hook guarantees the detachment happens before any cart manipulation begins.
wdp_after_apply_to_wc_cartAn Advanced Dynamic Pricing action that fires immediately after the plugin completes its full cart recalculation cycle. The reattachment here restores normal PayPal session behaviour for everything that follows.
woocommerce_cart_emptiedA native WooCommerce action that fires whenever the cart contents get cleared. Advanced Dynamic Pricing triggers this during its internal cart rebuild process, which is what inadvertently calls PayPal’s session cleaner.
Angelleye_PayPal_Express_Checkout_Helper::instance()Retrieves the singleton instance of Angell EYE’s Express Checkout helper class. Using ::instance() here matches the exact callable format PayPal registered — you must pass the same object reference to remove_action() for the removal to succeed.
ec_clear_session_dataThe PayPal helper method that clears the Express Checkout session. Under normal circumstances this should only fire when a customer genuinely empties their cart — not during an internal pricing recalculation.
10 (priority in remove_action)Must match the priority PayPal used when it originally registered the handler, otherwise remove_action() will silently fail to find the callback and the session data continues to get cleared.
10, 0 (hook priority and arg count)Both actions register at priority 10 with 0 accepted arguments — neither callback needs any parameters from the hook since they only add or remove a filter.

Key concept: The remove_action() / add_action() pair creates a precise window during which PayPal’s session handler stays silent. Advanced Dynamic Pricing rebuilds the cart freely inside that window, and the handler resumes normal operation the moment the rebuild finishes — with no data loss for the customer’s PayPal session.


Why Does This Conflict Happen?

Advanced Dynamic Pricing recalculates cart prices by temporarily clearing cart items internally and rebuilding them with modified prices. This triggers woocommerce_cart_emptied, which WooCommerce fires any time it considers the cart to have been emptied. PayPal’s Express Checkout helper treats that signal as a genuine cart abandonment and wipes its session data — including any Express Checkout token the customer already generated. The customer then finds their PayPal checkout flow broken or reset, requiring them to start the payment process again from scratch.


How to Apply This Code

  1. Go to Advanced Dynamic Pricing → Settings → Calculation and enable “Use prices modified by other plugins”. Save the page.
  2. Go to Advanced Dynamic Pricing → Settings → System and disable “Suppress other pricing plugins in frontend”. Save the page.
  3. Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
  4. Paste the full snippet into your child theme’s functions.php or create a new dedicated snippet.
  5. Save the file or snippet.
  6. Test the fix by adding a product with an active discount rule to your cart, proceeding to checkout, and selecting PayPal Express Checkout. Verify that the PayPal flow completes without resetting mid-checkout and that the discounted total carries through to the PayPal payment screen 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 fix applies whenever customers using PayPal Express Checkout encounter a broken or reset checkout experience after Advanced Dynamic Pricing applies a discount rule. The most common symptoms are: the PayPal Express Checkout window closing unexpectedly, the customer returning to the cart with the PayPal session lost, or the discounted price not reaching the PayPal payment screen. If you run both plugins simultaneously and any of these occur, this snippet resolves the conflict.

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