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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / compatibility / WcNameYourPrice / MulticurrencyHooks.php
woocommerce-multilingual / compatibility / WcNameYourPrice Last commit date
Factory.php 4 weeks ago MulticurrencyHooks.php 4 weeks ago
MulticurrencyHooks.php
98 lines
1 <?php
2
3 namespace WCML\Compatibility\WcNameYourPrice;
4
5 use WC_Name_Your_Price_Compatibility;
6
7 use function WPML\Container\make;
8 use function WCML\functions\getClientCurrency;
9
10 class MulticurrencyHooks implements \IWPML_Action {
11
12 public function add_hooks() {
13 if ( ! is_admin() ) {
14 if ( is_callable( [ 'WC_Name_Your_Price_Compatibility', 'is_nyp_gte' ] ) && WC_Name_Your_Price_Compatibility::is_nyp_gte( '3.0' ) ) {
15 add_filter( 'wc_nyp_raw_suggested_price', [ $this, 'product_price_filter' ] );
16 add_filter( 'wc_nyp_raw_minimum_price', [ $this, 'product_price_filter' ] );
17 add_filter( 'wc_nyp_raw_maximum_price', [ $this, 'product_price_filter' ] );
18 } else {
19 add_filter( 'woocommerce_raw_suggested_price', [ $this, 'product_price_filter' ] );
20 add_filter( 'woocommerce_raw_minimum_price', [ $this, 'product_price_filter' ] );
21 add_filter( 'woocommerce_raw_maximum_price', [ $this, 'product_price_filter' ] );
22 }
23 }
24
25 add_filter( 'woocommerce_add_cart_item_data', [ $this, 'add_initial_currency' ] );
26 add_filter( 'woocommerce_get_cart_item_from_session', [ $this, 'filter_woocommerce_get_cart_item_from_session' ], 20, 2 );
27
28 add_filter( 'wc_nyp_edit_in_cart_args', [ $this, 'edit_in_cart_args' ], 10 );
29 add_filter( 'wc_nyp_get_initial_price', [ $this, 'get_initial_price' ], 10, 3 );
30 }
31
32 public function product_price_filter( $price, $currency = false ) {
33 return apply_filters( 'wcml_raw_price_amount', $price, $currency );
34 }
35
36 public function add_initial_currency( $cart_item_data ) {
37
38 if ( isset( $cart_item_data['nyp'] ) ) {
39 $cart_item_data['nyp_currency'] = get_woocommerce_currency();
40 $cart_item_data['nyp_original'] = $cart_item_data['nyp'];
41 }
42
43 return $cart_item_data;
44 }
45
46 public function filter_woocommerce_get_cart_item_from_session( $session_data, $values ) {
47
48 if ( isset( $values['nyp_currency'] ) ) {
49 $session_data['nyp_currency'] = $values['nyp_currency'];
50 }
51
52 if ( isset( $values['nyp_original'] ) ) {
53 $session_data['nyp_original'] = $values['nyp_original'];
54 }
55
56 $current_currency = getClientCurrency();
57
58 if ( isset( $session_data['nyp_currency'] ) && $session_data['nyp_currency'] !== $current_currency ) {
59
60 $product = $session_data['data'];
61
62 $price_in_current_currency = $this->product_price_filter( $session_data['nyp'], $current_currency );
63
64 $product->set_price( $price_in_current_currency );
65 $product->set_regular_price( $price_in_current_currency );
66 $product->set_sale_price( $price_in_current_currency );
67
68 if ( $product->is_type( [ 'subscription', 'subscription_variation' ] ) ) {
69 $product->update_meta_data( '_subscription_price', $price_in_current_currency );
70 }
71 }
72
73 return $session_data;
74 }
75
76 public function edit_in_cart_args( $args ) {
77 $args['nyp_currency'] = get_woocommerce_currency();
78 return $args;
79 }
80
81 public function get_initial_price( $initial_price, $product, $suffix ) {
82
83 if ( isset( $_REQUEST[ 'nyp_raw' . $suffix ] ) && isset( $_REQUEST[ 'nyp_currency' ] ) ) {
84 $from_currency = wc_clean( $_REQUEST[ 'nyp_currency' ] );
85 $current_currency = get_woocommerce_currency();
86 if ( $from_currency !== $current_currency ) {
87 $raw_price = wc_clean( $_REQUEST[ 'nyp_raw' . $suffix ] );
88
89 $multi_currency = make( \WCML_Multi_Currency::class );
90 $initial_price = $multi_currency->prices->convert_price_amount_by_currencies( $raw_price, $from_currency, $current_currency );
91 }
92 }
93
94 return $initial_price;
95 }
96
97 }
98