{SAVE_PERCENT} is not correct
-
Great Plugin! Love it.
Found some wrong calculation/maths for this variables on my store:
{SAVE_PERCENT}
{SAVE_AMOUNT|2}
Please see the attachment. The two variables are printed in the labels.
The values are not correct.
Nothing special on my store, default woo.
https://prnt.sc/59H-QxBpSBN5
-
Hi,
Please try ti use following code snippet:
add_filter('awl_enable_discounts_cache', 'my_awl_enable_discounts_cache'); function my_awl_enable_discounts_cache( $cache ) { return true; }
You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.
Also, after adding this code you will need to go to the plugin settings page and click the ‘Clear cache’ button.
Thank for your reply!
Added the filter to my functions.php, but there is no cache button in the plugin settings page.
Am I missing something.
I’m with the free version.Sorry about that. Just add this code snippet. If you have any caching plugin installed – clear their cache. The AWL plugin itself doesn’t have such a clear cache button.
The filter is added, but the calcs are still not correct ??
I have an idea that this could happen because of the dot at the end of the currency symbol. Can you temporarily remove it from the currency and check discounts calculation one more time?
Thanks for your reply!
The problem is related with the TAX settings.
When I disable the tax calculation for specific product, the save percentage is correct.
By default the prices of the products are entered Exclusive of tax.
Display prices in the shop: Including tax
In this scenario, I’m getting a warning from Woo for Inconsistent tax settings. But everything works fine with this warning, and no worries till now.Here is a screenshot form the Tax settings/warning: https://prnt.sc/vYfdtmWZ_lod
Well, when I change the settings as recommended by Woo, the save percentage is correct. I mean to display prices excluding of taxes ?? (which is not ok for B2C clients.)But for this specific project, we need to enter prices excluding of taxes and show them in the store front with Inclusive of tax.
It’s related to accounting, invoices and erp integration. The change of the tax calculation and prices will bring us serious problems with the workflow.
Hope this helps the community.I see.
So for now you can fix this problem by using following code snippet:
add_filter( 'awl_labels_text_vars', 'my_awl_labels_text_vars', 1 ); function my_awl_labels_text_vars( $variables ) { $variable['/{SAVE_AMOUNT_NEW\s*\|*\s*([\d]*)\s*}/i'] = array( 'func' => 'new_get_discount_amount_text', 'desc' => __( "Show discount about. Fix for tax calculation", "advanced-woo-labels" ), 'example' => '{SAVE_AMOUNT_NEW}', ); $variables = array_merge( $variable, $variables ); return $variables; } function new_get_discount_amount_text( $matches ) { global $product; $round = isset( $matches[1] ) ? intval( $matches[1] ) : 0; $value = new_get_discount_amount( $product ); $save_amount = $value ? number_format( $value, $round, wc_get_price_decimal_separator(), wc_get_price_thousand_separator() ) : ''; return $save_amount; } function new_get_discount_amount( $product ) { $enable_cache_discounts = apply_filters( 'awl_enable_discounts_cache', false, $product ); $save_amount = 0; if ( $product->is_type( 'variable' ) ) { if ( $enable_cache_discounts ) { $save_amount_cache = get_post_meta( $product->get_id(), '_awl_save_amount_value_new', true ); if ( $save_amount_cache ) { return $save_amount_cache; } } $available_variations = $product->get_available_variations(); for ( $i = 0; $i < count( $available_variations ); ++ $i ) { $variation_id = $available_variations[ $i ]['variation_id']; $variable_product = new WC_Product_Variation( $variation_id ); $variable_product_regular_price = wc_get_price_to_display($product, array('price' => $variable_product->get_regular_price() )); $variable_product_sale_price = wc_get_price_to_display($product, array('price' => AWL_Product_Data::get_sale_price( $variable_product ) )); if ( $variable_product_regular_price == $variable_product_sale_price ) { continue; } $amount = $variable_product_regular_price - $variable_product_sale_price; if ( $amount > $save_amount ) { $save_amount = $amount; } } if ( $enable_cache_discounts ) { update_post_meta( $product->get_id(), '_awl_save_amount_value_new', $save_amount ); } } else { $product_regular_price = wc_get_price_to_display($product, array('price' => $product->get_regular_price() )); $product_sale_price = wc_get_price_to_display($product, array('price' => AWL_Product_Data::get_sale_price( $product ) )); if ( $product_sale_price && $product_regular_price && $product_regular_price !== $product_sale_price ) { $save_amount = $product_regular_price - $product_sale_price; } } return $save_amount; }
You need to add this code somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.
Now you can use new text variable {SAVE_AMOUNT_NEW} to show discount amount.
Also in the next plugin releases I will try to fix this problem.
Regards
- The topic ‘{SAVE_PERCENT} is not correct’ is closed to new replies.