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

212 lines 6.0 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 /**
48 * Apply multi-step functionality.
49 *
50 * @return void
51 * @since 1.1.0
52 */
53 private function apply_multi_step_design( $settings ) {
54 new Multi_Step( $settings );
55 }
56
57 /**
58 * Apply local hooks.
59 *
60 * @return void
61 * @since 1.1.0
62 */
63 private function apply_local_hooks( $settings ) {
64 new Local_Hooks( $settings, $this );
65 }
66
67 protected function register_controls() {
68 require __DIR__ . '/settings-controls.php';
69 require __DIR__ . '/style-controls.php';
70
71 new Settings_Controls();
72 new Style_Controls();
73 }
74
75 protected function render() {
76 add_filter( 'woocommerce_is_checkout', function() {
77 return true;
78 }, 10 );
79
80 $settings = $this->get_settings_for_display();
81
82 $this->clear_sellkit_checkout_custom_hooks( $settings );
83
84 if ( 'multi-step' === $settings['layout-type'] ) {
85 $this->apply_multi_step_design( $settings );
86 }
87
88 $this->apply_local_hooks( $settings );
89
90 if ( 'one-page' === $settings['layout-type'] ) {
91 $this->add_render_attribute(
92 'wrapper',
93 'class',
94 'sellkit-checkout-widget-one-page-build sellkit-checkout-widget-main-wrapper'
95 );
96 } else {
97 $this->add_render_attribute(
98 'wrapper',
99 'class',
100 'sellkit-checkout-widget-multi-page-build sellkit-checkout-widget-main-wrapper'
101 );
102 }
103
104 if ( Elementor::$instance->editor->is_edit_mode() ) {
105 $current_user = wp_get_current_user()->ID;
106 wp_set_current_user( 0 );
107 }
108
109 echo '<div ' . $this->get_render_attribute_string( 'wrapper' ) . ' >';
110 echo do_shortcode( '[woocommerce_checkout]' );
111 echo do_shortcode( '[sellkit_checkout_widget_simulated]' );
112 echo '</div>';
113
114 do_action( 'sellkit-after-checkout-content', $settings );
115
116 if ( Elementor::$instance->editor->is_edit_mode() ) {
117 wp_set_current_user( $current_user );
118 }
119
120 }
121
122 /**
123 * Remove every function attached to sellkit checkout custom hooks.
124 *
125 * @param array $settings widget settings.
126 * @since 1.1.0
127 * @return void
128 */
129 private function clear_sellkit_checkout_custom_hooks( $settings ) {
130 // Removed function that attached to custom hooks to prevent any error.
131 remove_all_actions( 'sellkit-checkout-cart-item' );
132 remove_all_actions( 'sellkit-checkout-step-a-begins' );
133 remove_all_actions( 'sellkit-checkout-step-a-ends' );
134 remove_all_actions( 'sellkit-checkout-step-b-begins' );
135 remove_all_actions( 'sellkit-checkout-step-b-ends' );
136 remove_all_actions( 'sellkit-checkout-widget-step-two-header' );
137 remove_all_actions( 'sellkit-checkout-step-c-begins' );
138 remove_all_actions( 'sellkit-checkout-multistep-third-step-back-btn' );
139 remove_all_actions( 'sellkit-checkout-step-c-ends' );
140 remove_all_actions( 'sellkit-checkout-widget-step-three-header' );
141 remove_all_actions( 'sellkit-checkout-multistep-sidebar-begins' );
142 remove_all_actions( 'sellkit-checkout-multistep-sidebar-ends' );
143 remove_all_actions( 'sellkit-checkout-widget-breadcrumb-desktop' );
144 remove_all_actions( 'sellkit-checkout-widget-breadcrumb-mobile' );
145
146 remove_all_actions( 'sellkit_checkout_shipping_fields' );
147 remove_all_actions( 'sellkit_checkout_billing_fields' );
148
149 remove_all_actions( 'sellkit_checkout_after_shipping_section' );
150
151 remove_all_actions( 'sellkit_checkout_one_page_express_methods' );
152
153 remove_all_actions( 'sellkit-checkout-widget-custom-coupon-form' );
154
155 remove_all_filters( 'woocommerce_locate_template' );
156
157 if ( Elementor::$instance->editor->is_edit_mode() ) {
158 $this->editor_mode( $settings );
159 }
160 }
161
162 /**
163 * Editor mode, Render widget content on clicking it's wrapper.
164 *
165 * @since 1.1.0
166 * @return void
167 */
168 private function editor_mode( $settings ) {
169 add_action( 'sellkit_checkout_required_hidden_fields', function() {
170 echo '<input type="hidden" name="sellkit-elementor-editor-mode" value="true" >';
171 } );
172
173 // Some frontend Hooks doesn't work in editor mode.
174 // So we just hide them in editor mode, BUT we use real hooks in frontend.
175 // Purpose is to increase user experience in editor mode.
176
177 if ( 'yes' !== $settings['show_cart_items'] ) {
178 $this->hide_items_in_editor( 'cart_item' );
179 }
180
181 if ( 'yes' !== $settings['show_cart_edit'] ) {
182 $this->hide_items_in_editor( 'sellkit-one-page-checkout-product-qty' );
183
184 add_action( 'sellkit-checkout-widget-disable-quantity', [ Helper::instance(), 'checkout_order_hidden_quantity' ], 10, 2 );
185 }
186
187 if ( 'yes' !== $settings['show_shipping_method'] ) {
188 $this->hide_items_in_editor( 'sellkit-one-page-shipping-methods' );
189 }
190
191 add_action( 'sellkit-checkout-widget-custom-coupon-form', function() use ( $settings ) {
192 Local_Hooks::coupon_form( $settings );
193 } );
194
195 if ( 'yes' !== $settings['show_coupon_field'] ) {
196 $this->hide_items_in_editor( 'coupon-form' );
197 }
198
199 if ( 'yes' !== $settings['order_summary_show_image'] ) {
200 $this->hide_items_in_editor( 'sellkit-checkout-widget-item-image' );
201 }
202 }
203
204 private function hide_items_in_editor( $class ) {
205 echo sprintf(
206 /** Translators : %s : class name */
207 '<style>.%s { display:none !important; }</style>',
208 $class
209 );
210 }
211 }
212