I read through the documentation but didn’t see where 3rd party plugins could hook into an client side events to listen for changes in the product price.
When a product option is selected on the product page, I can see that the hidden element with id="prad_selection" is updated with a stringified JSON object.
I’d like to submit a request for a client side event to be emitted when the product price is updated. jQuery already supports the triggerHandler function which you could use to emit an object that contains relevant information like the product price, selected options etc.
This would the make it possible for 3rd party plugins to respond to that event. In our case, with our Stripe plugin we’d like to update the buy now pay later messaging.
Thanks for dropping by our forum! We love seeing developers working together to improve the WooCommerce ecosystem, and your idea for a client-side event trigger is excellent.
I passed your notes directly to our developers. They are eager to help, but they mentioned that your exact requirement isn’t 100% clear just yet.our developers mentioned they need a bit more clarification regarding your specific requirements and the exact data payload you need emitted.
Thank you for your reply. Regarding the requirements, I think providing the product total plus an array of selected addons would be great. Here is an example of what the payload could look like:
In this example, the product’s configured price is $95 and the customer has selected a quantity of 2. The customer has chosen 2 addons, the Size and Color.
Original Price: $95 X 2 = $190
Size Add On: $5
Color Add On: $5 X 2 = $10
Final Price = $205
With this payload structure, our plugin can use the payload.price to update the necessary integrations. By providing payload.price, which is the price after all addon calculations, 3rd party plugins don’t need to have knowledge of your plugin’s business logic.
Kind Regards
This reply was modified 1 week, 5 days ago by Clayton R.
Thank you for providing that payload structure! This makes perfect sense and clarifies exactly what you need.
I have passed your example directly to our developers. They understand, but since this involves modifying our core event triggers, they will need to discuss it internally to make a final decision on the implementation.
We will discuss this with the team and let you know what they decide!
While testing your plugin I have noticed a few inconsistencies which might be considered bugs but might be a misunderstanding on my part.
When updating the product quantity, the Total Price does not update accordingly. Notice in this screenshot is remains at $104.90 despite the quantity of 2.
2. Despite having the Size Option addon configured to a fixed price type, when adding the 2 items to the cart, the subtotal is $209.80. That seems contradictory to the Price Type setting since there is a “Per Unit” option offered.
3. Given that the plugin supports Fixed, Percentage, Per Unit, and No Cost price options, does that means the plugin assumed Per Unit is fixed? I would think assigning “Per Unit” would be a separate option and the administrator can configure their price type to be one of Fixed, Percentage, or No Cost. This way they can offer the different price types as either Per Unit for all quantities.
Thank you for continuing to test the plugin and sharing your notes!
Regarding the Total Price not updating dynamically: This is actually the default behavior of WooCommerce, as it does not calculate totals on the single product page when the quantity changes. However, I am forwarding this to our dev team to see if we can add a custom feature to bypass the WooCommerce default and make it dynamic!
Regarding your points on the Fixed and Per Unit pricing: Your logic is spot on. However, advanced “Per Unit” separation and specific fee modifiers are upgraded features. In the free version, the standard “Fixed” fee will automatically multiply by the cart quantity.
I do love your suggestion about restructuring the “Per Unit” option as a separate checkbox, and I have passed that UI feedback to our R&D team!