I found an issue in your plugin
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price_mstore_api' );
function add_custom_price_mstore_api( $cart_object ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$add_price = 0;
if ($variations = $cart_item['variation']) {
foreach($variations as $v => $f) {
preg_match('#\((.*?)\)#', $v, $match);
if(is_array($match) && array_key_exists(1,$match)){
$val = $match[1];
$cents = filter_var($val, FILTER_SANITIZE_NUMBER_INT);
if(is_numeric($cents)){
$add_price += floatval($cents / 100);
}
}
}
}
$new_price = $cart_item['data']->get_price() + $add_price;
$res = $cart_item['data']->set_price($new_price);
}
}
The above code contains
$new_price = $cart_item['data']->get_price() + $add_price;
$res = $cart_item['data']->set_price($new_price);
First nonsense issue it’s outside if condition which only get the price and add 0 to it
Second once get the price with WOOCS I guess it give the price in current currency conversion not the base price So once set price again it reconvert the price again
So an example of what happened:
if I have 2 currencies KWD (default) and USD and the conversion rate is 2 for example
With a product with 100 KWD price added to cart in EUR website version
The cart should contains $200 product. But it shows $400 product in the cart
Please advise why this method exists in a first place and does it needed on mobile?
-
This reply was modified 2 years, 5 months ago by SZ4H.