PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.7.5
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.7.5
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / elementor / modules / checkout / widgets / checkout.php

checkout.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.7.5, at includes/elementor/modules/checkout/widgets/checkout.php

243 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || die();
4
5 use Sellkit\Elementor\Modules\Checkout\Widgets\{ Settings_Controls, Style_Controls };
6 use Sellkit\Elementor\Modules\Checkout\Classes\{Global_Hooks, Local_Hooks, Multi_Step, Helper };
7 use Elementor\Plugin as Elementor;
8 use Sellkit\Global_Checkout\Checkout;
9
10 /**
11 * Checkout class.
12 *
13 * @since 1.1.0
14 */
15 class Sellkit_Elementor_Checkout_Widget extends Sellkit_Elementor_Base_Widget {
16
17 public function __construct( $data = [], $args = null ) {
18 parent::__construct( $data, $args );
19
20 add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'frontend_enqueue_scripts' ], 10 );
21 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'editor_enqueue_scripts' ], 10 );
22 }
23
24 public function get_name() {
25 return 'sellkit-checkout';
26 }
27
28 public function get_title() {
29 return __( 'Checkout Form', 'sellkit' );
30 }
31
32 public function get_icon() {
33 return 'sellkit-element-icon sellkit-checkout-icon';
34 }
35
36 public function frontend_enqueue_scripts() {
37 wp_enqueue_script( 'wc-checkout' );
38 }
39
40 public function editor_enqueue_scripts() {
41 wp_enqueue_script( 'wc-checkout' );
42 }
43
44 public function is_reload_preview_required() {
45 return true;
46 }
47
48 public function get_style_depends() {
49 return [ 'font-awesome' ];
50 }
51
52 /**
53 * Apply multi-step functionality.
54 *
55 * @return void
56 * @since 1.1.0
57 */
58 private function apply_multi_step_design( $settings ) {
59 new Multi_Step( $settings );
60 }
61
62 /**
63 * Apply local hooks.
64 *
65 * @return void
66 * @since 1.1.0
67 */
68 private function apply_local_hooks( $settings ) {
69 new Local_Hooks( $settings, $this );
70 }
71
72 protected function register_controls() {
73 require_once __DIR__ . '/settings-controls.php';
74 require_once __DIR__ . '/style-controls.php';
75
76 new Settings_Controls();
77 new Style_Controls();
78 }
79
80 protected function render() {
81 $settings = $this->get_settings_for_display();
82 $checkout_id = get_the_ID();
83 $step_data = get_post_meta( $checkout_id, 'step_data', true );
84 $global_checkout = apply_filters( 'sellkit_global_checkout_activated', false );
85 $global_checkout_id = get_option( Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, 0 );
86 $current_funnel_id = ( ! empty( $step_data ) ) ? $step_data['funnel_id'] : -1;
87
88 if (
89 false === $global_checkout &&
90 intval( $global_checkout_id ) !== intval( $current_funnel_id ) &&
91 is_array( $step_data ) &&
92 (
93 ! array_key_exists( 'data', $step_data ) ||
94 ! array_key_exists( 'list', $step_data['data']['products'] )
95 )
96 ) {
97 /* translators: %s: Empty cart message. */
98 echo sprintf(
99 '<div class="elementor-alert elementor-alert-info sellkit-checkout-empty-cart-message-box">%s</div>',
100 $settings['empty_cart']
101 );
102 return;
103 }
104
105 add_filter( 'woocommerce_is_checkout', function() {
106 return true;
107 }, 10 );
108
109 $this->clear_sellkit_checkout_custom_hooks( $settings );
110
111 if ( 'multi-step' === $settings['layout-type'] ) {
112 $this->apply_multi_step_design( $settings );
113 }
114
115 $this->apply_local_hooks( $settings );
116
117 if ( 'one-page' === $settings['layout-type'] ) {
118 $this->add_render_attribute(
119 'wrapper',
120 'class',
121 'sellkit-checkout-widget-one-page-build sellkit-checkout-widget-main-wrapper'
122 );
123 } else {
124 $this->add_render_attribute(
125 'wrapper',
126 'class',
127 'sellkit-checkout-widget-multi-page-build sellkit-checkout-widget-main-wrapper'
128 );
129 }
130
131 if ( Elementor::$instance->editor->is_edit_mode() ) {
132 $current_user = wp_get_current_user()->ID;
133 wp_set_current_user( 0 );
134 }
135
136 echo '<div ' . $this->get_render_attribute_string( 'wrapper' ) . ' >';
137 echo do_shortcode( '[woocommerce_checkout]' );
138 echo do_shortcode( '[sellkit_checkout_widget_simulated]' );
139 echo '</div>';
140
141 do_action( 'sellkit-after-checkout-content', $settings );
142
143 if ( Elementor::$instance->editor->is_edit_mode() ) {
144 wp_set_current_user( $current_user );
145 }
146
147 }
148
149 /**
150 * Remove every function attached to sellkit checkout custom hooks.
151 *
152 * @param array $settings widget settings.
153 * @since 1.1.0
154 * @return void
155 */
156 private function clear_sellkit_checkout_custom_hooks( $settings ) {
157 // Removed function that attached to custom hooks to prevent any error.
158 remove_all_actions( 'sellkit-checkout-cart-item' );
159 remove_all_actions( 'sellkit-checkout-step-a-begins' );
160 remove_all_actions( 'sellkit-checkout-step-a-ends' );
161 remove_all_actions( 'sellkit-checkout-step-b-begins' );
162 remove_all_actions( 'sellkit-checkout-step-b-ends' );
163 remove_all_actions( 'sellkit-checkout-widget-step-two-header' );
164 remove_all_actions( 'sellkit-checkout-step-c-begins' );
165 remove_all_actions( 'sellkit-checkout-multistep-third-step-back-btn' );
166 remove_all_actions( 'sellkit-checkout-step-c-ends' );
167 remove_all_actions( 'sellkit-checkout-widget-step-three-header' );
168 remove_all_actions( 'sellkit-checkout-multistep-sidebar-begins' );
169 remove_all_actions( 'sellkit-checkout-multistep-sidebar-ends' );
170 remove_all_actions( 'sellkit-checkout-widget-breadcrumb-desktop' );
171 remove_all_actions( 'sellkit-checkout-widget-breadcrumb-mobile' );
172
173 remove_all_actions( 'sellkit_checkout_shipping_fields' );
174 remove_all_actions( 'sellkit_checkout_billing_fields' );
175
176 remove_all_actions( 'sellkit_checkout_after_shipping_section' );
177
178 remove_all_actions( 'sellkit_checkout_one_page_express_methods' );
179
180 remove_all_actions( 'sellkit-checkout-widget-custom-coupon-form' );
181
182 remove_all_filters( 'woocommerce_locate_template' );
183
184 // !TODO We can use this method to move / remove billing and shipping fields.
185 add_action( 'woocommerce_checkout_shipping', [ WC()->checkout(), 'checkout_form_shipping' ] ); // ! added for theme integration. Astra.
186 remove_action( 'woocommerce_checkout_billing', [ WC()->checkout(), 'checkout_form_shipping' ] ); // ! added for theme integration. Astra.
187
188 if ( Elementor::$instance->editor->is_edit_mode() ) {
189 $this->editor_mode( $settings );
190 }
191 }
192
193 /**
194 * Editor mode, Render widget content on clicking it's wrapper.
195 *
196 * @since 1.1.0
197 * @return void
198 */
199 private function editor_mode( $settings ) {
200 add_action( 'sellkit_checkout_required_hidden_fields', function() {
201 echo '<input type="hidden" name="sellkit-elementor-editor-mode" value="true" >';
202 } );
203
204 // Some frontend Hooks doesn't work in editor mode.
205 // So we just hide them in editor mode, BUT we use real hooks in frontend.
206 // Purpose is to increase user experience in editor mode.
207
208 if ( 'yes' !== $settings['show_cart_items'] ) {
209 $this->hide_items_in_editor( 'cart_item' );
210 }
211
212 if ( 'yes' !== $settings['show_cart_edit'] ) {
213 $this->hide_items_in_editor( 'sellkit-one-page-checkout-product-qty' );
214
215 add_filter( 'sellkit-checkout-widget-disable-quantity', [ Helper::instance(), 'checkout_order_hidden_quantity' ], 10, 2 );
216 }
217
218 if ( 'yes' !== $settings['show_shipping_method'] ) {
219 $this->hide_items_in_editor( 'sellkit-one-page-shipping-methods' );
220 }
221
222 add_action( 'sellkit-checkout-widget-custom-coupon-form', function() use ( $settings ) {
223 Local_Hooks::coupon_form( $settings );
224 } );
225
226 if ( 'yes' !== $settings['show_coupon_field'] ) {
227 $this->hide_items_in_editor( 'coupon-form' );
228 }
229
230 if ( 'yes' !== $settings['order_summary_show_image'] ) {
231 $this->hide_items_in_editor( 'sellkit-checkout-widget-item-image' );
232 }
233 }
234
235 private function hide_items_in_editor( $class ) {
236 echo sprintf(
237 /** Translators : %s : class name */
238 '<style>.%s { display:none !important; }</style>',
239 $class
240 );
241 }
242 }
243