PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.10.6
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.10.6
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / compatibility / plugin / class-wpfnl-wcml.php

class-wpfnl-wcml.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.10.6, at includes/core/compatibility/plugin/class-wpfnl-wcml.php

222 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WooCommerce Multilingual & Multicurrency with WPML Compatibility
4 *
5 * @package
6 */
7 namespace WPFunnels\Compatibility\Plugin;
8
9
10 use WPFunnels\Traits\SingletonTrait;
11 use WC_Session_Handler;
12 use WPFunnels\Wpfnl_functions;
13 use WPFunnels\Discount\WpfnlDiscount;
14 use WPFunnels\Modules\Frontend\CheckoutHelper\CheckoutHelper;
15 /**
16 * WooCommerce Multilingual & Multicurrency with WPML Compatibility
17 *
18 * @package WPFunnels\Compatibility\Plugin\Wcml;
19 */
20 class Wcml {
21
22 use SingletonTrait;
23
24
25 /**
26 * Filters/Hook from Twenty Twenty Two
27 *
28 * @return void
29 * @since 3.1.8
30 */
31 public function init() {
32
33 if ($this->maybe_activate() && Wpfnl_functions::is_funnel_checkout_page()) {
34 add_action('plugins_loaded', array($this, 'remove_wcml_refresh_cart_total_hook'));
35
36 // Hook to save checkout fields
37 add_action('woocommerce_checkout_update_order_meta', array($this, 'save_checkout_fields'), 10, 2);
38
39 add_action('wp', array($this, 'add_widget_hooks'));
40
41 add_filter('wpfunnels/modify_offer_product_price_data_without_discount', [$this,'get_updated_price'], 10 );
42 add_filter('wpfunnels/modify_offer_product_price_data_with_discount', [$this,'get_updated_price'], 10 );
43
44 }
45 }
46
47 /**
48 * Add widget hooks
49 *
50 * @return void
51 * @since 3.1.8
52 */
53 public function add_widget_hooks() {
54 global $post;
55
56 if ( isset($_REQUEST['wc-ajax']) && ( 'apply_coupon' === $_REQUEST['wc-ajax'] || 'wc_stripe_get_cart_details' === $_REQUEST['wc-ajax'] ) ) {
57 return;
58 }
59
60 if(
61 is_admin()
62 || isset( $_GET[ 'removed_item' ] )
63 || wp_doing_ajax()
64 || !$post
65 ) {
66 return;
67 }
68
69
70 $checkout_id = $post->ID;
71 if( !$checkout_id ) {
72 return;
73 }
74
75 // Returns if the post id is not funnel checkout type.
76 if(
77 !Wpfnl_functions::check_if_this_is_step_type_by_id( $checkout_id, 'checkout' )
78 || !Wpfnl_functions::check_if_this_is_step_type( 'checkout' )
79 || Wpfnl_functions::is_orderbump_clicked_from_post_data()
80 || Wpfnl_functions::is_checkoutify_orderbump_clicked_from_post_data()
81 || Wpfnl_functions::is_variation_selected_from_post_data()
82 || Wpfnl_functions::maybe_select_quantity_from_post_data()
83 // || Wpfnl_functions::is_coupon_applied_from_post_data()
84 ) {
85 return;
86 }
87
88 if( isset($_REQUEST['wc-ajax']) && Wpfnl_functions::is_wc_active() && !WC()->cart->is_empty() && WC()->cart->has_discount()){
89 return;
90 }
91
92 $funnel_id = get_post_meta( $checkout_id, '_funnel_id', true );
93
94 // Returns in case of invalid funnel id or if the funnel id is `lms` type.
95 if( !$funnel_id || 'lms' === get_post_meta( $funnel_id, '_wpfnl_funnel_type', true ) ) {
96 return;
97 }
98
99 $widget_position = get_post_meta( $checkout_id, '_wpfnl_wpml_Widget_Position_on_checkout', true );
100 if( $widget_position ) {
101 add_action( $widget_position, array( $this, 'add_wpml_widget' ), 10 );
102 }
103 }
104
105 /**
106 * Add WPML widget
107 *
108 * @return void
109 * @since 3.1.8
110 */
111 public function add_wpml_widget(){
112
113 echo( do_shortcode( '[currency_switcher]' ) );
114 }
115
116
117 /**
118 * Remove wcml_refresh_cart_total action
119 *
120 * @return void
121 * @since 3.1.8
122 */
123 public function remove_wcml_refresh_cart_total_hook() {
124 remove_action('woocommerce_before_checkout_process', array('\WCML_Cart', 'wcml_refresh_cart_total'));
125 }
126
127
128
129
130 /**
131 * Save checkout metas
132 *
133 * @param $order_id
134 * @param $posted
135 *
136 * @since 3.1.8
137 */
138 public function save_checkout_fields( $order_id, $posted )
139 {
140 // Instantiate the CheckoutModuleHelper
141 $helper = CheckoutHelper::getInstance();
142
143 if (isset($_POST['_wpfunnels_checkout_id'])) {
144 $helper->update_checkout_id_post_meta($order_id, sanitize_text_field( $_POST['_wpfunnels_checkout_id'] ) );
145 if (isset($_POST['_wpfunnels_funnel_id'])) {
146 $funnel_id = $helper->update_order_meta_for_funnel($order_id, sanitize_text_field($_POST['_wpfunnels_funnel_id']));
147 }
148 if (isset($_POST['_wpfunnels_order_unique_identifier'])) {
149 $helper->update_unique_identifier_post_meta($order_id, sanitize_text_field($_POST['_wpfunnels_order_unique_identifier']));
150 }
151 $order_bump_products = get_post_meta( $_POST['_wpfunnels_checkout_id'], 'order-bump-settings' , true );
152 $helper->update_order_bump_product( $order_bump_products, $order_id );
153 }
154
155 if (isset($funnel_id)) {
156 $order = Wpfnl_functions::is_wc_active() ? wc_get_order($order_id) : null;
157 $funnel_id = $helper->update_order_meta_for_funnel($order_id, sanitize_text_field( $_POST['_wpfunnels_funnel_id']) );
158
159 if( $funnel_id ){
160 $discount_instance = new WpfnlDiscount();
161
162 if( !$discount_instance->maybe_time_bound_discount( $_POST['_wpfunnels_checkout_id'] ) || ($discount_instance->maybe_time_bound_discount( $_POST['_wpfunnels_checkout_id'] ) && $discount_instance->maybe_validate_discount_time( $_POST['_wpfunnels_checkout_id'] )) ){
163 $discount = $discount_instance->get_discount_settings( $_POST['_wpfunnels_checkout_id'] );
164 $main_products = $helper->get_main_products( $_POST['_wpfunnels_checkout_id'], $funnel_id );
165
166 $variable_product_check = $helper->variable_product_check( $order->get_items(), $main_products, false );
167 $main_products = isset( $variable_product_check['main_products'] ) ? $variable_product_check['main_products'] : $main_products;
168
169 $is_main_product_in_cart = isset( $variable_product_check['is_main_product_in_cart'] ) ? $variable_product_check['is_main_product_in_cart'] : false;
170 $total = $helper->get_custom_subtotal();
171 $response = $helper->apply_discount_and_update_total( $order, $total, $discount, $is_main_product_in_cart);
172 }
173 }
174 $user_id = $order->get_user_id();
175 $orders[sanitize_text_field($_POST['_wpfunnels_checkout_id'])] = $order_id;
176 WC()->session->set('wpfnl_orders_'.$user_id.'_'.$funnel_id, $orders);
177
178 $session_handler = new WC_Session_Handler();
179 WC()->session->set('wpfnl_order_owner', $session_handler->generate_customer_id());
180
181 /**
182 * Fires after a funnel order is placed.
183 *
184 * @since 1.0.0
185 *
186 * @param int $order_id The ID of the order.
187 * @param string $funnel_id The ID of the funnel.
188 * @param string $_POST['_wpfunnels_checkout_id'] The checkout ID associated with the order.
189 */
190 do_action( 'wpfunnels/funnel_order_placed', $order_id, $funnel_id, $_POST['_wpfunnels_checkout_id'] );
191 }
192 }
193
194
195 /**
196 * Retrieves the updated price of a product.
197 *
198 * @param float $product_price The original price of the product.
199 * @return float The updated price of the product.
200 *
201 * @since 3.1.8
202 */
203 public function get_updated_price( $product_price ) {
204 global $woocommerce_wpml;
205 $multi_currency = new \WCML_Multi_Currency();
206 $price_instance = new \WCML_Multi_Currency_Prices( $multi_currency, $woocommerce_wpml->get_setting( 'currency_options' ) );
207 $new_price = $price_instance->raw_price_filter( $product_price );
208 return $new_price;
209 }
210
211
212 /**
213 * Check if WooCommerce Multilingual plugin is activated
214 *
215 * @return bool
216 * @since 3.1.8
217 */
218 public function maybe_activate() {
219 return defined('WCML_VERSION');
220 }
221 }
222