PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.3
ShopBuilder – WooCommerce Builder For Elementor v2.6.3
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Elementor / Widgets / Single / ProductAddToCart.php

ProductAddToCart.php in ShopBuilder – WooCommerce Builder For Elementor 2.6.3, at app/Elementor/Widgets/Single/ProductAddToCart.php

210 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductDescription class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Elementor\Widgets\Single;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Abstracts\ElementorWidgetBase;
12 use RadiusTheme\SB\Elementor\Widgets\Controls\AddToCartSettings;
13
14 // Do not allow directly accessing this file.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit( 'This script cannot be accessed directly.' );
17 }
18
19 /**
20 * Product Description class
21 */
22 class ProductAddToCart extends ElementorWidgetBase {
23 /**
24 * Construct function
25 *
26 * @param array $data default array.
27 * @param mixed $args default arg.
28 */
29 public function __construct( $data = [], $args = null ) {
30 $this->rtsb_name = esc_html__( 'Product add to cart', 'shopbuilder' );
31 $this->rtsb_base = 'rtsb-product-add-to-cart';
32 parent::__construct( $data, $args );
33 }
34 /**
35 * Widget Field
36 *
37 * @return array
38 */
39 public function widget_fields() {
40 return AddToCartSettings::widget_fields( $this );
41 }
42 /**
43 * Set Widget Keyword.
44 *
45 * @return array
46 */
47 public function get_keywords() {
48 return [ 'Cart' ] + parent::get_keywords();
49 }
50 /**
51 * Widget Field.
52 *
53 * @param array $controllers Control.
54 *
55 * @return void
56 */
57 public function the_hooks() {
58 $controllers = $this->get_settings_for_display();
59 add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_false', 99 );
60 $product = Fns::get_product();
61 $is_visible_qty = Fns::is_visible_qty_input( $product );
62
63 if ( ! empty( $controllers['quantity_style'] ) && $is_visible_qty ) {
64 if ( in_array( $controllers['quantity_style'], [ 'style-1', 'style-2' ], true ) ) {
65 add_action( 'woocommerce_before_quantity_input_field', [ $this, 'quantity_wrapper_start' ] );
66 add_action( 'woocommerce_after_quantity_input_field', [ $this, 'quantity_wrapper_end' ] );
67 }
68
69 if ( in_array( $controllers['quantity_style'], [ 'style-3', 'style-4' ], true ) && $is_visible_qty ) {
70 add_action( 'woocommerce_before_quantity_input_field', [ $this, 'quantity_wrapper_with_inner_border' ] );
71 add_action( 'woocommerce_after_quantity_input_field', [ $this, 'close_quantity_wrapper' ] );
72 }
73 }
74
75 if ( $this->is_edit_mode() ) {
76 if ( class_exists( Rtwpvs\Controllers\Hooks::class ) ) {
77 remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 );
78 }
79
80 add_filter( 'woocommerce_ajax_variation_threshold', [ $this, 'override_ajax_variation_threshold' ], 99 );
81 }
82 }
83 /**
84 * Start quantity wrapper.
85 *
86 * @return void
87 */
88 public function reset_hooks() {
89 $controllers = $this->get_settings_for_display();
90 $product = Fns::get_product();
91 $is_visible_qty = Fns::is_visible_qty_input( $product );
92 if ( ! empty( $controllers['quantity_style'] ) && $is_visible_qty ) {
93 if ( in_array( $controllers['quantity_style'], [ 'style-1', 'style-2' ], true ) ) {
94 remove_action( 'woocommerce_before_quantity_input_field', [ $this, 'quantity_wrapper_start' ] );
95 remove_action( 'woocommerce_after_quantity_input_field', [ $this, 'quantity_wrapper_end' ] );
96 }
97
98 if ( in_array( $controllers['quantity_style'], [ 'style-3', 'style-4' ], true ) && $is_visible_qty ) {
99 remove_action( 'woocommerce_before_quantity_input_field', [ $this, 'quantity_wrapper_with_inner_border' ] );
100 remove_action( 'woocommerce_after_quantity_input_field', [ $this, 'close_quantity_wrapper' ] );
101 }
102 }
103 }
104 /**
105 * Start quantity wrapper.
106 *
107 * @return void
108 */
109 public function quantity_wrapper_start() {
110 $controllers = $this->get_settings_for_display();
111 ?>
112 <!-- Quantity Wrapper Start -->
113 <div class="rtsb-quantity-box-group">
114 <button type="button" class="rtsb-quantity-btn rtsb-quantity-minus">
115 <?php Fns::print_html( Fns::icons_manager( $controllers['decrement_icon'] ), true ); ?>
116 </button>
117 <?php
118 }
119
120 /**
121 * End quantity wrapper.
122 *
123 * @return void
124 */
125 public function quantity_wrapper_end() {
126 $controllers = $this->get_settings_for_display();
127 ?>
128 <button type="button" class="rtsb-quantity-btn rtsb-quantity-plus">
129 <?php Fns::print_html( Fns::icons_manager( $controllers['increment_icon'] ), true ); ?>
130 </button>
131 </div>
132 <!-- Quantity Wrapper End -->
133 <?php
134 }
135
136 /**
137 * Start quantity wrapper with inner border.
138 *
139 * @return void
140 */
141 public function quantity_wrapper_with_inner_border() {
142 $controllers = $this->get_settings_for_display();
143 $inner_border = ! empty( $controllers['show_inner_border'] ) ? 'show-inner-border' : '';
144 ?>
145 <!-- Quantity Wrapper Start -->
146 <div class="rtsb-quantity-box-group rtsb-quantity-box-group-<?php echo esc_attr( $controllers['quantity_style'] . ' ' . $inner_border ); ?>">
147 <div class="rtsb-qty-btns-group">
148 <button type="button" class="rtsb-quantity-btn rtsb-quantity-plus">
149 <?php Fns::print_html( Fns::icons_manager( $controllers['increment_icon'] ), true ); ?>
150 </button>
151 <button type="button" class="rtsb-quantity-btn rtsb-quantity-minus">
152 <?php Fns::print_html( Fns::icons_manager( $controllers['decrement_icon'] ), true ); ?>
153 </button>
154 </div>
155 <?php
156 }
157
158 /**
159 * Close quantity wrapper.
160 *
161 * @return void
162 */
163 public function close_quantity_wrapper() {
164 ?>
165 </div>
166 <!-- Quantity Wrapper End -->
167 <?php
168 }
169
170 /**
171 * Override WooCommerce AJAX variation threshold.
172 *
173 * @return int
174 */
175 public function override_ajax_variation_threshold() {
176 return 1;
177 }
178 /**
179 * Render Function
180 *
181 * @return void
182 */
183 protected function render() {
184 global $product;
185 $_product = $product;
186 $product = Fns::get_product();
187 $controllers = $this->get_settings_for_display();
188 $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] );
189 $add_to_cart_visibility = rtsb()->has_pro() && Fns::is_guest_feature_disabled( 'hide_add_to_cart', '' );
190 $controllers['visibility'] = $add_to_cart_visibility ? ' rtsb-not-visible' : ' rtsb-is-visible';
191
192 $this->the_hooks();
193 $this->theme_support();
194
195 $data = [
196 'template' => 'elementor/single-product/add-to-cart',
197 'controllers' => $controllers,
198 'product_type' => $product ? $product->get_type() : '',
199 ];
200
201 Fns::load_template( $data['template'], $data );
202
203 $this->editor_cart_icon_script();
204 add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_true', 99 );
205 $this->reset_hooks();
206 $this->theme_support( 'render_reset' );
207 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
208 }
209 }
210