PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
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 2.8.17 2.8.18 All 259 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.13.1, at includes/core/compatibility/plugin/class-wpfnl-wcml.php

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