PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.7.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.7.2
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.2, at includes/elementor/modules/checkout/widgets/checkout.php

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