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

Commit

Permalink
fixes #390, #346 Cart: retain price when switching languages props mw…
Browse files Browse the repository at this point in the history
…eimerskirch
  • Loading branch information
Jon007 committed May 25, 2019
1 parent 49d1196 commit ec272c0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Hyyan/WPI/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Hyyan\WPI;

use Hyyan\WPI\Product\Variation;
use Hyyan\WPI\Product\Meta;
use Hyyan\WPI\Utilities;

/**
Expand Down Expand Up @@ -105,6 +106,25 @@ public function translateCartItemProduct($cart_item_data, $cart_item)
break;
}


// If we are changing the product to the right language
if ( $cart_item_data_translation->get_id() != $cart_item_data->get_id() ) {
// Keep the price that's currently saved in the cart,
// because it might have been modified using the
// "woocommerce_before_calculate_totals" filter
// (unless the shop admin has explicitly turned off price synchronisation options)
$metas = Meta::getDisabledProductMetaToCopy();
if ( ! in_array( '_regular_price', $metas ) ) {
$cart_item_data_translation->set_regular_price( $cart_item_data->get_regular_price() );
}
if ( ! in_array( '_sale_price', $metas ) ) {
$cart_item_data_translation->set_sale_price( $cart_item_data->get_sale_price() );
}
if ( ! in_array( '_price', $metas ) ) {
$cart_item_data_translation->set_price( $cart_item_data->get_price() );
}
}

return $cart_item_data_translation;
}

Expand Down

0 comments on commit ec272c0

Please sign in to comment.