PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.5.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.5.0
4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Integrations / Elementor / Widgets / ProductQuickAddButton.php
surecart / app / src / Integrations / Elementor / Widgets Last commit date
AddToCartButton.php 3 months ago CartMenuIcon.php 1 year ago CollectionTags.php 1 year ago Media.php 1 year ago PriceChooser.php 1 year ago Product.php 1 year ago ProductCard.php 1 year ago ProductContent.php 7 months ago ProductLineItemNote.php 10 months ago ProductPricing.php 1 year ago ProductQuickAddButton.php 7 months ago ProductReviewAverageRatingStars.php 4 months ago ProductReviewAverageRatingValue.php 4 months ago ProductReviewBreakdown.php 4 months ago ProductReviewContent.php 4 months ago ProductReviewList.php 2 months ago ProductReviewRating.php 4 months ago ProductReviewTotalRating.php 4 months ago ProductReviews.php 4 months ago Quantity.php 1 year ago ReusableFormWidget.php 1 year ago SaleBadge.php 1 year ago SelectedPriceAdHocAmount.php 1 year ago VariantPills.php 6 months ago
ProductQuickAddButton.php
423 lines
1 <?php
2
3 namespace SureCart\Integrations\Elementor\Widgets;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 /**
10 * Product Quick Add Button widget.
11 */
12 class ProductQuickAddButton extends \Elementor\Widget_Base {
13 /**
14 * Default icon.
15 */
16 public const DEFAULT_ICON = array(
17 'value' => 'fas fa-plus',
18 'library' => 'fa-solid',
19 );
20
21 /**
22 * Get widget name.
23 *
24 * @return string
25 */
26 public function get_name() {
27 return 'surecart-product-quick-add-button';
28 }
29
30 /**
31 * Get widget title.
32 *
33 * @return string
34 */
35 public function get_title() {
36 return esc_html__( 'Product Quick Add Button', 'surecart' );
37 }
38
39 /**
40 * Get widget icon.
41 *
42 * @return string
43 */
44 public function get_icon() {
45 return 'eicon-plus-square';
46 }
47
48 /**
49 * Get the widget keywords.
50 *
51 * @return array
52 */
53 public function get_keywords() {
54 return array( 'surecart', 'shop', 'button', 'quick' );
55 }
56
57 /**
58 * Get the widget categories.
59 *
60 * @return array
61 */
62 public function get_categories() {
63 return array( 'surecart-elementor-elements' );
64 }
65
66 /**
67 * Get the default button label.
68 *
69 * @return string
70 */
71 protected function get_default_label(): string {
72 return esc_html__( 'Add', 'surecart' );
73 }
74
75 /**
76 * Get the style dependencies.
77 *
78 * @return array
79 */
80 public function get_style_depends() {
81 return array( 'surecart-wp-buttons', 'surecart-wp-button', 'wp-block-button', 'surecart-product-quick-view-button' );
82 }
83
84 /**
85 * Register the widget content settings.
86 *
87 * @return void
88 */
89 protected function register_content_settings() {
90 $this->start_controls_section(
91 'section_design',
92 [
93 'label' => esc_html__( 'Design', 'surecart' ),
94 ]
95 );
96
97 $this->add_control(
98 'label',
99 [
100 'label' => esc_html__( 'Button Text', 'surecart' ),
101 'type' => \Elementor\Controls_Manager::TEXT,
102 'default' => $this->get_default_label(),
103 ]
104 );
105
106 $this->add_control(
107 'icon_position',
108 [
109 'label' => esc_html__( 'Icon Position', 'surecart' ),
110 'type' => \Elementor\Controls_Manager::SELECT,
111 'default' => 'before',
112 'options' => [
113 'before' => esc_html__( 'Before', 'surecart' ),
114 'after' => esc_html__( 'After', 'surecart' ),
115 ],
116 ]
117 );
118
119 $this->add_control(
120 'quick_view_button_type',
121 [
122 'label' => esc_html__( 'Icon & Text', 'surecart' ),
123 'type' => \Elementor\Controls_Manager::SELECT,
124 'default' => 'both',
125 'options' => [
126 'icon' => esc_html__( 'Icon', 'surecart' ),
127 'text' => esc_html__( 'Text', 'surecart' ),
128 'both' => esc_html__( 'Both', 'surecart' ),
129 ],
130 ]
131 );
132
133 $this->add_control(
134 'show_on_hover',
135 array(
136 'label' => esc_html__( 'Show on Hover', 'surecart' ),
137 'type' => \Elementor\Controls_Manager::SWITCHER,
138 'label_on' => esc_html__( 'Yes', 'surecart' ),
139 'label_off' => esc_html__( 'No', 'surecart' ),
140 'default' => 'no',
141 )
142 );
143
144 $this->end_controls_section();
145
146 $this->start_controls_section(
147 'section_settings',
148 [
149 'label' => esc_html__( 'Settings', 'surecart' ),
150 ]
151 );
152
153 $this->add_control(
154 'direct_add_to_cart',
155 array(
156 'label' => esc_html__( 'Direct add to cart', 'surecart' ),
157 'type' => \Elementor\Controls_Manager::SWITCHER,
158 'label_on' => esc_html__( 'Yes', 'surecart' ),
159 'label_off' => esc_html__( 'No', 'surecart' ),
160 'return_value' => 'yes',
161 'default' => 'yes',
162 )
163 );
164
165 $this->end_controls_section();
166
167 $this->start_controls_section(
168 'section_icon_settings',
169 [
170 'label' => esc_html__( 'Icon', 'surecart' ),
171 ]
172 );
173
174 $this->add_control(
175 'selected_icon',
176 [
177 'label' => esc_html__( 'Icon', 'surecart' ),
178 'type' => \Elementor\Controls_Manager::ICONS,
179 'fa4compatibility' => 'icon',
180 'skin' => 'inline',
181 'label_block' => false,
182 'recommended' => [
183 'fa-solid' => [
184 'plus',
185 ],
186 ],
187 'default' => self::DEFAULT_ICON,
188 ]
189 );
190
191 $this->end_controls_section();
192 }
193
194 /**
195 * Register the widget style settings.
196 *
197 * @return void
198 */
199 protected function register_style_settings() {
200 $button_selector = '{{WRAPPER}} .wp-block-surecart-product-quick-view-button';
201 $button_icon_selector = '{{WRAPPER}} .elementor-button-icon svg';
202
203 $this->start_controls_section(
204 'section_style',
205 [
206 'label' => esc_html__( 'Button', 'surecart' ),
207 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
208 ]
209 );
210
211 $this->add_group_control(
212 \Elementor\Group_Control_Typography::get_type(),
213 [
214 'name' => 'button_typography',
215 'global' => [
216 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY,
217 ],
218 'fields_options' => [
219 'typography' => [ 'default' => 'yes' ],
220 'line_height' => [
221 'default' => [
222 'unit' => 'px',
223 'size' => 16,
224 ],
225 ],
226 ],
227 'selector' => $button_selector,
228 ]
229 );
230
231 $this->add_control(
232 'content_align',
233 [
234 'label' => esc_html__( 'Content Alignment', 'surecart' ),
235 'type' => \Elementor\Controls_Manager::CHOOSE,
236 'options' => [
237 'flex-start' => [
238 'title' => esc_html__( 'Start', 'surecart' ),
239 'icon' => 'eicon-h-align-left',
240 ],
241 'center' => [
242 'title' => esc_html__( 'Center', 'surecart' ),
243 'icon' => 'eicon-h-align-center',
244 ],
245 'flex-end' => [
246 'title' => esc_html__( 'End', 'surecart' ),
247 'icon' => 'eicon-h-align-right',
248 ],
249 ],
250 'default' => 'flex-start',
251 'selectors' => [
252 $button_selector => 'justify-content: {{VALUE}};',
253 ],
254 ]
255 );
256
257 $this->add_control(
258 'button_text_color',
259 [
260 'label' => esc_html__( 'Text Color', 'surecart' ),
261 'type' => \Elementor\Controls_Manager::COLOR,
262 'selectors' => [
263 $button_selector => 'color: {{VALUE}}',
264 $button_icon_selector => 'fill: {{VALUE}}',
265 ],
266 'default' => '#ffffff',
267 ]
268 );
269
270 $this->add_control(
271 'button_background_color',
272 [
273 'label' => esc_html__( 'Background Color', 'surecart' ),
274 'type' => \Elementor\Controls_Manager::COLOR,
275 'selectors' => [
276 $button_selector => 'background-color: {{VALUE}}',
277 ],
278 ]
279 );
280
281 $this->add_group_control(
282 \Elementor\Group_Control_Border::get_type(),
283 [
284 'name' => 'border',
285 'selector' => $button_selector,
286 ]
287 );
288
289 $this->add_control(
290 'border_radius',
291 array(
292 'label' => esc_html__( 'Border Radius', 'surecart' ),
293 'type' => \Elementor\Controls_Manager::DIMENSIONS,
294 'size_units' => [ 'px', 'em', '%' ],
295 'selectors' => array(
296 $button_selector => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
297 ),
298 )
299 );
300
301 $this->add_responsive_control(
302 'padding',
303 [
304 'type' => \Elementor\Controls_Manager::DIMENSIONS,
305 'label' => esc_html__( 'Padding', 'surecart' ),
306 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
307 'selectors' => [
308 $button_selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
309 ],
310 ]
311 );
312
313 $this->add_responsive_control(
314 'margin',
315 [
316 'type' => \Elementor\Controls_Manager::DIMENSIONS,
317 'label' => esc_html__( 'Margin', 'surecart' ),
318 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
319 'selectors' => [
320 $button_selector => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
321 ],
322 ]
323 );
324
325 $this->end_controls_section();
326 }
327
328 /**
329 * Register the widget controls.
330 *
331 * @return void
332 */
333 protected function register_controls() {
334 $this->register_content_settings();
335 $this->register_style_settings();
336 }
337
338 /**
339 * Render the widget output on the frontend.
340 *
341 * @return void
342 */
343 protected function render() {
344 $settings = $this->get_settings_for_display();
345 $product_id = get_the_ID();
346 $product = sc_get_product();
347 $is_add_to_cart = ! empty( $settings['direct_add_to_cart'] ) && 'yes' === $settings['direct_add_to_cart'];
348 $should_direct_add = $is_add_to_cart && empty( $product->has_options );
349 $show_on_hover_class = 'yes' === $settings['show_on_hover'] ? 'is-style-show-on-hover ' : '';
350 $attributes = array(
351 'icon_position' => $settings['icon_position'] ?? 'before',
352 'quick_view_button_type' => $settings['quick_view_button_type'] ?? 'both',
353 'label' => $settings['label'] ?? $this->get_default_label(),
354 );
355 $show_icon = in_array( $attributes['quick_view_button_type'], [ 'icon', 'both' ], true ) && ( ! empty( $settings['icon'] ) || ! empty( $settings['selected_icon']['value'] ) );
356 $show_text = in_array( $attributes['quick_view_button_type'], [ 'text', 'both' ], true );
357 $quick_view_link = add_query_arg( 'product-quick-view', $product_id );
358 $is_disabled = empty( $quick_view_link ) ? 'true' : null;
359
360 if ( $should_direct_add ) {
361 $is_disabled = empty( $product->in_stock ) ? 'true' : null;
362 $aria_label = empty( $product->in_stock ) ? __( 'Sold Out', 'surecart' ) : __( 'Add to Cart', 'surecart' );
363
364 $this->add_render_attribute( 'quick-add-button', 'disabled', $is_disabled );
365 $this->add_render_attribute( 'quick-add-button', 'aria-label', $aria_label );
366 $this->add_render_attribute( 'quick-add-button', 'data-wp-on--click', 'callbacks.handleSubmit' );
367 $this->add_render_attribute( 'quick-add-button', 'data-wp-on--keydown', 'callbacks.handleSubmit' );
368 } else {
369 $this->add_render_attribute(
370 'quick-add-button',
371 'data-wp-context',
372 wp_json_encode(
373 [
374 'url' => sanitize_url( $quick_view_link ),
375 ],
376 JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP
377 )
378 );
379 $this->add_render_attribute( 'quick-add-button', 'aria-label', __( 'Quick Add Product', 'surecart' ) );
380 $this->add_render_attribute( 'quick-add-button', 'data-wp-on--click', 'actions.open' );
381 $this->add_render_attribute( 'quick-add-button', 'data-wp-on--keydown', 'actions.open' );
382 $this->add_render_attribute( 'quick-add-button', 'data-wp-on--mouseenter', 'actions.prefetch' );
383 $this->add_render_attribute( 'quick-add-button', 'data-wp-interactive', '{ "namespace": "surecart/product-quick-view" }' );
384 }
385
386 $this->add_render_attribute( 'quick-add-button', 'class', 'wp-block-surecart-product-quick-view-button wp-block-button__link sc-button__link elementor-button elementor-button-link elementor-size-sm ' . $show_on_hover_class );
387 $this->add_render_attribute( 'quick-add-button', 'data-wp-class--loading', 'state.loading' );
388 $this->add_render_attribute( 'quick-add-button', 'data-wp-class--sc-button__link--busy', 'state.loading' );
389 $this->add_render_attribute( 'quick-add-button', 'aria-disabled', $is_disabled );
390
391 if ( $show_icon && ! empty( $settings['selected_icon']['value'] ) ) {
392 $this->add_render_attribute( 'icon', 'class', 'elementor-button-icon' );
393 }
394
395 if ( ! \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
396 \SureCart::block()->quickView()->render();
397 }
398
399 ?>
400 <div
401 role="button"
402 tabindex="0"
403 <?php echo $this->get_render_attribute_string( 'quick-add-button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
404 >
405 <span class="sc-spinner" aria-hidden="true"></span>
406 <?php if ( $show_icon && 'before' === $attributes['icon_position'] ) : ?>
407 <span <?php echo $this->get_render_attribute_string( 'icon' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
408 <?php \Elementor\Icons_Manager::render_icon( $settings['selected_icon'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
409 </span>
410 <?php endif; ?>
411 <?php if ( $show_text ) : ?>
412 <span class="sc-button__link-text"><?php echo esc_html( empty( $product->in_stock ) ? __( 'Sold Out', 'surecart' ) : $attributes['label'] ); ?></span>
413 <?php endif; ?>
414 <?php if ( $show_icon && 'after' === $attributes['icon_position'] ) : ?>
415 <span <?php echo $this->get_render_attribute_string( 'icon' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
416 <?php \Elementor\Icons_Manager::render_icon( $settings['selected_icon'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
417 </span>
418 <?php endif; ?>
419 </div>
420 <?php
421 }
422 }
423