Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit ec272c0

Browse files
committed
fixes #390, #346 Cart: retain price when switching languages props mweimerskirch
1 parent 49d1196 commit ec272c0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Hyyan/WPI/Cart.php

+20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Hyyan\WPI;
1212

1313
use Hyyan\WPI\Product\Variation;
14+
use Hyyan\WPI\Product\Meta;
1415
use Hyyan\WPI\Utilities;
1516

1617
/**
@@ -105,6 +106,25 @@ public function translateCartItemProduct($cart_item_data, $cart_item)
105106
break;
106107
}
107108

109+
110+
// If we are changing the product to the right language
111+
if ( $cart_item_data_translation->get_id() != $cart_item_data->get_id() ) {
112+
// Keep the price that's currently saved in the cart,
113+
// because it might have been modified using the
114+
// "woocommerce_before_calculate_totals" filter
115+
// (unless the shop admin has explicitly turned off price synchronisation options)
116+
$metas = Meta::getDisabledProductMetaToCopy();
117+
if ( ! in_array( '_regular_price', $metas ) ) {
118+
$cart_item_data_translation->set_regular_price( $cart_item_data->get_regular_price() );
119+
}
120+
if ( ! in_array( '_sale_price', $metas ) ) {
121+
$cart_item_data_translation->set_sale_price( $cart_item_data->get_sale_price() );
122+
}
123+
if ( ! in_array( '_price', $metas ) ) {
124+
$cart_item_data_translation->set_price( $cart_item_data->get_price() );
125+
}
126+
}
127+
108128
return $cart_item_data_translation;
109129
}
110130

0 commit comments

Comments
 (0)