Codeinwp / Codeinwp/woocommerce-product-addon
Improper subtotal values for cart items in the cart view
- Dominant language
- PHP
- Stars
- 15
- Forks
- 9
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 16
Description
Description
Plugin version: 34.0.8
When adding multiple options configured through this module to a single product - improper subtotal values appear in the cart view.
I have a restaurant with catering website that allows the customer to add custom extras to the food. Here is an image showing the product page with available extras:
As you can see the total is 17,00 zł
When I proceed to the cart view though - the subtotal is 12,00 zł
It appears that only one extra field is being taken into calculation.
Step-by-step reproduction instructions
- Go to backoffice to create a field group inside the module settings.
- Configure at least 3 checkbox fields that add flat value to the price.
- Apply that config to any product.
- Proceed to front office - to the product chosen in the last step.
- Add at least 2 fields to the product.
- Observe the price on the product page.
- Add the product to the cart.
- Proceed to the cart view.
- Observe the subtotal of the previously added product.
Screenshots, screen recording, code snippet or Help Scout ticket
I have already found a solution to this problem in the following file:
\woocommerce-product-addon\src\WooCommerce\Cart\CartHandler.php
function item_subtotal (line ~778)
Replace this:
foreach ( $option_prices as $option ) {
$option = Helpers::translation_options( $option );
$option_price = isset( $option['price'] ) ? $option['price'] : 0;
if ( 0 === $option_price || ( ! isset( $option['apply'] ) || 'onetime' !== $option['apply'] ) ) {
continue;
}
$price = isset( $option['discount'] ) && $option['discount'] > 0 ? $option['discount'] : $option_price;
if ( ! empty( $price ) ) {
$price = apply_filters( 'ppom_option_price', $price );
$price = floatval( wp_strip_all_tags( $price ) );
}
}
With this:
foreach ( $option_prices as $option ) {
$option = Helpers::translation_options( $option );
$option_price = isset( $option['price'] ) ? (float) $option['price'] : 0;
if ( $option_price === 0 || ( ! isset( $option['apply'] ) || 'onetime' !== $option['apply'] ) ) {
continue;
}
$current_price = ( isset( $option['discount'] ) && $option['discount'] > 0 )
? (float) $option['discount']
: $option_price;
$current_price = apply_filters( 'ppom_option_price', $current_price );
$current_price = (float) wp_strip_all_tags( $current_price );
$price += $current_price;
}
It fixes a problem with setting the value of the subtotal by instead accummulating it
Environment info
No response
Is the issue you are reporting a regression
No
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.